masster 0.4.4__py3-none-any.whl → 0.4.5__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.

Files changed (39) hide show
  1. masster/__init__.py +8 -8
  2. masster/chromatogram.py +1 -1
  3. masster/data/libs/urine.csv +3 -3
  4. masster/logger.py +11 -11
  5. masster/sample/__init__.py +1 -1
  6. masster/sample/adducts.py +338 -264
  7. masster/sample/defaults/find_adducts_def.py +21 -8
  8. masster/sample/h5.py +561 -282
  9. masster/sample/helpers.py +131 -75
  10. masster/sample/lib.py +4 -4
  11. masster/sample/load.py +31 -17
  12. masster/sample/parameters.py +1 -1
  13. masster/sample/plot.py +7 -7
  14. masster/sample/processing.py +117 -87
  15. masster/sample/sample.py +103 -90
  16. masster/sample/sample5_schema.json +44 -44
  17. masster/sample/save.py +35 -12
  18. masster/spectrum.py +1 -1
  19. masster/study/__init__.py +1 -1
  20. masster/study/defaults/align_def.py +5 -1
  21. masster/study/defaults/identify_def.py +3 -1
  22. masster/study/defaults/study_def.py +58 -25
  23. masster/study/export.py +360 -210
  24. masster/study/h5.py +560 -158
  25. masster/study/helpers.py +496 -203
  26. masster/study/helpers_optimized.py +1 -1
  27. masster/study/id.py +538 -349
  28. masster/study/load.py +233 -143
  29. masster/study/plot.py +71 -71
  30. masster/study/processing.py +456 -254
  31. masster/study/save.py +15 -5
  32. masster/study/study.py +213 -131
  33. masster/study/study5_schema.json +149 -149
  34. {masster-0.4.4.dist-info → masster-0.4.5.dist-info}/METADATA +3 -1
  35. {masster-0.4.4.dist-info → masster-0.4.5.dist-info}/RECORD +39 -39
  36. {masster-0.4.4.dist-info → masster-0.4.5.dist-info}/WHEEL +0 -0
  37. {masster-0.4.4.dist-info → masster-0.4.5.dist-info}/entry_points.txt +0 -0
  38. {masster-0.4.4.dist-info → masster-0.4.5.dist-info}/licenses/LICENSE +0 -0
  39. {masster-0.4.4.dist-info → masster-0.4.5.dist-info}/top_level.txt +0 -0
@@ -33,7 +33,7 @@ class study_defaults:
33
33
 
34
34
  eic_mz_tol: float = 0.01
35
35
  eic_rt_tol: float = 10.0
36
-
36
+
37
37
  polarity: str = "positive"
38
38
  adducts: list[str] | None = None
39
39
  adduct_min_probability: float = 0.04
@@ -54,7 +54,14 @@ class study_defaults:
54
54
  "dtype": str,
55
55
  "description": "Logging level to be set for the logger",
56
56
  "default": "INFO",
57
- "allowed_values": ["TRACE", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
57
+ "allowed_values": [
58
+ "TRACE",
59
+ "DEBUG",
60
+ "INFO",
61
+ "WARNING",
62
+ "ERROR",
63
+ "CRITICAL",
64
+ ],
58
65
  },
59
66
  "log_label": {
60
67
  "dtype": "Optional[str]",
@@ -92,14 +99,19 @@ class study_defaults:
92
99
  "default": ["H:+:0.8", "Na:+:0.1", "NH4:+:0.1"],
93
100
  "examples": {
94
101
  "positive": ["H:+:0.8", "Na:+:0.1", "NH4:+:0.1"],
95
- "negative": ["H-1:-:0.95", "Cl:-:0.05", "CH2O2:0:0.2", "H-2-O:0:0.2"]
102
+ "negative": [
103
+ "H-1:-:0.95",
104
+ "Cl:-:0.05",
105
+ "CH2O2:0:0.2",
106
+ "H-2-O:0:0.2",
107
+ ],
96
108
  },
97
109
  "validation_rules": [
98
110
  "Format: element:charge:probability",
99
111
  "Charge must be +, -, or 0 (neutral)",
100
112
  "Probability must be between 0.0 and 1.0",
101
- "Sum of all charged adduct probabilities must equal 1.0"
102
- ]
113
+ "Sum of all charged adduct probabilities must equal 1.0",
114
+ ],
103
115
  },
