masster 0.2.5__py3-none-any.whl → 0.3.1__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/__init__.py +27 -27
- masster/_version.py +17 -17
- masster/chromatogram.py +497 -503
- masster/data/examples/2025_01_14_VW_7600_LpMx_DBS_CID_2min_TOP15_030msecMS1_005msecReac_CE35_DBS-ON_3.featureXML +199787 -0
- masster/data/examples/2025_01_14_VW_7600_LpMx_DBS_CID_2min_TOP15_030msecMS1_005msecReac_CE35_DBS-ON_3.sample5 +0 -0
- masster/logger.py +318 -244
- masster/sample/__init__.py +9 -9
- masster/sample/defaults/__init__.py +15 -15
- masster/sample/defaults/find_adducts_def.py +325 -325
- masster/sample/defaults/find_features_def.py +366 -366
- masster/sample/defaults/find_ms2_def.py +285 -285
- masster/sample/defaults/get_spectrum_def.py +314 -318
- masster/sample/defaults/sample_def.py +374 -378
- masster/sample/h5.py +1321 -1297
- masster/sample/helpers.py +833 -364
- masster/sample/lib.py +762 -0
- masster/sample/load.py +1220 -1187
- masster/sample/parameters.py +131 -131
- masster/sample/plot.py +1685 -1622
- masster/sample/processing.py +1402 -1416
- masster/sample/quant.py +209 -0
- masster/sample/sample.py +393 -387
- masster/sample/sample5_schema.json +181 -181
- masster/sample/save.py +737 -736
- masster/sample/sciex.py +1213 -0
- masster/spectrum.py +1287 -1319
- masster/study/__init__.py +9 -9
- masster/study/defaults/__init__.py +21 -19
- masster/study/defaults/align_def.py +267 -267
- masster/study/defaults/export_def.py +41 -40
- masster/study/defaults/fill_chrom_def.py +264 -264
- masster/study/defaults/fill_def.py +260 -0
- masster/study/defaults/find_consensus_def.py +256 -256
- masster/study/defaults/find_ms2_def.py +163 -163
- masster/study/defaults/integrate_chrom_def.py +225 -225
- masster/study/defaults/integrate_def.py +221 -0
- masster/study/defaults/merge_def.py +256 -0
- masster/study/defaults/study_def.py +272 -269
- masster/study/export.py +674 -287
- masster/study/h5.py +1406 -886
- masster/study/helpers.py +1713 -433
- masster/study/helpers_optimized.py +317 -0
- masster/study/load.py +1231 -1078
- masster/study/parameters.py +99 -99
- masster/study/plot.py +632 -645
- masster/study/processing.py +1057 -1046
- masster/study/save.py +161 -134
- masster/study/study.py +612 -522
- masster/study/study5_schema.json +253 -241
- {masster-0.2.5.dist-info → masster-0.3.1.dist-info}/METADATA +15 -10
- masster-0.3.1.dist-info/RECORD +59 -0
- {masster-0.2.5.dist-info → masster-0.3.1.dist-info}/licenses/LICENSE +661 -661
- masster-0.2.5.dist-info/RECORD +0 -50
- {masster-0.2.5.dist-info → masster-0.3.1.dist-info}/WHEEL +0 -0
- {masster-0.2.5.dist-info → masster-0.3.1.dist-info}/entry_points.txt +0 -0
|
@@ -1,366 +1,366 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Find Features Parameters Module
|
|
3
|
-
|
|
4
|
-
This module defines parameters for feature detection in mass spectrometry data.
|
|
5
|
-
It consolidates all parameters used in the find_features() method with type checking,
|
|
6
|
-
validation, and comprehensive descriptions.
|
|
7
|
-
|
|
8
|
-
Classes:
|
|
9
|
-
find_features_defaults: Configuration parameters for the find_features() method.
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
from __future__ import annotations
|
|
13
|
-
|
|
14
|
-
from dataclasses import dataclass, field
|
|
15
|
-
from typing import Any
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@dataclass
|
|
19
|
-
class find_features_defaults:
|
|
20
|
-
"""
|
|
21
|
-
Parameters for mass spectrometry feature detection using OpenMS algorithms.
|
|
22
|
-
|
|
23
|
-
This class consolidates all parameters used in the find_features() method including
|
|
24
|
-
mass trace detection (MTD), elution peak detection (EPD), and feature finding (FFM).
|
|
25
|
-
It provides type checking, validation, and comprehensive parameter descriptions.
|
|
26
|
-
|
|
27
|
-
Mass Trace Detection (MTD) Parameters:
|
|
28
|
-
tol_ppm: Mass error tolerance in parts-per-million for mass trace detection.
|
|
29
|
-
noise: Noise threshold intensity to filter out low-intensity signals.
|
|
30
|
-
min_trace_length_multiplier: Multiplier for minimum trace length (multiplied by chrom_fwhm_min).
|
|
31
|
-
trace_termination_outliers: Number of outliers allowed before terminating a trace.
|
|
32
|
-
|
|
33
|
-
Elution Peak Detection (EPD) Parameters:
|
|
34
|
-
chrom_fwhm: Full width at half maximum for chromatographic peak shape.
|
|
35
|
-
chrom_fwhm_min: Minimum FWHM for chromatographic peak detection.
|
|
36
|
-
chrom_peak_snr: Signal-to-noise ratio required for chromatographic peaks.
|
|
37
|
-
masstrace_snr_filtering: Whether to apply SNR filtering to mass traces.
|
|
38
|
-
mz_scoring_13C: Whether to enable scoring of 13C isotopic patterns.
|
|
39
|
-
width_filtering: Width filtering method for mass traces.
|
|
40
|
-
|
|
41
|
-
Feature Finding (FFM) Parameters:
|
|
42
|
-
remove_single_traces: Whether to remove mass traces without satellite isotopic traces.
|
|
43
|
-
report_convex_hulls: Whether to report convex hulls for features.
|
|
44
|
-
report_summed_ints: Whether to report summed intensities.
|
|
45
|
-
report_chromatograms: Whether to report chromatograms.
|
|
46
|
-
|
|
47
|
-
Post-processing Parameters:
|
|
48
|
-
deisotope: Whether to perform deisotoping of detected features.
|
|
49
|
-
deisotope_mz_tol: m/z tolerance for deisotoping.
|
|
50
|
-
deisotope_rt_tol_factor: RT tolerance factor for deisotoping (multiplied by chrom_fwhm_min/4).
|
|
51
|
-
eic_mz_tol: m/z tolerance for EIC extraction.
|
|
52
|
-
eic_rt_tol: RT tolerance for EIC extraction.
|
|
53
|
-
|
|
54
|
-
Available Methods:
|
|
55
|
-
- validate(param_name, value): Validate a single parameter value
|
|
56
|
-
- validate_all(): Validate all parameters at once
|
|
57
|
-
- to_dict(): Convert parameters to dictionary
|
|
58
|
-
- set_from_dict(param_dict, validate=True): Update multiple parameters from dict
|
|
59
|
-
- set(param_name, value, validate=True): Set parameter value with validation
|
|
60
|
-
- get(param_name): Get parameter value
|
|
61
|
-
- get_description(param_name): Get parameter description
|
|
62
|
-
- get_info(param_name): Get full parameter metadata
|
|
63
|
-
- list_parameters(): Get list of all parameter names
|
|
64
|
-
"""
|
|
65
|
-
|
|
66
|
-
# Mass Trace Detection parameters
|
|
67
|
-
tol_ppm: float = 30.0
|
|
68
|
-
noise: float = 200.0
|
|
69
|
-
min_trace_length_multiplier: float =
|
|
70
|
-
trace_termination_outliers: int = 2
|
|
71
|
-
|
|
72
|
-
# Elution Peak Detection parameters
|
|
73
|
-
chrom_fwhm: float = 1.0
|
|
74
|
-
chrom_fwhm_min: float = 0.5
|
|
75
|
-
chrom_peak_snr: float = 10.0
|
|
76
|
-
masstrace_snr_filtering: bool = False
|
|
77
|
-
mz_scoring_13C: bool = False
|
|
78
|
-
width_filtering: str = "fixed"
|
|
79
|
-
|
|
80
|
-
# Feature Finding parameters
|
|
81
|
-
remove_single_traces: bool = False
|
|
82
|
-
report_convex_hulls: bool = True
|
|
83
|
-
report_summed_ints: bool = False
|
|
84
|
-
report_chromatograms: bool = True
|
|
85
|
-
|
|
86
|
-
# Post-processing parameters
|
|
87
|
-
deisotope: bool = True
|
|
88
|
-
deisotope_mz_tol: float = 0.02
|
|
89
|
-
deisotope_rt_tol_factor: float = 0.25 # Will be multiplied by chrom_fwhm_min/4
|
|
90
|
-
eic_mz_tol: float = 0.01
|
|
91
|
-
eic_rt_tol: float = 10.0
|
|
92
|
-
|
|
93
|
-
# Parameter metadata for validation and description
|
|
94
|
-
_param_metadata: dict[str, dict[str, Any]] = field(
|
|
95
|
-
default_factory=lambda: {
|
|
96
|
-
"tol_ppm": {
|
|
97
|
-
"dtype": float,
|
|
98
|
-
"description": "Mass error tolerance in parts-per-million for mass trace detection",
|
|
99
|
-
"min_value": 0.1,
|
|
100
|
-
"max_value": 100.0,
|
|
101
|
-
},
|
|
102
|
-
"noise": {
|
|
103
|
-
"dtype": float,
|
|
104
|
-
"description": "VIP: Noise threshold intensity to filter out low-intensity signals",
|
|
105
|
-
"min_value": 0.0,
|
|
106
|
-
"max_value": float("inf"),
|
|
107
|
-
},
|
|
108
|
-
"min_trace_length_multiplier": {
|
|
109
|
-
"dtype": float,
|
|
110
|
-
"description": "Multiplier for minimum trace length calculation (multiplied by chrom_fwhm_min)",
|
|
111
|
-
"min_value": 1.0,
|
|
112
|
-
"max_value": 10.0,
|
|
113
|
-
},
|
|
114
|
-
"trace_termination_outliers": {
|
|
115
|
-
"dtype": int,
|
|
116
|
-
"description": "Number of outliers allowed before terminating a mass trace",
|
|
117
|
-
"min_value": 1,
|
|
118
|
-
"max_value": 10,
|
|
119
|
-
},
|
|
120
|
-
"chrom_fwhm": {
|
|
121
|
-
"dtype": float,
|
|
122
|
-
"description": "VIP: Full width at half maximum for chromatographic peak shape in elution peak detection",
|
|
123
|
-
"min_value": 0.1,
|
|
124
|
-
"max_value": 30.0,
|
|
125
|
-
},
|
|
126
|
-
"chrom_fwhm_min": {
|
|
127
|
-
"dtype": float,
|
|
128
|
-
"description": "Minimum FWHM for chromatographic peak detection",
|
|
129
|
-
"min_value": 0.1,
|
|
130
|
-
"max_value": 5.0,
|
|
131
|
-
},
|
|
132
|
-
"chrom_peak_snr": {
|
|
133
|
-
"dtype": float,
|
|
134
|
-
"description": "VIP: Signal-to-noise ratio required for chromatographic peaks",
|
|
135
|
-
"min_value": 1.0,
|
|
136
|
-
"max_value": 100.0,
|
|
137
|
-
},
|
|
138
|
-
"masstrace_snr_filtering": {
|
|
139
|
-
"dtype": bool,
|
|
140
|
-
"description": "Whether to apply signal-to-noise filtering to mass traces",
|
|
141
|
-
},
|
|
142
|
-
"mz_scoring_13C": {
|
|
143
|
-
"dtype": bool,
|
|
144
|
-
"description": "Whether to enable scoring of 13C isotopic patterns during peak detection",
|
|
145
|
-
},
|
|
146
|
-
"width_filtering": {
|
|
147
|
-
"dtype": str,
|
|
148
|
-
"description": "Width filtering method for mass traces",
|
|
149
|
-
"allowed_values": ["fixed", "auto"],
|
|
150
|
-
},
|
|
151
|
-
"remove_single_traces": {
|
|
152
|
-
"dtype": bool,
|
|
153
|
-
"description": "Whether to remove mass traces without satellite isotopic traces",
|
|
154
|
-
},
|
|
155
|
-
"report_convex_hulls": {
|
|
156
|
-
"dtype": bool,
|
|
157
|
-
"description": "Whether to report convex hulls for detected features",
|
|
158
|
-
},
|
|
159
|
-
"report_summed_ints": {
|
|
160
|
-
"dtype": bool,
|
|
161
|
-
"description": "Whether to report summed intensities for features",
|
|
162
|
-
},
|
|
163
|
-
"report_chromatograms": {
|
|
164
|
-
"dtype": bool,
|
|
165
|
-
"description": "Whether to report chromatograms for features",
|
|
166
|
-
},
|
|
167
|
-
"deisotope": {
|
|
168
|
-
"dtype": bool,
|
|
169
|
-
"description": "Whether to perform deisotoping of detected features to remove redundant isotope peaks",
|
|
170
|
-
},
|
|
171
|
-
"deisotope_mz_tol": {
|
|
172
|
-
"dtype": float,
|
|
173
|
-
"description": "m/z tolerance for deisotoping (Da)",
|
|
174
|
-
"min_value": 0.001,
|
|
175
|
-
"max_value": 0.1,
|
|
176
|
-
},
|
|
177
|
-
"deisotope_rt_tol_factor": {
|
|
178
|
-
"dtype": float,
|
|
179
|
-
"description": "RT tolerance factor for deisotoping (multiplied by chrom_fwhm_min/4)",
|
|
180
|
-
"min_value": 0.1,
|
|
181
|
-
"max_value": 2.0,
|
|
182
|
-
},
|
|
183
|
-
"eic_mz_tol": {
|
|
184
|
-
"dtype": float,
|
|
185
|
-
"description": "m/z tolerance for EIC extraction (Da)",
|
|
186
|
-
"min_value": 0.001,
|
|
187
|
-
"max_value": 0.1,
|
|
188
|
-
},
|
|
189
|
-
"eic_rt_tol": {
|
|
190
|
-
"dtype": float,
|
|
191
|
-
"description": "RT tolerance for EIC extraction (seconds)",
|
|
192
|
-
"min_value": 1.0,
|
|
193
|
-
"max_value": 60.0,
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
def get_info(self, param_name: str) -> dict[str, Any]:
|
|
199
|
-
"""
|
|
200
|
-
Get information about a specific parameter.
|
|
201
|
-
|
|
202
|
-
Args:
|
|
203
|
-
param_name: Name of the parameter
|
|
204
|
-
|
|
205
|
-
Returns:
|
|
206
|
-
Dictionary containing parameter metadata
|
|
207
|
-
|
|
208
|
-
Raises:
|
|
209
|
-
KeyError: If parameter name is not found
|
|
210
|
-
"""
|
|
211
|
-
if param_name not in self._param_metadata:
|
|
212
|
-
raise KeyError(f"Parameter '{param_name}' not found")
|
|
213
|
-
return self._param_metadata[param_name]
|
|
214
|
-
|
|
215
|
-
def get_description(self, param_name: str) -> str:
|
|
216
|
-
"""
|
|
217
|
-
Get description for a specific parameter.
|
|
218
|
-
|
|
219
|
-
Args:
|
|
220
|
-
param_name: Name of the parameter
|
|
221
|
-
|
|
222
|
-
Returns:
|
|
223
|
-
Parameter description string
|
|
224
|
-
"""
|
|
225
|
-
return str(self.get_info(param_name)["description"])
|
|
226
|
-
|
|
227
|
-
def validate(self, param_name: str, value: Any) -> bool:
|
|
228
|
-
"""
|
|
229
|
-
Validate a parameter value against its constraints.
|
|
230
|
-
|
|
231
|
-
Args:
|
|
232
|
-
param_name: Name of the parameter
|
|
233
|
-
value: Value to validate
|
|
234
|
-
|
|
235
|
-
Returns:
|
|
236
|
-
True if value is valid, False otherwise
|
|
237
|
-
"""
|
|
238
|
-
if param_name not in self._param_metadata:
|
|
239
|
-
return False
|
|
240
|
-
|
|
241
|
-
metadata = self._param_metadata[param_name]
|
|
242
|
-
expected_dtype = metadata["dtype"]
|
|
243
|
-
|
|
244
|
-
# Check type
|
|
245
|
-
if not isinstance(value, expected_dtype):
|
|
246
|
-
try:
|
|
247
|
-
# Try to convert to expected type
|
|
248
|
-
value = expected_dtype(value)
|
|
249
|
-
except (ValueError, TypeError):
|
|
250
|
-
return False
|
|
251
|
-
|
|
252
|
-
# Check range constraints for numeric types
|
|
253
|
-
if expected_dtype in (int, float):
|
|
254
|
-
if "min_value" in metadata and value < metadata["min_value"]:
|
|
255
|
-
return False
|
|
256
|
-
if "max_value" in metadata and value > metadata["max_value"]:
|
|
257
|
-
return False
|
|
258
|
-
|
|
259
|
-
# Check allowed values for strings
|
|
260
|
-
if expected_dtype is str and "allowed_values" in metadata:
|
|
261
|
-
if value not in metadata["allowed_values"]:
|
|
262
|
-
return False
|
|
263
|
-
|
|
264
|
-
return True
|
|
265
|
-
|
|
266
|
-
def set(self, param_name: str, value: Any, validate: bool = True) -> bool:
|
|
267
|
-
"""
|
|
268
|
-
Set a parameter value with optional validation.
|
|
269
|
-
|
|
270
|
-
Args:
|
|
271
|
-
param_name: Name of the parameter
|
|
272
|
-
value: New value for the parameter
|
|
273
|
-
validate: Whether to validate the value before setting
|
|
274
|
-
|
|
275
|
-
Returns:
|
|
276
|
-
True if parameter was set successfully, False otherwise
|
|
277
|
-
"""
|
|
278
|
-
if not hasattr(self, param_name):
|
|
279
|
-
return False
|
|
280
|
-
|
|
281
|
-
if validate and not self.validate(param_name, value):
|
|
282
|
-
return False
|
|
283
|
-
|
|
284
|
-
# Convert to expected type if needed
|
|
285
|
-
if param_name in self._param_metadata:
|
|
286
|
-
expected_dtype = self._param_metadata[param_name]["dtype"]
|
|
287
|
-
try:
|
|
288
|
-
value = expected_dtype(value)
|
|
289
|
-
except (ValueError, TypeError):
|
|
290
|
-
if validate:
|
|
291
|
-
return False
|
|
292
|
-
|
|
293
|
-
setattr(self, param_name, value)
|
|
294
|
-
return True
|
|
295
|
-
|
|
296
|
-
def get(self, param_name: str) -> Any:
|
|
297
|
-
"""
|
|
298
|
-
Get the value of a parameter by name.
|
|
299
|
-
Args:
|
|
300
|
-
param_name: Name of the parameter
|
|
301
|
-
Returns:
|
|
302
|
-
Current value of the parameter
|
|
303
|
-
"""
|
|
304
|
-
if not hasattr(self, param_name):
|
|
305
|
-
raise KeyError(f"Parameter '{param_name}' not found")
|
|
306
|
-
return getattr(self, param_name)
|
|
307
|
-
|
|
308
|
-
def set_from_dict(
|
|
309
|
-
self,
|
|
310
|
-
param_dict: dict[str, Any],
|
|
311
|
-
validate: bool = True,
|
|
312
|
-
) -> list[str]:
|
|
313
|
-
"""
|
|
314
|
-
Update multiple parameters from a dictionary.
|
|
315
|
-
|
|
316
|
-
Args:
|
|
317
|
-
param_dict: Dictionary of parameter names and values
|
|
318
|
-
validate: Whether to validate values before setting
|
|
319
|
-
|
|
320
|
-
Returns:
|
|
321
|
-
List of parameter names that could not be set
|
|
322
|
-
"""
|
|
323
|
-
failed_params = []
|
|
324
|
-
|
|
325
|
-
for param_name, value in param_dict.items():
|
|
326
|
-
if not self.set(param_name, value, validate):
|
|
327
|
-
failed_params.append(param_name)
|
|
328
|
-
|
|
329
|
-
return failed_params
|
|
330
|
-
|
|
331
|
-
def to_dict(self) -> dict[str, Any]:
|
|
332
|
-
"""
|
|
333
|
-
Convert parameters to dictionary, excluding metadata.
|
|
334
|
-
|
|
335
|
-
Returns:
|
|
336
|
-
Dictionary of parameter names and values
|
|
337
|
-
"""
|
|
338
|
-
return {k: v for k, v in self.__dict__.items() if not k.startswith("_")}
|
|
339
|
-
|
|
340
|
-
def list_parameters(self) -> list[str]:
|
|
341
|
-
"""
|
|
342
|
-
Get list of all parameter names.
|
|
343
|
-
|
|
344
|
-
Returns:
|
|
345
|
-
List of parameter names
|
|
346
|
-
"""
|
|
347
|
-
return [k for k in self.__dict__.keys() if not k.startswith("_")]
|
|
348
|
-
|
|
349
|
-
def validate_all(self) -> tuple[bool, list[str]]:
|
|
350
|
-
"""
|
|
351
|
-
Validate all parameters in the instance.
|
|
352
|
-
|
|
353
|
-
Returns:
|
|
354
|
-
Tuple of (all_valid, list_of_invalid_params)
|
|
355
|
-
- all_valid: True if all parameters are valid, False otherwise
|
|
356
|
-
- list_of_invalid_params: List of parameter names that failed validation
|
|
357
|
-
"""
|
|
358
|
-
invalid_params = []
|
|
359
|
-
|
|
360
|
-
for param_name in self.list_parameters():
|
|
361
|
-
if param_name in self._param_metadata:
|
|
362
|
-
current_value = getattr(self, param_name)
|
|
363
|
-
if not self.validate(param_name, current_value):
|
|
364
|
-
invalid_params.append(param_name)
|
|
365
|
-
|
|
366
|
-
return len(invalid_params) == 0, invalid_params
|
|
1
|
+
"""
|
|
2
|
+
Find Features Parameters Module
|
|
3
|
+
|
|
4
|
+
This module defines parameters for feature detection in mass spectrometry data.
|
|
5
|
+
It consolidates all parameters used in the find_features() method with type checking,
|
|
6
|
+
validation, and comprehensive descriptions.
|
|
7
|
+
|
|
8
|
+
Classes:
|
|
9
|
+
find_features_defaults: Configuration parameters for the find_features() method.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class find_features_defaults:
|
|
20
|
+
"""
|
|
21
|
+
Parameters for mass spectrometry feature detection using OpenMS algorithms.
|
|
22
|
+
|
|
23
|
+
This class consolidates all parameters used in the find_features() method including
|
|
24
|
+
mass trace detection (MTD), elution peak detection (EPD), and feature finding (FFM).
|
|
25
|
+
It provides type checking, validation, and comprehensive parameter descriptions.
|
|
26
|
+
|
|
27
|
+
Mass Trace Detection (MTD) Parameters:
|
|
28
|
+
tol_ppm: Mass error tolerance in parts-per-million for mass trace detection.
|
|
29
|
+
noise: Noise threshold intensity to filter out low-intensity signals.
|
|
30
|
+
min_trace_length_multiplier: Multiplier for minimum trace length (multiplied by chrom_fwhm_min).
|
|
31
|
+
trace_termination_outliers: Number of outliers allowed before terminating a trace.
|
|
32
|
+
|
|
33
|
+
Elution Peak Detection (EPD) Parameters:
|
|
34
|
+
chrom_fwhm: Full width at half maximum for chromatographic peak shape.
|
|
35
|
+
chrom_fwhm_min: Minimum FWHM for chromatographic peak detection.
|
|
36
|
+
chrom_peak_snr: Signal-to-noise ratio required for chromatographic peaks.
|
|
37
|
+
masstrace_snr_filtering: Whether to apply SNR filtering to mass traces.
|
|
38
|
+
mz_scoring_13C: Whether to enable scoring of 13C isotopic patterns.
|
|
39
|
+
width_filtering: Width filtering method for mass traces.
|
|
40
|
+
|
|
41
|
+
Feature Finding (FFM) Parameters:
|
|
42
|
+
remove_single_traces: Whether to remove mass traces without satellite isotopic traces.
|
|
43
|
+
report_convex_hulls: Whether to report convex hulls for features.
|
|
44
|
+
report_summed_ints: Whether to report summed intensities.
|
|
45
|
+
report_chromatograms: Whether to report chromatograms.
|
|
46
|
+
|
|
47
|
+
Post-processing Parameters:
|
|
48
|
+
deisotope: Whether to perform deisotoping of detected features.
|
|
49
|
+
deisotope_mz_tol: m/z tolerance for deisotoping.
|
|
50
|
+
deisotope_rt_tol_factor: RT tolerance factor for deisotoping (multiplied by chrom_fwhm_min/4).
|
|
51
|
+
eic_mz_tol: m/z tolerance for EIC extraction.
|
|
52
|
+
eic_rt_tol: RT tolerance for EIC extraction.
|
|
53
|
+
|
|
54
|
+
Available Methods:
|
|
55
|
+
- validate(param_name, value): Validate a single parameter value
|
|
56
|
+
- validate_all(): Validate all parameters at once
|
|
57
|
+
- to_dict(): Convert parameters to dictionary
|
|
58
|
+
- set_from_dict(param_dict, validate=True): Update multiple parameters from dict
|
|
59
|
+
- set(param_name, value, validate=True): Set parameter value with validation
|
|
60
|
+
- get(param_name): Get parameter value
|
|
61
|
+
- get_description(param_name): Get parameter description
|
|
62
|
+
- get_info(param_name): Get full parameter metadata
|
|
63
|
+
- list_parameters(): Get list of all parameter names
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
# Mass Trace Detection parameters
|
|
67
|
+
tol_ppm: float = 30.0
|
|
68
|
+
noise: float = 200.0
|
|
69
|
+
min_trace_length_multiplier: float = 1.0
|
|
70
|
+
trace_termination_outliers: int = 2
|
|
71
|
+
|
|
72
|
+
# Elution Peak Detection parameters
|
|
73
|
+
chrom_fwhm: float = 1.0
|
|
74
|
+
chrom_fwhm_min: float = 0.5
|
|
75
|
+
chrom_peak_snr: float = 10.0
|
|
76
|
+
masstrace_snr_filtering: bool = False
|
|
77
|
+
mz_scoring_13C: bool = False
|
|
78
|
+
width_filtering: str = "fixed"
|
|
79
|
+
|
|
80
|
+
# Feature Finding parameters
|
|
81
|
+
remove_single_traces: bool = False
|
|
82
|
+
report_convex_hulls: bool = True
|
|
83
|
+
report_summed_ints: bool = False
|
|
84
|
+
report_chromatograms: bool = True
|
|
85
|
+
|
|
86
|
+
# Post-processing parameters
|
|
87
|
+
deisotope: bool = True
|
|
88
|
+
deisotope_mz_tol: float = 0.02
|
|
89
|
+
deisotope_rt_tol_factor: float = 0.25 # Will be multiplied by chrom_fwhm_min/4
|
|
90
|
+
eic_mz_tol: float = 0.01
|
|
91
|
+
eic_rt_tol: float = 10.0
|
|
92
|
+
|
|
93
|
+
# Parameter metadata for validation and description
|
|
94
|
+
_param_metadata: dict[str, dict[str, Any]] = field(
|
|
95
|
+
default_factory=lambda: {
|
|
96
|
+
"tol_ppm": {
|
|
97
|
+
"dtype": float,
|
|
98
|
+
"description": "Mass error tolerance in parts-per-million for mass trace detection",
|
|
99
|
+
"min_value": 0.1,
|
|
100
|
+
"max_value": 100.0,
|
|
101
|
+
},
|
|
102
|
+
"noise": {
|
|
103
|
+
"dtype": float,
|
|
104
|
+
"description": "VIP: Noise threshold intensity to filter out low-intensity signals",
|
|
105
|
+
"min_value": 0.0,
|
|
106
|
+
"max_value": float("inf"),
|
|
107
|
+
},
|
|
108
|
+
"min_trace_length_multiplier": {
|
|
109
|
+
"dtype": float,
|
|
110
|
+
"description": "Multiplier for minimum trace length calculation (multiplied by chrom_fwhm_min)",
|
|
111
|
+
"min_value": 1.0,
|
|
112
|
+
"max_value": 10.0,
|
|
113
|
+
},
|
|
114
|
+
"trace_termination_outliers": {
|
|
115
|
+
"dtype": int,
|
|
116
|
+
"description": "Number of outliers allowed before terminating a mass trace",
|
|
117
|
+
"min_value": 1,
|
|
118
|
+
"max_value": 10,
|
|
119
|
+
},
|
|
120
|
+
"chrom_fwhm": {
|
|
121
|
+
"dtype": float,
|
|
122
|
+
"description": "VIP: Full width at half maximum for chromatographic peak shape in elution peak detection",
|
|
123
|
+
"min_value": 0.1,
|
|
124
|
+
"max_value": 30.0,
|
|
125
|
+
},
|
|
126
|
+
"chrom_fwhm_min": {
|
|
127
|
+
"dtype": float,
|
|
128
|
+
"description": "Minimum FWHM for chromatographic peak detection",
|
|
129
|
+
"min_value": 0.1,
|
|
130
|
+
"max_value": 5.0,
|
|
131
|
+
},
|
|
132
|
+
"chrom_peak_snr": {
|
|
133
|
+
"dtype": float,
|
|
134
|
+
"description": "VIP: Signal-to-noise ratio required for chromatographic peaks",
|
|
135
|
+
"min_value": 1.0,
|
|
136
|
+
"max_value": 100.0,
|
|
137
|
+
},
|
|
138
|
+
"masstrace_snr_filtering": {
|
|
139
|
+
"dtype": bool,
|
|
140
|
+
"description": "Whether to apply signal-to-noise filtering to mass traces",
|
|
141
|
+
},
|
|
142
|
+
"mz_scoring_13C": {
|
|
143
|
+
"dtype": bool,
|
|
144
|
+
"description": "Whether to enable scoring of 13C isotopic patterns during peak detection",
|
|
145
|
+
},
|
|
146
|
+
"width_filtering": {
|
|
147
|
+
"dtype": str,
|
|
148
|
+
"description": "Width filtering method for mass traces",
|
|
149
|
+
"allowed_values": ["fixed", "auto"],
|
|
150
|
+
},
|
|
151
|
+
"remove_single_traces": {
|
|
152
|
+
"dtype": bool,
|
|
153
|
+
"description": "Whether to remove mass traces without satellite isotopic traces",
|
|
154
|
+
},
|
|
155
|
+
"report_convex_hulls": {
|
|
156
|
+
"dtype": bool,
|
|
157
|
+
"description": "Whether to report convex hulls for detected features",
|
|
158
|
+
},
|
|
159
|
+
"report_summed_ints": {
|
|
160
|
+
"dtype": bool,
|
|
161
|
+
"description": "Whether to report summed intensities for features",
|
|
162
|
+
},
|
|
163
|
+
"report_chromatograms": {
|
|
164
|
+
"dtype": bool,
|
|
165
|
+
"description": "Whether to report chromatograms for features",
|
|
166
|
+
},
|
|
167
|
+
"deisotope": {
|
|
168
|
+
"dtype": bool,
|
|
169
|
+
"description": "Whether to perform deisotoping of detected features to remove redundant isotope peaks",
|
|
170
|
+
},
|
|
171
|
+
"deisotope_mz_tol": {
|
|
172
|
+
"dtype": float,
|
|
173
|
+
"description": "m/z tolerance for deisotoping (Da)",
|
|
174
|
+
"min_value": 0.001,
|
|
175
|
+
"max_value": 0.1,
|
|
176
|
+
},
|
|
177
|
+
"deisotope_rt_tol_factor": {
|
|
178
|
+
"dtype": float,
|
|
179
|
+
"description": "RT tolerance factor for deisotoping (multiplied by chrom_fwhm_min/4)",
|
|
180
|
+
"min_value": 0.1,
|
|
181
|
+
"max_value": 2.0,
|
|
182
|
+
},
|
|
183
|
+
"eic_mz_tol": {
|
|
184
|
+
"dtype": float,
|
|
185
|
+
"description": "m/z tolerance for EIC extraction (Da)",
|
|
186
|
+
"min_value": 0.001,
|
|
187
|
+
"max_value": 0.1,
|
|
188
|
+
},
|
|
189
|
+
"eic_rt_tol": {
|
|
190
|
+
"dtype": float,
|
|
191
|
+
"description": "RT tolerance for EIC extraction (seconds)",
|
|
192
|
+
"min_value": 1.0,
|
|
193
|
+
"max_value": 60.0,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
def get_info(self, param_name: str) -> dict[str, Any]:
|
|
199
|
+
"""
|
|
200
|
+
Get information about a specific parameter.
|
|
201
|
+
|
|
202
|
+
Args:
|
|
203
|
+
param_name: Name of the parameter
|
|
204
|
+
|
|
205
|
+
Returns:
|
|
206
|
+
Dictionary containing parameter metadata
|
|
207
|
+
|
|
208
|
+
Raises:
|
|
209
|
+
KeyError: If parameter name is not found
|
|
210
|
+
"""
|
|
211
|
+
if param_name not in self._param_metadata:
|
|
212
|
+
raise KeyError(f"Parameter '{param_name}' not found")
|
|
213
|
+
return self._param_metadata[param_name]
|
|
214
|
+
|
|
215
|
+
def get_description(self, param_name: str) -> str:
|
|
216
|
+
"""
|
|
217
|
+
Get description for a specific parameter.
|
|
218
|
+
|
|
219
|
+
Args:
|
|
220
|
+
param_name: Name of the parameter
|
|
221
|
+
|
|
222
|
+
Returns:
|
|
223
|
+
Parameter description string
|
|
224
|
+
"""
|
|
225
|
+
return str(self.get_info(param_name)["description"])
|
|
226
|
+
|
|
227
|
+
def validate(self, param_name: str, value: Any) -> bool:
|
|
228
|
+
"""
|
|
229
|
+
Validate a parameter value against its constraints.
|
|
230
|
+
|
|
231
|
+
Args:
|
|
232
|
+
param_name: Name of the parameter
|
|
233
|
+
value: Value to validate
|
|
234
|
+
|
|
235
|
+
Returns:
|
|
236
|
+
True if value is valid, False otherwise
|
|
237
|
+
"""
|
|
238
|
+
if param_name not in self._param_metadata:
|
|
239
|
+
return False
|
|
240
|
+
|
|
241
|
+
metadata = self._param_metadata[param_name]
|
|
242
|
+
expected_dtype = metadata["dtype"]
|
|
243
|
+
|
|
244
|
+
# Check type
|
|
245
|
+
if not isinstance(value, expected_dtype):
|
|
246
|
+
try:
|
|
247
|
+
# Try to convert to expected type
|
|
248
|
+
value = expected_dtype(value)
|
|
249
|
+
except (ValueError, TypeError):
|
|
250
|
+
return False
|
|
251
|
+
|
|
252
|
+
# Check range constraints for numeric types
|
|
253
|
+
if expected_dtype in (int, float):
|
|
254
|
+
if "min_value" in metadata and value < metadata["min_value"]:
|
|
255
|
+
return False
|
|
256
|
+
if "max_value" in metadata and value > metadata["max_value"]:
|
|
257
|
+
return False
|
|
258
|
+
|
|
259
|
+
# Check allowed values for strings
|
|
260
|
+
if expected_dtype is str and "allowed_values" in metadata:
|
|
261
|
+
if value not in metadata["allowed_values"]:
|
|
262
|
+
return False
|
|
263
|
+
|
|
264
|
+
return True
|
|
265
|
+
|
|
266
|
+
def set(self, param_name: str, value: Any, validate: bool = True) -> bool:
|
|
267
|
+
"""
|
|
268
|
+
Set a parameter value with optional validation.
|
|
269
|
+
|
|
270
|
+
Args:
|
|
271
|
+
param_name: Name of the parameter
|
|
272
|
+
value: New value for the parameter
|
|
273
|
+
validate: Whether to validate the value before setting
|
|
274
|
+
|
|
275
|
+
Returns:
|
|
276
|
+
True if parameter was set successfully, False otherwise
|
|
277
|
+
"""
|
|
278
|
+
if not hasattr(self, param_name):
|
|
279
|
+
return False
|
|
280
|
+
|
|
281
|
+
if validate and not self.validate(param_name, value):
|
|
282
|
+
return False
|
|
283
|
+
|
|
284
|
+
# Convert to expected type if needed
|
|
285
|
+
if param_name in self._param_metadata:
|
|
286
|
+
expected_dtype = self._param_metadata[param_name]["dtype"]
|
|
287
|
+
try:
|
|
288
|
+
value = expected_dtype(value)
|
|
289
|
+
except (ValueError, TypeError):
|
|
290
|
+
if validate:
|
|
291
|
+
return False
|
|
292
|
+
|
|
293
|
+
setattr(self, param_name, value)
|
|
294
|
+
return True
|
|
295
|
+
|
|
296
|
+
def get(self, param_name: str) -> Any:
|
|
297
|
+
"""
|
|
298
|
+
Get the value of a parameter by name.
|
|
299
|
+
Args:
|
|
300
|
+
param_name: Name of the parameter
|
|
301
|
+
Returns:
|
|
302
|
+
Current value of the parameter
|
|
303
|
+
"""
|
|
304
|
+
if not hasattr(self, param_name):
|
|
305
|
+
raise KeyError(f"Parameter '{param_name}' not found")
|
|
306
|
+
return getattr(self, param_name)
|
|
307
|
+
|
|
308
|
+
def set_from_dict(
|
|
309
|
+
self,
|
|
310
|
+
param_dict: dict[str, Any],
|
|
311
|
+
validate: bool = True,
|
|
312
|
+
) -> list[str]:
|
|
313
|
+
"""
|
|
314
|
+
Update multiple parameters from a dictionary.
|
|
315
|
+
|
|
316
|
+
Args:
|
|
317
|
+
param_dict: Dictionary of parameter names and values
|
|
318
|
+
validate: Whether to validate values before setting
|
|
319
|
+
|
|
320
|
+
Returns:
|
|
321
|
+
List of parameter names that could not be set
|
|
322
|
+
"""
|
|
323
|
+
failed_params = []
|
|
324
|
+
|
|
325
|
+
for param_name, value in param_dict.items():
|
|
326
|
+
if not self.set(param_name, value, validate):
|
|
327
|
+
failed_params.append(param_name)
|
|
328
|
+
|
|
329
|
+
return failed_params
|
|
330
|
+
|
|
331
|
+
def to_dict(self) -> dict[str, Any]:
|
|
332
|
+
"""
|
|
333
|
+
Convert parameters to dictionary, excluding metadata.
|
|
334
|
+
|
|
335
|
+
Returns:
|
|
336
|
+
Dictionary of parameter names and values
|
|
337
|
+
"""
|
|
338
|
+
return {k: v for k, v in self.__dict__.items() if not k.startswith("_")}
|
|
339
|
+
|
|
340
|
+
def list_parameters(self) -> list[str]:
|
|
341
|
+
"""
|
|
342
|
+
Get list of all parameter names.
|
|
343
|
+
|
|
344
|
+
Returns:
|
|
345
|
+
List of parameter names
|
|
346
|
+
"""
|
|
347
|
+
return [k for k in self.__dict__.keys() if not k.startswith("_")]
|
|
348
|
+
|
|
349
|
+
def validate_all(self) -> tuple[bool, list[str]]:
|
|
350
|
+
"""
|
|
351
|
+
Validate all parameters in the instance.
|
|
352
|
+
|
|
353
|
+
Returns:
|
|
354
|
+
Tuple of (all_valid, list_of_invalid_params)
|
|
355
|
+
- all_valid: True if all parameters are valid, False otherwise
|
|
356
|
+
- list_of_invalid_params: List of parameter names that failed validation
|
|
357
|
+
"""
|
|
358
|
+
invalid_params = []
|
|
359
|
+
|
|
360
|
+
for param_name in self.list_parameters():
|
|
361
|
+
if param_name in self._param_metadata:
|
|
362
|
+
current_value = getattr(self, param_name)
|
|
363
|
+
if not self.validate(param_name, current_value):
|
|
364
|
+
invalid_params.append(param_name)
|
|
365
|
+
|
|
366
|
+
return len(invalid_params) == 0, invalid_params
|