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.

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