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

@@ -1,260 +0,0 @@
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 isinstance(expected_dtype, str) and expected_dtype.startswith("Optional") and value is not None:
172
- if "int" in expected_dtype and not isinstance(value, int):
173
- try:
174
- value = int(value)
175
- except (ValueError, TypeError):
176
- if validate:
177
- return False
178
- elif "float" in expected_dtype and not isinstance(value, float):
179
- try:
180
- value = float(value)
181
- except (ValueError, TypeError):
182
- if validate:
183
- return False
184
-
185
- setattr(self, param_name, value)
186
- return True
187
-
188
- def get(self, param_name: str) -> Any:
189
- """
190
- Get the value of a parameter by name.
191
-
192
- Args:
193
- param_name: Name of the parameter
194
-
195
- Returns:
196
- Current value of the parameter
197
- """
198
- if not hasattr(self, param_name):
199
- raise KeyError(f"Parameter '{param_name}' not found")
200
- return getattr(self, param_name)
201
-
202
- def set_from_dict(
203
- self,
204
- param_dict: dict[str, Any],
205
- validate: bool = True,
206
- ) -> list[str]:
207
- """
208
- Update multiple parameters from a dictionary.
209
-
210
- Args:
211
- param_dict: Dictionary of parameter names and values
212
- validate: Whether to validate values before setting
213
-
214
- Returns:
215
- List of parameter names that could not be set
216
- """
217
- failed_params = []
218
-
219
- for param_name, value in param_dict.items():
220
- if not self.set(param_name, value, validate):
221
- failed_params.append(param_name)
222
-
223
- return failed_params
224
-
225
- def to_dict(self) -> dict[str, Any]:
226
- """
227
- Convert parameters to dictionary, excluding metadata.
228
-
229
- Returns:
230
- Dictionary of parameter names and values
231
- """
232
- return {k: v for k, v in self.__dict__.items() if not k.startswith("_")}
233
-
234
- def list_parameters(self) -> list[str]:
235
- """
236
- Get list of all parameter names.
237
-
238
- Returns:
239
- List of parameter names
240
- """
241
- return [k for k in self.__dict__.keys() if not k.startswith("_")]
242
-
243
- def validate_all(self) -> tuple[bool, list[str]]:
244
- """
245
- Validate all parameters in the instance.
246
-
247
- Returns:
248
- Tuple of (all_valid, list_of_invalid_params)
249
- - all_valid: True if all parameters are valid, False otherwise
250
- - list_of_invalid_params: List of parameter names that failed validation
251
- """
252
- invalid_params = []
253
-
254
- for param_name in self.list_parameters():
255
- if param_name in self._param_metadata:
256
- current_value = getattr(self, param_name)
257
- if not self.validate(param_name, current_value):
258
- invalid_params.append(param_name)
259
-
260
- return len(invalid_params) == 0, invalid_params