masster 0.3.13__py3-none-any.whl → 0.3.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of masster might be problematic. Click here for more details.

masster/study/load.py CHANGED
@@ -71,11 +71,8 @@ def add(
71
71
 
72
72
  # Build search pattern
73
73
  if any(char in folder for char in ["*", "?", "[", "]"]):
74
- # If folder already contains glob patterns, modify the extension
75
- if folder.endswith("*.sample5"):
76
- pattern = folder.replace("*.sample5", f"*{ext}")
77
- else:
78
- pattern = os.path.join(search_folder, "**", f"*{ext}")
74
+ # If folder already contains glob patterns, use it as-is
75
+ pattern = folder
79
76
  else:
80
77
  pattern = os.path.join(search_folder, "**", f"*{ext}")
81
78
 
@@ -187,7 +184,9 @@ def add_sample(self, file, type=None, reset=False, adducts=None):
187
184
  sample_type = "qc"
188
185
  if "blank" in sample_name.lower():
189
186
  sample_type = "blank"
190
- map_id_value = str(ddaobj.features.getUniqueId())
187
+
188
+ # Use the index of the feature map in self.features_maps as map_id
189
+ map_id_value = len(self.features_maps) - 1
191
190
 
192
191
  # Determine the final sample path based on file type
193
192
  if file.endswith(".sample5"):
@@ -222,28 +221,39 @@ def add_sample(self, file, type=None, reset=False, adducts=None):
222
221
  ms1_count = int(ddaobj.scans_df.filter(pl.col("ms_level") == 1).height)
223
222
  ms2_count = int(ddaobj.scans_df.filter(pl.col("ms_level") == 2).height)
224
223
 
224
+ # Calculate next sequence number
225
+ next_sequence = len(self.samples_df) + 1 if not self.samples_df.is_empty() else 1
226
+
225
227
  new_sample = pl.DataFrame(
226
228
  {
227
229
  "sample_uid": [int(len(self.samples_df) + 1)],
228
230
  "sample_name": [sample_name],
229
231
  "sample_path": [final_sample_path], # Use the determined path
230
232
  "sample_type": [sample_type],
231
- "size": [int(ddaobj.features.size())],
232
233
  "map_id": [map_id_value],
233
- "file_source": [getattr(ddaobj, "file_source", file)],
234
- "ms1": [ms1_count],
235
- "ms2": [ms2_count],
234
+ "sample_source": [getattr(ddaobj, "file_source", file)],
235
+ "sample_color": [None], # Will be set by set_sample_color below
236
+ "sample_group": [""], # Default empty string
237
+ "sample_batch": [1], # Default batch 1
238
+ "sample_sequence": [next_sequence], # Increasing sequence number
239
+ "num_features": [int(ddaobj.features.size())],
240
+ "num_ms1": [ms1_count],
241
+ "num_ms2": [ms2_count],
236
242
  },
237
243
  schema={
238
244
  "sample_uid": pl.Int64,
239
245
  "sample_name": pl.Utf8,
240
246
  "sample_path": pl.Utf8,
241
247
  "sample_type": pl.Utf8,
242
- "size": pl.Int64,
243
- "map_id": pl.Utf8,
244
- "file_source": pl.Utf8,
245
- "ms1": pl.Int64,
246
- "ms2": pl.Int64,
248
+ "map_id": pl.Int64,
249
+ "sample_source": pl.Utf8,
250
+ "sample_color": pl.Utf8,
251
+ "sample_group": pl.Utf8,
252
+ "sample_batch": pl.Int64,
253
+ "sample_sequence": pl.Int64,
254
+ "num_features": pl.Int64,
255
+ "num_ms1": pl.Int64,
256
+ "num_ms2": pl.Int64,
247
257
  },
248
258
  )
249
259
  self.samples_df = pl.concat([self.samples_df, new_sample])
@@ -309,6 +319,9 @@ def add_sample(self, file, type=None, reset=False, adducts=None):
309
319
  # Ensure features_df column order matches schema
310
320
  self._ensure_features_df_schema_order()
311
321
 
322
+ # Auto-assign colors when new sample is added (reset all colors using turbo colormap based on UID)
323
+ self.sample_color_reset()
324
+
312
325
  self.logger.debug(
313
326
  f"Added sample {sample_name} with {ddaobj.features.size()} features to the study.",
314
327
  )