104
116
  "adduct_min_probability": {
105
117
  "dtype": float,
@@ -116,54 +128,71 @@ class study_defaults:
116
128
  """Set polarity-specific defaults for adducts if not explicitly provided."""
117
129
  # If adducts is None, set based on polarity
118
130
  if self.adducts is None:
119
- if self.polarity.lower() in ['positive', 'pos']:
120
- self.adducts = ["+H:1:0.65", "+Na:1:0.15", "+NH4:1:0.15", "+K:1:0.05", "-H2O:0:0.15"]
121
- elif self.polarity.lower() in ['negative', 'neg']:
122
- self.adducts = ["-H:-1:0.9", "+Cl:-1:0.1", "+CH2O2:0:0.15", "-H2O:0:0.15"]
131
+ if self.polarity.lower() in ["positive", "pos"]:
132
+ self.adducts = [
133
+ "+H:1:0.65",
134
+ "+Na:1:0.15",
135
+ "+NH4:1:0.15",
136
+ "+K:1:0.05",
137
+ "-H2O:0:0.15",
138
+ ]
139
+ elif self.polarity.lower() in ["negative", "neg"]:
140
+ self.adducts = [
141
+ "-H:-1:0.9",
142
+ "+Cl:-1:0.1",
143
+ "+CH2O2:0:0.15",
144
+ "-H2O:0:0.15",
145
+ ]
123
146
  else:
124
147
  # Default to positive if polarity is not recognized
125
- self.adducts = ["+H:1:0.65", "+Na:1:0.15", "+NH4:1:0.15", "+K:1:0.05", "-H2O:0:0.15"]
148
+ self.adducts = [
149
+ "+H:1:0.65",
150
+ "+Na:1:0.15",
151
+ "+NH4:1:0.15",
152
+ "+K:1:0.05",
153
+ "-H2O:0:0.15",
154
+ ]
126
155
 
127
156
  def _validate_adducts(self, adduct_list: list[str]) -> bool:
128
157
  """
129
158
  Validate adducts according to OpenMS convention.
130
-
159
+
131
160
  Format: element:charge:probability
132
161
  - Elements can be molecular formulas (e.g., H, Na, NH4, H-1, CH2O2)
133
162
  - Charge must be +, -, or 0 (for neutral)
134
163
  - Probability must be a float between 0 and 1
135
164
  - Total probability of all charged adducts should sum to 1.0
136
-
165
+
137
166
  Args:
138
167
  adduct_list: List of adduct strings in OpenMS format
139
-
168
+
140
169
  Returns:
141
170
  True if all adducts are valid, False otherwise
142
171
  """
143
172
  if not adduct_list: # Empty list is valid
144
173
  return True
145
-
174
+
146
175
  charged_total_prob = 0.0
147
176
  neutral_total_prob = 0.0
148
-
177
+
149
178
  for adduct in adduct_list:
150
179
  if not isinstance(adduct, str):
151
180
  return False
152
-
181
+
153
182
  parts = adduct.split(":")
154
183
  if len(parts) != 3:
155
184
  return False
156
-
185
+
157
186
  element, charge, prob_str = parts
158
-
187
+
159
188
  # Validate element (non-empty string)
160
189
  if not element:
161
190
  return False
162
-
191
+
163
192
  # Validate charge
164
193
  if charge not in ["+", "-", "0"]:
165
194
  return False
166
-
195
+
167
196
  # Validate probability
168
197
  try:
169
198
  probability = float(prob_str)
@@ -171,20 +200,20 @@ class study_defaults:
171
200
  return False
172
201
  except (ValueError, TypeError):
173
202
  return False
174
-
203
+
175
204
  # Sum probabilities by charge type
176
205
  if charge in ["+", "-"]:
177
206
  charged_total_prob += probability
178
207
  else: # charge == "0" (neutral)
179
208
  neutral_total_prob += probability
180
-
209
+
181
210
  # Validate probability constraints
182
211
  # Charged adducts should sum to 1.0 (within tolerance)
183
212
  if charged_total_prob > 0 and abs(charged_total_prob - 1.0) > 1e-6:
184
213
  return False
185
-
214
+
186
215
  # Neutral adducts can have any total probability (they're optional)
187
-
216
+
188
217
  return True
189
218
 
190
219
  def get_info(self, param_name: str) -> dict[str, Any]:
@@ -316,7 +345,11 @@ class study_defaults:
316
345
  expected_dtype = self._param_metadata[param_name]["dtype"]
317
346
 
318
347
  # Handle optional types
319
- if isinstance(expected_dtype, str) and expected_dtype.startswith("Optional") and value is not None:
348
+ if (
349
+ isinstance(expected_dtype, str)
350
+ and expected_dtype.startswith("Optional")
351
+ and value is not None
352
+ ):
320
353
  if "int" in expected_dtype and not isinstance(value, int):
321
354
  try:
322
355
  value = int(value)