masster 0.2.5__py3-none-any.whl → 0.3.0__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 +1610 -1622
- masster/sample/processing.py +1402 -1416
- masster/sample/quant.py +209 -0
- masster/sample/sample.py +391 -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 +1398 -886
- masster/study/helpers.py +1650 -433
- masster/study/helpers_optimized.py +317 -0
- masster/study/load.py +1201 -1078
- masster/study/parameters.py +99 -99
- masster/study/plot.py +632 -645
- masster/study/processing.py +1057 -1046
- masster/study/save.py +149 -134
- masster/study/study.py +606 -522
- masster/study/study5_schema.json +247 -241
- {masster-0.2.5.dist-info → masster-0.3.0.dist-info}/METADATA +15 -10
- masster-0.3.0.dist-info/RECORD +59 -0
- {masster-0.2.5.dist-info → masster-0.3.0.dist-info}/licenses/LICENSE +661 -661
- masster-0.2.5.dist-info/RECORD +0 -50
- {masster-0.2.5.dist-info → masster-0.3.0.dist-info}/WHEEL +0 -0
- {masster-0.2.5.dist-info → masster-0.3.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,269 +1,272 @@
|
|
|
1
|
-
"""Parameter class for Study core parameters."""
|
|
2
|
-
|
|
3
|
-
from dataclasses import dataclass, field
|
|
4
|
-
from typing import Optional, Any
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@dataclass
|
|
8
|
-
class study_defaults:
|
|
9
|
-
"""
|
|
10
|
-
Parameter class for Study core parameters.
|
|
11
|
-
|
|
12
|
-
This class encapsulates parameters for study initialization, logging configuration,
|
|
13
|
-
and folder management for multi-sample mass spectrometry studies.
|
|
14
|
-
|
|
15
|
-
Attributes:
|
|
16
|
-
|
|
17
|
-
label (Optional[str]): Optional label to identify the study. Default is None.
|
|
18
|
-
log_level (str): Logging level to be set for the logger. Default is "INFO".
|
|
19
|
-
log_label (Optional[str]): Optional label for the logger. Default is None.
|
|
20
|
-
log_sink (str): Output sink for logging. Default is "sys.stdout".
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
label: str | None = None
|
|
25
|
-
log_level: str = "INFO"
|
|
26
|
-
log_label: Optional[str] = None
|
|
27
|
-
log_sink: str = "sys.stdout"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if
|
|
144
|
-
return False
|
|
145
|
-
|
|
146
|
-
#
|
|
147
|
-
if expected_dtype
|
|
148
|
-
if
|
|
149
|
-
return False
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
""
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
self,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
""
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
""
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
1
|
+
"""Parameter class for Study core parameters."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Optional, Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class study_defaults:
|
|
9
|
+
"""
|
|
10
|
+
Parameter class for Study core parameters.
|
|
11
|
+
|
|
12
|
+
This class encapsulates parameters for study initialization, logging configuration,
|
|
13
|
+
and folder management for multi-sample mass spectrometry studies.
|
|
14
|
+
|
|
15
|
+
Attributes:
|
|
16
|
+
folder (Optional[str]): Default directory for study files and outputs. Default is None.
|
|
17
|
+
label (Optional[str]): Optional label to identify the study. Default is None.
|
|
18
|
+
log_level (str): Logging level to be set for the logger. Default is "INFO".
|
|
19
|
+
log_label (Optional[str]): Optional label for the logger. Default is None.
|
|
20
|
+
log_sink (str): Output sink for logging. Default is "sys.stdout".
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
folder: Optional[str] = None
|
|
24
|
+
label: str | None = None
|
|
25
|
+
log_level: str = "INFO"
|
|
26
|
+
log_label: Optional[str] = None
|
|
27
|
+
log_sink: str = "sys.stdout"
|
|
28
|
+
polarity: str = "positive"
|
|
29
|
+
|
|
30
|
+
_param_metadata: dict[str, dict[str, Any]] = field(
|
|
31
|
+
default_factory=lambda: {
|
|
32
|
+
"folder": {
|
|
33
|
+
"dtype": "Optional[str]",
|
|
34
|
+
"description": "Default directory for study files and outputs",
|
|
35
|
+
"default": None,
|
|
36
|
+
},
|
|
37
|
+
"label": {
|
|
38
|
+
"dtype": "Optional[str]",
|
|
39
|
+
"description": "Optional label to identify the study",
|
|
40
|
+
"default": None,
|
|
41
|
+
},
|
|
42
|
+
"log_level": {
|
|
43
|
+
"dtype": str,
|
|
44
|
+
"description": "Logging level to be set for the logger",
|
|
45
|
+
"default": "INFO",
|
|
46
|
+
"allowed_values": ["TRACE", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
|
|
47
|
+
},
|
|
48
|
+
"log_label": {
|
|
49
|
+
"dtype": "Optional[str]",
|
|
50
|
+
"description": "Optional label for the logger",
|
|
51
|
+
"default": None,
|
|
52
|
+
},
|
|
53
|
+
"log_sink": {
|
|
54
|
+
"dtype": str,
|
|
55
|
+
"description": "Output sink for logging. Use 'sys.stdout' for console output, or a file path",
|
|
56
|
+
"default": "sys.stdout",
|
|
57
|
+
},
|
|
58
|
+
"polarity": {
|
|
59
|
+
"dtype": str,
|
|
60
|
+
"description": "Polarity of the study (positive/negative)",
|
|
61
|
+
"default": "positive",
|
|
62
|
+
"allowed_values": ["positive", "negative","pos","neg"],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
repr=False,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def get_info(self, param_name: str) -> dict[str, Any]:
|
|
69
|
+
"""
|
|
70
|
+
Get information about a specific parameter.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
param_name: Name of the parameter
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
Dictionary containing parameter metadata
|
|
77
|
+
|
|
78
|
+
Raises:
|
|
79
|
+
KeyError: If parameter name is not found
|
|
80
|
+
"""
|
|
81
|
+
if param_name not in self._param_metadata:
|
|
82
|
+
raise KeyError(f"Parameter '{param_name}' not found")
|
|
83
|
+
return self._param_metadata[param_name]
|
|
84
|
+
|
|
85
|
+
def get_description(self, param_name: str) -> str:
|
|
86
|
+
"""
|
|
87
|
+
Get description for a specific parameter.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
param_name: Name of the parameter
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
Parameter description string
|
|
94
|
+
"""
|
|
95
|
+
return str(self.get_info(param_name)["description"])
|
|
96
|
+
|
|
97
|
+
def validate(self, param_name: str, value: Any) -> bool:
|
|
98
|
+
"""
|
|
99
|
+
Validate a parameter value against its constraints.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
param_name: Name of the parameter
|
|
103
|
+
value: Value to validate
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
True if value is valid, False otherwise
|
|
107
|
+
"""
|
|
108
|
+
if param_name not in self._param_metadata:
|
|
109
|
+
return False
|
|
110
|
+
|
|
111
|
+
metadata = self._param_metadata[param_name]
|
|
112
|
+
expected_dtype = metadata["dtype"]
|
|
113
|
+
|
|
114
|
+
# Handle optional types
|
|
115
|
+
if isinstance(expected_dtype, str) and expected_dtype.startswith("Optional"):
|
|
116
|
+
if value is None:
|
|
117
|
+
return True
|
|
118
|
+
# Extract the inner type for validation
|
|
119
|
+
if "str" in expected_dtype:
|
|
120
|
+
expected_dtype = str
|
|
121
|
+
elif "float" in expected_dtype:
|
|
122
|
+
expected_dtype = float
|
|
123
|
+
elif "int" in expected_dtype:
|
|
124
|
+
expected_dtype = int
|
|
125
|
+
|
|
126
|
+
# Type checking
|
|
127
|
+
if expected_dtype is int:
|
|
128
|
+
if not isinstance(value, int):
|
|
129
|
+
try:
|
|
130
|
+
value = int(value)
|
|
131
|
+
except (ValueError, TypeError):
|
|
132
|
+
return False
|
|
133
|
+
elif expected_dtype is float:
|
|
134
|
+
if not isinstance(value, (int, float)):
|
|
135
|
+
try:
|
|
136
|
+
value = float(value)
|
|
137
|
+
except (ValueError, TypeError):
|
|
138
|
+
return False
|
|
139
|
+
elif expected_dtype is bool:
|
|
140
|
+
if not isinstance(value, bool):
|
|
141
|
+
return False
|
|
142
|
+
elif expected_dtype is str:
|
|
143
|
+
if not isinstance(value, str):
|
|
144
|
+
return False
|
|
145
|
+
|
|
146
|
+
# Range validation for numeric types
|
|
147
|
+
if expected_dtype in (int, float) and isinstance(value, (int, float)):
|
|
148
|
+
if "min_value" in metadata and value < metadata["min_value"]:
|
|
149
|
+
return False
|
|
150
|
+
if "max_value" in metadata and value > metadata["max_value"]:
|
|
151
|
+
return False
|
|
152
|
+
|
|
153
|
+
# Allowed values validation for strings
|
|
154
|
+
if expected_dtype is str and "allowed_values" in metadata:
|
|
155
|
+
if value not in metadata["allowed_values"]:
|
|
156
|
+
return False
|
|
157
|
+
|
|
158
|
+
return True
|
|
159
|
+
|
|
160
|
+
def set(self, param_name: str, value: Any, validate: bool = True) -> bool:
|
|
161
|
+
"""
|
|
162
|
+
Set a parameter value with optional validation.
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
param_name: Name of the parameter
|
|
166
|
+
value: New value for the parameter
|
|
167
|
+
validate: Whether to validate the value before setting
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
True if parameter was set successfully, False otherwise
|
|
171
|
+
"""
|
|
172
|
+
if not hasattr(self, param_name):
|
|
173
|
+
return False
|
|
174
|
+
|
|
175
|
+
if validate and not self.validate(param_name, value):
|
|
176
|
+
return False
|
|
177
|
+
|
|
178
|
+
# Convert to expected type if needed
|
|
179
|
+
if param_name in self._param_metadata:
|
|
180
|
+
expected_dtype = self._param_metadata[param_name]["dtype"]
|
|
181
|
+
|
|
182
|
+
# Handle optional types
|
|
183
|
+
if isinstance(expected_dtype, str) and expected_dtype.startswith("Optional") and value is not None:
|
|
184
|
+
if "int" in expected_dtype and not isinstance(value, int):
|
|
185
|
+
try:
|
|
186
|
+
value = int(value)
|
|
187
|
+
except (ValueError, TypeError):
|
|
188
|
+
if validate:
|
|
189
|
+
return False
|
|
190
|
+
elif "float" in expected_dtype and not isinstance(value, float):
|
|
191
|
+
try:
|
|
192
|
+
value = float(value)
|
|
193
|
+
except (ValueError, TypeError):
|
|
194
|
+
if validate:
|
|
195
|
+
return False
|
|
196
|
+
|
|
197
|
+
setattr(self, param_name, value)
|
|
198
|
+
return True
|
|
199
|
+
|
|
200
|
+
def get(self, param_name: str) -> Any:
|
|
201
|
+
"""
|
|
202
|
+
Get the value of a parameter by name.
|
|
203
|
+
|
|
204
|
+
Args:
|
|
205
|
+
param_name: Name of the parameter
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
Current value of the parameter
|
|
209
|
+
"""
|
|
210
|
+
if not hasattr(self, param_name):
|
|
211
|
+
raise KeyError(f"Parameter '{param_name}' not found")
|
|
212
|
+
return getattr(self, param_name)
|
|
213
|
+
|
|
214
|
+
def set_from_dict(
|
|
215
|
+
self,
|
|
216
|
+
param_dict: dict[str, Any],
|
|
217
|
+
validate: bool = True,
|
|
218
|
+
) -> list[str]:
|
|
219
|
+
"""
|
|
220
|
+
Update multiple parameters from a dictionary.
|
|
221
|
+
|
|
222
|
+
Args:
|
|
223
|
+
param_dict: Dictionary of parameter names and values
|
|
224
|
+
validate: Whether to validate values before setting
|
|
225
|
+
|
|
226
|
+
Returns:
|
|
227
|
+
List of parameter names that could not be set
|
|
228
|
+
"""
|
|
229
|
+
failed_params = []
|
|
230
|
+
|
|
231
|
+
for param_name, value in param_dict.items():
|
|
232
|
+
if not self.set(param_name, value, validate):
|
|
233
|
+
failed_params.append(param_name)
|
|
234
|
+
|
|
235
|
+
return failed_params
|
|
236
|
+
|
|
237
|
+
def to_dict(self) -> dict[str, Any]:
|
|
238
|
+
"""
|
|
239
|
+
Convert parameters to dictionary, excluding metadata.
|
|
240
|
+
|
|
241
|
+
Returns:
|
|
242
|
+
Dictionary of parameter names and values
|
|
243
|
+
"""
|
|
244
|
+
return {k: v for k, v in self.__dict__.items() if not k.startswith("_")}
|
|
245
|
+
|
|
246
|
+
def list_parameters(self) -> list[str]:
|
|
247
|
+
"""
|
|
248
|
+
Get list of all parameter names.
|
|
249
|
+
|
|
250
|
+
Returns:
|
|
251
|
+
List of parameter names
|
|
252
|
+
"""
|
|
253
|
+
return [k for k in self.__dict__.keys() if not k.startswith("_")]
|
|
254
|
+
|
|
255
|
+
def validate_all(self) -> tuple[bool, list[str]]:
|
|
256
|
+
"""
|
|
257
|
+
Validate all parameters in the instance.
|
|
258
|
+
|
|
259
|
+
Returns:
|
|
260
|
+
Tuple of (all_valid, list_of_invalid_params)
|
|
261
|
+
- all_valid: True if all parameters are valid, False otherwise
|
|
262
|
+
- list_of_invalid_params: List of parameter names that failed validation
|
|
263
|
+
"""
|
|
264
|
+
invalid_params = []
|
|
265
|
+
|
|
266
|
+
for param_name in self.list_parameters():
|
|
267
|
+
if param_name in self._param_metadata:
|
|
268
|
+
current_value = getattr(self, param_name)
|
|
269
|
+
if not self.validate(param_name, current_value):
|
|
270
|
+
invalid_params.append(param_name)
|
|
271
|
+
|
|
272
|
+
return len(invalid_params) == 0, invalid_params
|