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.

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 +1610 -1622
  20. masster/sample/processing.py +1402 -1416
  21. masster/sample/quant.py +209 -0
  22. masster/sample/sample.py +391 -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 +1398 -886
  41. masster/study/helpers.py +1650 -433
  42. masster/study/helpers_optimized.py +317 -0
  43. masster/study/load.py +1201 -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 +149 -134
  48. masster/study/study.py +606 -522
  49. masster/study/study5_schema.json +247 -241
  50. {masster-0.2.5.dist-info → masster-0.3.0.dist-info}/METADATA +15 -10
  51. masster-0.3.0.dist-info/RECORD +59 -0
  52. {masster-0.2.5.dist-info → masster-0.3.0.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.0.dist-info}/WHEEL +0 -0
  55. {masster-0.2.5.dist-info → masster-0.3.0.dist-info}/entry_points.txt +0 -0
@@ -1,40 +1,41 @@
1
- """Export defaults for study-level operations."""
2
-
3
- from dataclasses import dataclass
4
- from typing import Optional
5
-
6
-
7
- @dataclass
8
- class export_mgf_defaults:
9
- """Default parameters for exporting study results."""
10
-
11
- filename: str = "features.mgf"
12
- selection: str = "best" # "best" or "all"
13
- split_energy: bool = True
14
- merge: bool = False
15
- mz_start: Optional[float] = None
16
- mz_end: Optional[float] = None
17
- rt_start: Optional[float] = None
18
- rt_end: Optional[float] = None
19
- centroid: bool = True
20
- inty_min: Optional[float] = None
21
- deisotope: bool = True
22
- verbose: bool = False
23
- precursor_trim: float = -10
24
- centroid_algo: str = "lmp"
25
-
26
- def get(self, key: str):
27
- """Get parameter value by key."""
28
- return getattr(self, key, None)
29
-
30
- def set(self, key: str, value, validate: bool = True) -> bool:
31
- """Set parameter value with optional validation."""
32
- if hasattr(self, key):
33
- setattr(self, key, value)
34
- return True
35
- return False
36
-
37
- def to_dict(self) -> dict:
38
- """Convert to dictionary."""
39
- from dataclasses import asdict
40
- return asdict(self)
1
+ """Export defaults for study-level operations."""
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Optional
5
+
6
+
7
+ @dataclass
8
+ class export_mgf_defaults:
9
+ """Default parameters for exporting study results."""
10
+
11
+ filename: str = "features.mgf"
12
+ selection: str = "best" # "best" or "all"
13
+ split_energy: bool = True
14
+ merge: bool = False
15
+ mz_start: Optional[float] = None
16
+ mz_end: Optional[float] = None
17
+ rt_start: Optional[float] = None
18
+ rt_end: Optional[float] = None
19
+ centroid: bool = True
20
+ inty_min: Optional[float] = None
21
+ deisotope: bool = True
22
+ verbose: bool = False
23
+ precursor_trim: float = -10
24
+ centroid_algo: str = "lmp"
25
+
26
+ def get(self, key: str):
27
+ """Get parameter value by key."""
28
+ return getattr(self, key, None)
29
+
30
+ def set(self, key: str, value, validate: bool = True) -> bool:
31
+ """Set parameter value with optional validation."""
32
+ if hasattr(self, key):
33
+ setattr(self, key, value)
34
+ return True
35
+ return False
36
+
37
+ def to_dict(self) -> dict:
38
+ """Convert to dictionary."""
39
+ from dataclasses import asdict
40
+
41
+ return asdict(self)
@@ -1,264 +1,264 @@
1
- """Parameter class for Study fill_chrom method."""
2
-
3
- from dataclasses import dataclass, field
4
- from typing import Optional, Any
5
-
6
-
7
- @dataclass
8
- class fill_chrom_defaults:
9
- """
10
- Parameter class for Study fill_chrom method.
11
-
12
- This class encapsulates parameters for filling missing chromatograms
13
- by extracting them from raw data across samples.
14
-
15
- Attributes:
16
- uids (Optional[list]): List of consensus UIDs to process. Default is None (all).
17
- mz_tol (float): m/z tolerance for chromatogram extraction (Da). Default is 0.010.
18
- rt_tol (float): RT tolerance for chromatogram extraction (seconds). Default is 10.0.
19
- min_samples_rel (float): Minimum relative samples threshold. Default is 0.05.
20
- min_samples_abs (int): Minimum absolute samples threshold. Default is 5.
21
- """
22
-
23
- uids: Optional[list] = None
24
- mz_tol: float = 0.010
25
- rt_tol: float = 10.0
26
- min_samples_rel: float = 0.05
27
- min_samples_abs: int = 5
28
-
29
- _param_metadata: dict[str, dict[str, Any]] = field(
30
- default_factory=lambda: {
31
- "uids": {
32
- "dtype": "Optional[list]",
33
- "description": "List of consensus UIDs to process (None for all)",
34
- "default": None,
35
- },
36
- "mz_tol": {
37
- "dtype": float,
38
- "description": "m/z tolerance for chromatogram extraction (Da)",
39
- "default": 0.010,
40
- "min_value": 0.001,
41
- "max_value": 0.1,
42
- },
43
- "rt_tol": {
44
- "dtype": float,
45
- "description": "RT tolerance for chromatogram extraction (seconds)",
46
- "default": 10.0,
47
- "min_value": 1.0,
48
- "max_value": 300.0,
49
- },
50
- "min_samples_rel": {
51
- "dtype": float,
52
- "description": "Minimum relative samples threshold (fraction)",
53
- "default": 0.05,
54
- "min_value": 0.01,
55
- "max_value": 1.0,
56
- },
57
- "min_samples_abs": {
58
- "dtype": int,
59
- "description": "Minimum absolute samples threshold",
60
- "default": 5,
61
- "min_value": 1,
62
- "max_value": 100,
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 "list" in expected_dtype:
120
- expected_dtype = list
121
-
122
- # Type checking
123
- if expected_dtype is int:
124
- if not isinstance(value, int):
125
- try:
126
- value = int(value)
127
- except (ValueError, TypeError):
128
- return False
129
- elif expected_dtype is float:
130
- if not isinstance(value, (int, float)):
131
- try:
132
- value = float(value)
133
- except (ValueError, TypeError):
134
- return False
135
- elif expected_dtype is list:
136
- if not isinstance(value, list):
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
- return True
147
-
148
- def set(self, param_name: str, value: Any, validate: bool = True) -> bool:
149
- """
150
- Set a parameter value with optional validation.
151
-
152
- Args:
153
- param_name: Name of the parameter
154
- value: New value for the parameter
155
- validate: Whether to validate the value before setting
156
-
157
- Returns:
158
- True if parameter was set successfully, False otherwise
159
- """
160
- if not hasattr(self, param_name):
161
- return False
162
-
163
- if validate and not self.validate(param_name, value):
164
- return False
165
-
166
- # Convert to expected type if needed
167
- if param_name in self._param_metadata:
168
- expected_dtype = self._param_metadata[param_name]["dtype"]
169
-
170
- # Handle optional types
171
- if (
172
- isinstance(expected_dtype, str)
173
- and expected_dtype.startswith("Optional")
174
- and value is not None
175
- ):
176
- if "int" in expected_dtype and not isinstance(value, int):
177
- try:
178
- value = int(value)
179
- except (ValueError, TypeError):
180
- if validate:
181
- return False
182
- elif "float" in expected_dtype and not isinstance(value, float):
183
- try:
184
- value = float(value)
185
- except (ValueError, TypeError):
186
- if validate:
187
- return False
188
-
189
- setattr(self, param_name, value)
190
- return True
191
-
192
- def get(self, param_name: str) -> Any:
193
- """
194
- Get the value of a parameter by name.
195
-
196
- Args:
197
- param_name: Name of the parameter
198
-
199
- Returns:
200
- Current value of the parameter
201
- """
202
- if not hasattr(self, param_name):
203
- raise KeyError(f"Parameter '{param_name}' not found")
204
- return getattr(self, param_name)
205
-
206
- def set_from_dict(
207
- self,
208
- param_dict: dict[str, Any],
209
- validate: bool = True,
210
- ) -> list[str]:
211
- """
212
- Update multiple parameters from a dictionary.
213
-
214
- Args:
215
- param_dict: Dictionary of parameter names and values
216
- validate: Whether to validate values before setting
217
-
218
- Returns:
219
- List of parameter names that could not be set
220
- """
221
- failed_params = []
222
-
223
- for param_name, value in param_dict.items():
224
- if not self.set(param_name, value, validate):
225
- failed_params.append(param_name)
226
-
227
- return failed_params
228
-
229
- def to_dict(self) -> dict[str, Any]:
230
- """
231
- Convert parameters to dictionary, excluding metadata.
232
-
233
- Returns:
234
- Dictionary of parameter names and values
235
- """
236
- return {k: v for k, v in self.__dict__.items() if not k.startswith("_")}
237
-
238
- def list_parameters(self) -> list[str]:
239
- """
240
- Get list of all parameter names.
241
-
242
- Returns:
243
- List of parameter names
244
- """
245
- return [k for k in self.__dict__.keys() if not k.startswith("_")]
246
-
247
- def validate_all(self) -> tuple[bool, list[str]]:
248
- """
249
- Validate all parameters in the instance.
250
-
251
- Returns:
252
- Tuple of (all_valid, list_of_invalid_params)
253
- - all_valid: True if all parameters are valid, False otherwise
254
- - list_of_invalid_params: List of parameter names that failed validation
255
- """
256
- invalid_params = []
257
-
258
- for param_name in self.list_parameters():
259
- if param_name in self._param_metadata:
260
- current_value = getattr(self, param_name)
261
- if not self.validate(param_name, current_value):
262
- invalid_params.append(param_name)
263
-
264
- return len(invalid_params) == 0, invalid_params
1
+ """Parameter class for Study fill_chrom method."""
2
+
3
+ from dataclasses import dataclass, field
4
+ from typing import Optional, Any
5
+
6
+
7
+ @dataclass
8
+ class fill_chrom_defaults:
9
+ """
10
+ Parameter class for Study fill_chrom method.
11
+
12
+ This class encapsulates parameters for filling missing chromatograms
13
+ by extracting them from raw data across samples.
14
+
15
+ Attributes:
16
+ uids (Optional[list]): List of consensus UIDs to process. Default is None (all).
17
+ mz_tol (float): m/z tolerance for chromatogram extraction (Da). Default is 0.010.
18
+ rt_tol (float): RT tolerance for chromatogram extraction (seconds). Default is 10.0.
19
+ min_samples_rel (float): Minimum relative samples threshold. Default is 0.05.
20
+ min_samples_abs (int): Minimum absolute samples threshold. Default is 5.
21
+ """
22
+
23
+ uids: Optional[list] = None
24
+ mz_tol: float = 0.010
25
+ rt_tol: float = 10.0
26
+ min_samples_rel: float = 0.05
27
+ min_samples_abs: int = 5
28
+
29
+ _param_metadata: dict[str, dict[str, Any]] = field(
30
+ default_factory=lambda: {
31
+ "uids": {
32
+ "dtype": "Optional[list]",
33
+ "description": "List of consensus UIDs to process (None for all)",
34
+ "default": None,
35
+ },
36
+ "mz_tol": {
37
+ "dtype": float,
38
+ "description": "m/z tolerance for chromatogram extraction (Da)",
39
+ "default": 0.010,
40
+ "min_value": 0.001,
41
+ "max_value": 0.1,
42
+ },
43
+ "rt_tol": {
44
+ "dtype": float,
45
+ "description": "RT tolerance for chromatogram extraction (seconds)",
46
+ "default": 10.0,
47
+ "min_value": 1.0,
48
+ "max_value": 300.0,
49
+ },
50
+ "min_samples_rel": {
51
+ "dtype": float,
52
+ "description": "Minimum relative samples threshold (fraction)",
53
+ "default": 0.05,
54
+ "min_value": 0.01,
55
+ "max_value": 1.0,
56
+ },
57
+ "min_samples_abs": {
58
+ "dtype": int,
59
+ "description": "Minimum absolute samples threshold",
60
+ "default": 5,
61
+ "min_value": 1,
62
+ "max_value": 100,
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 "list" in expected_dtype:
120
+ expected_dtype = list
121
+
122
+ # Type checking
123
+ if expected_dtype is int:
124
+ if not isinstance(value, int):
125
+ try:
126
+ value = int(value)
127
+ except (ValueError, TypeError):
128
+ return False
129
+ elif expected_dtype is float:
130
+ if not isinstance(value, (int, float)):
131
+ try:
132
+ value = float(value)
133
+ except (ValueError, TypeError):
134
+ return False
135
+ elif expected_dtype is list:
136
+ if not isinstance(value, list):
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
+ return True
147
+
148
+ def set(self, param_name: str, value: Any, validate: bool = True) -> bool:
149
+ """
150
+ Set a parameter value with optional validation.
151
+
152
+ Args:
153
+ param_name: Name of the parameter
154
+ value: New value for the parameter
155
+ validate: Whether to validate the value before setting
156
+
157
+ Returns:
158
+ True if parameter was set successfully, False otherwise
159
+ """
160
+ if not hasattr(self, param_name):
161
+ return False
162
+
163
+ if validate and not self.validate(param_name, value):
164
+ return False
165
+
166
+ # Convert to expected type if needed
167
+ if param_name in self._param_metadata:
168
+ expected_dtype = self._param_metadata[param_name]["dtype"]
169
+
170
+ # Handle optional types
171
+ if (
172
+ isinstance(expected_dtype, str)
173
+ and expected_dtype.startswith("Optional")
174
+ and value is not None
175
+ ):
176
+ if "int" in expected_dtype and not isinstance(value, int):
177
+ try:
178
+ value = int(value)
179
+ except (ValueError, TypeError):
180
+ if validate:
181
+ return False
182
+ elif "float" in expected_dtype and not isinstance(value, float):
183
+ try:
184
+ value = float(value)
185
+ except (ValueError, TypeError):
186
+ if validate:
187
+ return False
188
+
189
+ setattr(self, param_name, value)
190
+ return True
191
+
192
+ def get(self, param_name: str) -> Any:
193
+ """
194
+ Get the value of a parameter by name.
195
+
196
+ Args:
197
+ param_name: Name of the parameter
198
+
199
+ Returns:
200
+ Current value of the parameter
201
+ """
202
+ if not hasattr(self, param_name):
203
+ raise KeyError(f"Parameter '{param_name}' not found")
204
+ return getattr(self, param_name)
205
+
206
+ def set_from_dict(
207
+ self,
208
+ param_dict: dict[str, Any],
209
+ validate: bool = True,
210
+ ) -> list[str]:
211
+ """
212
+ Update multiple parameters from a dictionary.
213
+
214
+ Args:
215
+ param_dict: Dictionary of parameter names and values
216
+ validate: Whether to validate values before setting
217
+
218
+ Returns:
219
+ List of parameter names that could not be set
220
+ """
221
+ failed_params = []
222
+
223
+ for param_name, value in param_dict.items():
224
+ if not self.set(param_name, value, validate):
225
+ failed_params.append(param_name)
226
+
227
+ return failed_params
228
+
229
+ def to_dict(self) -> dict[str, Any]:
230
+ """
231
+ Convert parameters to dictionary, excluding metadata.
232
+
233
+ Returns:
234
+ Dictionary of parameter names and values
235
+ """
236
+ return {k: v for k, v in self.__dict__.items() if not k.startswith("_")}
237
+
238
+ def list_parameters(self) -> list[str]:
239
+ """
240
+ Get list of all parameter names.
241
+
242
+ Returns:
243
+ List of parameter names
244
+ """
245
+ return [k for k in self.__dict__.keys() if not k.startswith("_")]
246
+
247
+ def validate_all(self) -> tuple[bool, list[str]]:
248
+ """
249
+ Validate all parameters in the instance.
250
+
251
+ Returns:
252
+ Tuple of (all_valid, list_of_invalid_params)
253
+ - all_valid: True if all parameters are valid, False otherwise
254
+ - list_of_invalid_params: List of parameter names that failed validation
255
+ """
256
+ invalid_params = []
257
+
258
+ for param_name in self.list_parameters():
259
+ if param_name in self._param_metadata:
260
+ current_value = getattr(self, param_name)
261
+ if not self.validate(param_name, current_value):
262
+ invalid_params.append(param_name)
263
+
264
+ return len(invalid_params) == 0, invalid_params