masster 0.4.4__py3-none-any.whl → 0.4.5__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 +8 -8
- masster/chromatogram.py +1 -1
- masster/data/libs/urine.csv +3 -3
- masster/logger.py +11 -11
- masster/sample/__init__.py +1 -1
- masster/sample/adducts.py +338 -264
- masster/sample/defaults/find_adducts_def.py +21 -8
- masster/sample/h5.py +561 -282
- masster/sample/helpers.py +131 -75
- masster/sample/lib.py +4 -4
- masster/sample/load.py +31 -17
- masster/sample/parameters.py +1 -1
- masster/sample/plot.py +7 -7
- masster/sample/processing.py +117 -87
- masster/sample/sample.py +103 -90
- masster/sample/sample5_schema.json +44 -44
- masster/sample/save.py +35 -12
- masster/spectrum.py +1 -1
- masster/study/__init__.py +1 -1
- masster/study/defaults/align_def.py +5 -1
- masster/study/defaults/identify_def.py +3 -1
- masster/study/defaults/study_def.py +58 -25
- masster/study/export.py +360 -210
- masster/study/h5.py +560 -158
- masster/study/helpers.py +496 -203
- masster/study/helpers_optimized.py +1 -1
- masster/study/id.py +538 -349
- masster/study/load.py +233 -143
- masster/study/plot.py +71 -71
- masster/study/processing.py +456 -254
- masster/study/save.py +15 -5
- masster/study/study.py +213 -131
- masster/study/study5_schema.json +149 -149
- {masster-0.4.4.dist-info → masster-0.4.5.dist-info}/METADATA +3 -1
- {masster-0.4.4.dist-info → masster-0.4.5.dist-info}/RECORD +39 -39
- {masster-0.4.4.dist-info → masster-0.4.5.dist-info}/WHEEL +0 -0
- {masster-0.4.4.dist-info → masster-0.4.5.dist-info}/entry_points.txt +0 -0
- {masster-0.4.4.dist-info → masster-0.4.5.dist-info}/licenses/LICENSE +0 -0
- {masster-0.4.4.dist-info → masster-0.4.5.dist-info}/top_level.txt +0 -0
masster/sample/sample.py
CHANGED
|
@@ -23,7 +23,7 @@ Classes:
|
|
|
23
23
|
|
|
24
24
|
Example Usage:
|
|
25
25
|
```python
|
|
26
|
-
from
|
|
26
|
+
from master.sample import Sample
|
|
27
27
|
|
|
28
28
|
sample = Sample(file="example.mzML")
|
|
29
29
|
sample.find_features()
|
|
@@ -38,86 +38,87 @@ import sys
|
|
|
38
38
|
|
|
39
39
|
import polars as pl
|
|
40
40
|
|
|
41
|
-
from
|
|
42
|
-
from
|
|
41
|
+
from master._version import get_version
|
|
42
|
+
from master.logger import MasterLogger
|
|
43
43
|
|
|
44
|
-
from
|
|
45
|
-
from
|
|
46
|
-
from
|
|
47
|
-
from
|
|
48
|
-
from
|
|
44
|
+
from master.sample.defaults.sample_def import sample_defaults
|
|
45
|
+
from master.sample.defaults.find_features_def import find_features_defaults
|
|
46
|
+
from master.sample.defaults.find_adducts_def import find_adducts_defaults
|
|
47
|
+
from master.sample.defaults.find_ms2_def import find_ms2_defaults
|
|
48
|
+
from master.sample.defaults.get_spectrum_def import get_spectrum_defaults
|
|
49
49
|
|
|
50
50
|
# Sample-specific imports
|
|
51
|
-
from
|
|
52
|
-
from
|
|
53
|
-
from
|
|
54
|
-
from
|
|
55
|
-
from
|
|
56
|
-
from
|
|
57
|
-
from
|
|
58
|
-
from
|
|
59
|
-
|
|
60
|
-
#from
|
|
61
|
-
#from
|
|
62
|
-
#from
|
|
63
|
-
#from
|
|
64
|
-
#from
|
|
65
|
-
#from
|
|
66
|
-
#from
|
|
67
|
-
from
|
|
68
|
-
from
|
|
69
|
-
from
|
|
70
|
-
from
|
|
71
|
-
from
|
|
72
|
-
from
|
|
73
|
-
from
|
|
74
|
-
from
|
|
75
|
-
from
|
|
76
|
-
from
|
|
77
|
-
from
|
|
78
|
-
from
|
|
79
|
-
from
|
|
80
|
-
from
|
|
81
|
-
from
|
|
82
|
-
from
|
|
83
|
-
from
|
|
84
|
-
from
|
|
85
|
-
from
|
|
86
|
-
from
|
|
87
|
-
from
|
|
88
|
-
from
|
|
89
|
-
from
|
|
90
|
-
from
|
|
91
|
-
from
|
|
92
|
-
from
|
|
93
|
-
from
|
|
94
|
-
from
|
|
95
|
-
from
|
|
96
|
-
from
|
|
97
|
-
from
|
|
98
|
-
from
|
|
99
|
-
from
|
|
100
|
-
from
|
|
101
|
-
from
|
|
102
|
-
from
|
|
103
|
-
from
|
|
104
|
-
from
|
|
105
|
-
from
|
|
106
|
-
from
|
|
107
|
-
from
|
|
108
|
-
from
|
|
109
|
-
from
|
|
110
|
-
from
|
|
111
|
-
from
|
|
112
|
-
from
|
|
113
|
-
from
|
|
114
|
-
from
|
|
115
|
-
from
|
|
116
|
-
from
|
|
117
|
-
from
|
|
118
|
-
from
|
|
119
|
-
from
|
|
120
|
-
from
|
|
51
|
+
from master.sample.h5 import _load_sample5
|
|
52
|
+
from master.sample.h5 import _load_sample5_study
|
|
53
|
+
from master.sample.h5 import _save_sample5
|
|
54
|
+
from master.sample.helpers import _delete_ms2
|
|
55
|
+
from master.sample.helpers import _estimate_memory_usage
|
|
56
|
+
from master.sample.helpers import _get_scan_uids
|
|
57
|
+
from master.sample.helpers import _get_feature_uids
|
|
58
|
+
from master.sample.helpers import _features_sync
|
|
59
|
+
|
|
60
|
+
# from master.sample.helpers import _parse_adduct_specs
|
|
61
|
+
# from master.sample.helpers import _calculate_adduct_mass_shift
|
|
62
|
+
# from master.sample.helpers import _parse_formula_expression
|
|
63
|
+
# from master.sample.helpers import _calculate_molecular_mass
|
|
64
|
+
# from master.sample.helpers import _parse_legacy_adduct_format
|
|
65
|
+
# from master.sample.helpers import _extract_adduct_probability
|
|
66
|
+
# from master.sample.helpers import _detect_adduct_groups_direct
|
|
67
|
+
# from master.sample.helpers import _check_adduct_relationship
|
|
68
|
+
from master.sample.adducts import _get_adducts
|
|
69
|
+
from master.sample.adducts import find_adducts
|
|
70
|
+
from master.sample.helpers import features_delete
|
|
71
|
+
from master.sample.helpers import features_filter
|
|
72
|
+
from master.sample.helpers import select
|
|
73
|
+
from master.sample.helpers import select_closest_scan
|
|
74
|
+
from master.sample.helpers import get_dda_stats
|
|
75
|
+
from master.sample.helpers import get_feature
|
|
76
|
+
from master.sample.helpers import get_scan
|
|
77
|
+
from master.sample.helpers import get_eic
|
|
78
|
+
from master.sample.helpers import set_source
|
|
79
|
+
from master.sample.helpers import _recreate_feature_map
|
|
80
|
+
from master.sample.helpers import _get_feature_map
|
|
81
|
+
from master.sample.load import _load_featureXML
|
|
82
|
+
from master.sample.load import _load_ms2data
|
|
83
|
+
from master.sample.load import _load_mzML
|
|
84
|
+
from master.sample.load import _load_raw
|
|
85
|
+
from master.sample.load import _load_wiff
|
|
86
|
+
from master.sample.load import chrom_extract
|
|
87
|
+
from master.sample.load import index_file
|
|
88
|
+
from master.sample.load import load
|
|
89
|
+
from master.sample.load import load_noms1
|
|
90
|
+
from master.sample.load import load_study
|
|
91
|
+
from master.sample.load import sanitize
|
|
92
|
+
from master.sample.plot import plot_2d
|
|
93
|
+
from master.sample.plot import plot_2d_oracle
|
|
94
|
+
from master.sample.plot import plot_dda_stats
|
|
95
|
+
from master.sample.plot import plot_chrom
|
|
96
|
+
from master.sample.plot import plot_feature_stats
|
|
97
|
+
from master.sample.plot import plot_ms2_cycle
|
|
98
|
+
from master.sample.plot import plot_ms2_eic
|
|
99
|
+
from master.sample.plot import plot_ms2_q1
|
|
100
|
+
from master.sample.plot import plot_bpc
|
|
101
|
+
from master.sample.plot import plot_tic
|
|
102
|
+
from master.sample.plot import _handle_sample_plot_output
|
|
103
|
+
from master.sample.processing import _clean_features_df
|
|
104
|
+
from master.sample.processing import _features_deisotope
|
|
105
|
+
from master.sample.processing import _get_ztscan_stats
|
|
106
|
+
from master.sample.processing import _spec_to_mat
|
|
107
|
+
from master.sample.processing import analyze_dda
|
|
108
|
+
from master.sample.processing import find_features
|
|
109
|
+
from master.sample.processing import find_ms2
|
|
110
|
+
from master.sample.processing import get_spectrum
|
|
111
|
+
from master.sample.parameters import store_history
|
|
112
|
+
from master.sample.parameters import get_parameters
|
|
113
|
+
from master.sample.parameters import update_parameters
|
|
114
|
+
from master.sample.parameters import get_parameters_property
|
|
115
|
+
from master.sample.parameters import set_parameters_property
|
|
116
|
+
from master.sample.save import _save_featureXML
|
|
117
|
+
from master.sample.save import export_chrom
|
|
118
|
+
from master.sample.save import export_dda_stats
|
|
119
|
+
from master.sample.save import export_features
|
|
120
|
+
from master.sample.save import export_mgf
|
|
121
|
+
from master.sample.save import save
|
|
121
122
|
|
|
122
123
|
|
|
123
124
|
class Sample:
|
|
@@ -179,7 +180,7 @@ class Sample:
|
|
|
179
180
|
self.log_sink = params.log_sink
|
|
180
181
|
|
|
181
182
|
# Initialize independent logger
|
|
182
|
-
self.logger =
|
|
183
|
+
self.logger = MasterLogger(
|
|
183
184
|
instance_type="sample",
|
|
184
185
|
level=params.log_level.upper(),
|
|
185
186
|
label=params.log_label if params.log_label else "",
|
|
@@ -298,7 +299,12 @@ class Sample:
|
|
|
298
299
|
find_ms2_defaults = find_ms2_defaults
|
|
299
300
|
get_spectrum_defaults = get_spectrum_defaults
|
|
300
301
|
|
|
301
|
-
def logger_update(
|
|
302
|
+
def logger_update(
|
|
303
|
+
self,
|
|
304
|
+
level: str | None = None,
|
|
305
|
+
label: str | None = None,
|
|
306
|
+
sink: str | None = None,
|
|
307
|
+
):
|
|
302
308
|
"""Update the logging configuration for this Sample instance.
|
|
303
309
|
|
|
304
310
|
Args:
|
|
@@ -323,20 +329,20 @@ class Sample:
|
|
|
323
329
|
|
|
324
330
|
def _reload(self):
|
|
325
331
|
"""
|
|
326
|
-
Reloads all
|
|
332
|
+
Reloads all master modules to pick up any changes to their source code,
|
|
327
333
|
and updates the instance's class reference to the newly reloaded class version.
|
|
328
334
|
This ensures that the instance uses the latest implementation without restarting the interpreter.
|
|
329
335
|
"""
|
|
330
336
|
# Reset logger configuration flags to allow proper reconfiguration after reload
|
|
331
337
|
try:
|
|
332
|
-
import
|
|
338
|
+
import master.logger as logger_module
|
|
333
339
|
|
|
334
340
|
if hasattr(logger_module, "_SAMPLE_LOGGER_CONFIGURED"):
|
|
335
341
|
logger_module._SAMPLE_LOGGER_CONFIGURED = False
|
|
336
342
|
except Exception:
|
|
337
343
|
pass
|
|
338
344
|
|
|
339
|
-
# Get the base module name (
|
|
345
|
+
# Get the base module name (master)
|
|
340
346
|
base_modname = self.__class__.__module__.split(".")[0]
|
|
341
347
|
current_module = self.__class__.__module__
|
|
342
348
|
|
|
@@ -346,10 +352,13 @@ class Sample:
|
|
|
346
352
|
|
|
347
353
|
# Get all currently loaded modules that are part of the sample package
|
|
348
354
|
for module_name in sys.modules:
|
|
349
|
-
if
|
|
355
|
+
if (
|
|
356
|
+
module_name.startswith(sample_module_prefix)
|
|
357
|
+
and module_name != current_module
|
|
358
|
+
):
|
|
350
359
|
sample_modules.append(module_name)
|
|
351
360
|
|
|
352
|
-
# Add core
|
|
361
|
+
# Add core master modules
|
|
353
362
|
core_modules = [
|
|
354
363
|
f"{base_modname}._version",
|
|
355
364
|
f"{base_modname}.chromatogram",
|
|
@@ -361,7 +370,10 @@ class Sample:
|
|
|
361
370
|
study_modules = []
|
|
362
371
|
study_module_prefix = f"{base_modname}.study."
|
|
363
372
|
for module_name in sys.modules:
|
|
364
|
-
if
|
|
373
|
+
if (
|
|
374
|
+
module_name.startswith(study_module_prefix)
|
|
375
|
+
and module_name != current_module
|
|
376
|
+
):
|
|
365
377
|
study_modules.append(module_name)
|
|
366
378
|
|
|
367
379
|
""" # Add parameters submodules
|
|
@@ -372,7 +384,9 @@ class Sample:
|
|
|
372
384
|
parameters_modules.append(module_name)
|
|
373
385
|
"""
|
|
374
386
|
|
|
375
|
-
all_modules_to_reload =
|
|
387
|
+
all_modules_to_reload = (
|
|
388
|
+
core_modules + sample_modules + study_modules
|
|
389
|
+
) # + parameters_modules
|
|
376
390
|
|
|
377
391
|
# Reload all discovered modules
|
|
378
392
|
for full_module_name in all_modules_to_reload:
|
|
@@ -401,7 +415,6 @@ class Sample:
|
|
|
401
415
|
def get_version(self):
|
|
402
416
|
return get_version()
|
|
403
417
|
|
|
404
|
-
|
|
405
418
|
def info(self):
|
|
406
419
|
# show the key attributes of the object
|
|
407
420
|
str = f"File: {os.path.basename(self.file_path)}\n"
|
|
@@ -424,9 +437,9 @@ class Sample:
|
|
|
424
437
|
|
|
425
438
|
def __str__(self):
|
|
426
439
|
if self.features_df is None:
|
|
427
|
-
str = f"
|
|
440
|
+
str = f"master Sample, source: {os.path.basename(self.file_path)}, features: 0"
|
|
428
441
|
else:
|
|
429
|
-
str = f"
|
|
442
|
+
str = f"master Sample, source: {os.path.basename(self.file_path)}, features: {len(self.features_df)}"
|
|
430
443
|
return str
|
|
431
444
|
|
|
432
445
|
|
|
@@ -1,47 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"features_df": {
|
|
3
3
|
"columns": {
|
|
4
|
-
"
|
|
5
|
-
"dtype": "pl.Int64"
|
|
6
|
-
},
|
|
7
|
-
"feature_id": {
|
|
4
|
+
"adduct": {
|
|
8
5
|
"dtype": "pl.Utf8"
|
|
9
6
|
},
|
|
10
|
-
"
|
|
11
|
-
"dtype": "pl.
|
|
7
|
+
"adduct_charge": {
|
|
8
|
+
"dtype": "pl.Int64"
|
|
12
9
|
},
|
|
13
|
-
"
|
|
14
|
-
"dtype": "pl.
|
|
10
|
+
"adduct_group": {
|
|
11
|
+
"dtype": "pl.Int64"
|
|
15
12
|
},
|
|
16
|
-
"
|
|
13
|
+
"adduct_mass_neutral": {
|
|
17
14
|
"dtype": "pl.Float64"
|
|
18
15
|
},
|
|
19
|
-
"
|
|
16
|
+
"adduct_mass_shift": {
|
|
20
17
|
"dtype": "pl.Float64"
|
|
21
18
|
},
|
|
22
|
-
"
|
|
23
|
-
"dtype": "pl.
|
|
19
|
+
"charge": {
|
|
20
|
+
"dtype": "pl.Int32"
|
|
24
21
|
},
|
|
25
|
-
"
|
|
26
|
-
"dtype": "pl.
|
|
22
|
+
"chrom": {
|
|
23
|
+
"dtype": "pl.Object"
|
|
27
24
|
},
|
|
28
|
-
"
|
|
25
|
+
"chrom_area": {
|
|
29
26
|
"dtype": "pl.Float64"
|
|
30
27
|
},
|
|
31
|
-
"
|
|
28
|
+
"chrom_coherence": {
|
|
32
29
|
"dtype": "pl.Float64"
|
|
33
30
|
},
|
|
34
|
-
"
|
|
31
|
+
"chrom_height_scaled": {
|
|
35
32
|
"dtype": "pl.Float64"
|
|
36
33
|
},
|
|
37
|
-
"
|
|
34
|
+
"chrom_prominence": {
|
|
38
35
|
"dtype": "pl.Float64"
|
|
39
36
|
},
|
|
40
|
-
"
|
|
37
|
+
"chrom_prominence_scaled": {
|
|
41
38
|
"dtype": "pl.Float64"
|
|
42
39
|
},
|
|
43
|
-
"
|
|
44
|
-
"dtype": "pl.
|
|
40
|
+
"feature_id": {
|
|
41
|
+
"dtype": "pl.Utf8"
|
|
42
|
+
},
|
|
43
|
+
"feature_uid": {
|
|
44
|
+
"dtype": "pl.Int64"
|
|
45
|
+
},
|
|
46
|
+
"filled": {
|
|
47
|
+
"dtype": "pl.Boolean"
|
|
48
|
+
},
|
|
49
|
+
"inty": {
|
|
50
|
+
"dtype": "pl.Float64"
|
|
45
51
|
},
|
|
46
52
|
"iso": {
|
|
47
53
|
"dtype": "pl.Int64"
|
|
@@ -49,47 +55,41 @@
|
|
|
49
55
|
"iso_of": {
|
|
50
56
|
"dtype": "pl.Int64"
|
|
51
57
|
},
|
|
52
|
-
"
|
|
53
|
-
"dtype": "pl.
|
|
58
|
+
"ms2_scans": {
|
|
59
|
+
"dtype": "pl.Object"
|
|
54
60
|
},
|
|
55
|
-
"
|
|
56
|
-
"dtype": "pl.
|
|
61
|
+
"ms2_specs": {
|
|
62
|
+
"dtype": "pl.Object"
|
|
57
63
|
},
|
|
58
|
-
"
|
|
64
|
+
"mz": {
|
|
59
65
|
"dtype": "pl.Float64"
|
|
60
66
|
},
|
|
61
|
-
"
|
|
67
|
+
"mz_end": {
|
|
62
68
|
"dtype": "pl.Float64"
|
|
63
69
|
},
|
|
64
|
-
"
|
|
65
|
-
"dtype": "pl.
|
|
66
|
-
},
|
|
67
|
-
"chrom": {
|
|
68
|
-
"dtype": "pl.Object"
|
|
69
|
-
},
|
|
70
|
-
"filled": {
|
|
71
|
-
"dtype": "pl.Boolean"
|
|
70
|
+
"mz_start": {
|
|
71
|
+
"dtype": "pl.Float64"
|
|
72
72
|
},
|
|
73
|
-
"
|
|
73
|
+
"quality": {
|
|
74
74
|
"dtype": "pl.Float64"
|
|
75
75
|
},
|
|
76
|
-
"
|
|
76
|
+
"rt": {
|
|
77
77
|
"dtype": "pl.Float64"
|
|
78
78
|
},
|
|
79
|
-
"
|
|
79
|
+
"rt_delta": {
|
|
80
80
|
"dtype": "pl.Float64"
|
|
81
81
|
},
|
|
82
|
-
"
|
|
82
|
+
"rt_end": {
|
|
83
83
|
"dtype": "pl.Float64"
|
|
84
84
|
},
|
|
85
|
-
"
|
|
85
|
+
"rt_original": {
|
|
86
86
|
"dtype": "pl.Float64"
|
|
87
87
|
},
|
|
88
|
-
"
|
|
89
|
-
"dtype": "pl.
|
|
88
|
+
"rt_start": {
|
|
89
|
+
"dtype": "pl.Float64"
|
|
90
90
|
},
|
|
91
|
-
"
|
|
92
|
-
"dtype": "pl.
|
|
91
|
+
"sample_uid": {
|
|
92
|
+
"dtype": "pl.Int32"
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
},
|
masster/sample/save.py
CHANGED
|
@@ -67,7 +67,7 @@ import pyopenms as oms
|
|
|
67
67
|
from tqdm import tqdm
|
|
68
68
|
|
|
69
69
|
# Parameters removed - using hardcoded defaults
|
|
70
|
-
from
|
|
70
|
+
from master.spectrum import combine_peaks
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
def save(self, filename=None):
|
|
@@ -139,9 +139,13 @@ def export_features(self, filename="features.csv"):
|
|
|
139
139
|
clean_df = clean_df.with_columns(
|
|
140
140
|
(pl.col("ms2_scans").is_not_null()).alias("has_ms2"),
|
|
141
141
|
)
|
|
142
|
-
clean_df = self.features_df.select(
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
clean_df = self.features_df.select(
|
|
143
|
+
[
|
|
144
|
+
col
|
|
145
|
+
for col in self.features_df.columns
|
|
146
|
+
if self.features_df[col].dtype not in (pl.List, pl.Object)
|
|
147
|
+
],
|
|
148
|
+
)
|
|
145
149
|
if filename.lower().endswith((".xls", ".xlsx")):
|
|
146
150
|
clean_df.to_pandas().to_excel(filename, index=False)
|
|
147
151
|
self.logger.info(f"Features exported to {filename} (Excel format)")
|
|
@@ -275,7 +279,10 @@ def export_mgf(
|
|
|
275
279
|
if spect.ms_level > 1 and hasattr(spect, "energy"):
|
|
276
280
|
f.write(f"ENERGY={spect.energy}\n")
|
|
277
281
|
# Use list comprehension for better performance
|
|
278
|
-
peak_lines = [
|
|
282
|
+
peak_lines = [
|
|
283
|
+
f"{mz_val:.5f} {inty_val:.0f}\n"
|
|
284
|
+
for mz_val, inty_val in zip(spect.mz, spect.inty, strict=False)
|
|
285
|
+
]
|
|
279
286
|
f.writelines(peak_lines)
|
|
280
287
|
f.write("END IONS\n\n")
|
|
281
288
|
|
|
@@ -287,7 +294,8 @@ def export_mgf(
|
|
|
287
294
|
|
|
288
295
|
# count how many features have charge < 0
|
|
289
296
|
if (
|
|
290
|
-
self.features_df.filter(pl.col("charge") < 0).shape[0]
|
|
297
|
+
self.features_df.filter(pl.col("charge") < 0).shape[0]
|
|
298
|
+
- self.features_df.filter(pl.col("charge") > 0).shape[0]
|
|
291
299
|
> 0
|
|
292
300
|
):
|
|
293
301
|
preferred_charge = -1
|
|
@@ -388,7 +396,9 @@ def export_mgf(
|
|
|
388
396
|
q1_max=q1_ratio_max,
|
|
389
397
|
)
|
|
390
398
|
# Get the corresponding scan_uid from the list
|
|
391
|
-
current_scan_uid =
|
|
399
|
+
current_scan_uid = (
|
|
400
|
+
scan_uids[i] if i < len(scan_uids) else "unknown"
|
|
401
|
+
)
|
|
392
402
|
write_ion(
|
|
393
403
|
f,
|
|
394
404
|
f"fid:{feature_uid}, rt:{rt_str}, mz:{mz_str}, scan_uid:{current_scan_uid}",
|
|
@@ -411,7 +421,12 @@ def export_mgf(
|
|
|
411
421
|
for scan_uid in ms2_scan_uids:
|
|
412
422
|
spec = self.get_spectrum(scan_uid)
|
|
413
423
|
if spec is not None:
|
|
414
|
-
spectra_with_energy.append(
|
|
424
|
+
spectra_with_energy.append(
|
|
425
|
+
(
|
|
426
|
+
scan_uid,
|
|
427
|
+
spec.energy if hasattr(spec, "energy") else 0,
|
|
428
|
+
),
|
|
429
|
+
)
|
|
415
430
|
|
|
416
431
|
# Group by energy
|
|
417
432
|
energy_groups: dict[float, list[int]] = {}
|
|
@@ -496,14 +511,18 @@ def export_mgf(
|
|
|
496
511
|
spect = spect.centroid(
|
|
497
512
|
tolerance=self.parameters["mz_tol_ms1_da"],
|
|
498
513
|
ppm=self.parameters["mz_tol_ms1_ppm"],
|
|
499
|
-
min_points=self.parameters[
|
|
514
|
+
min_points=self.parameters[
|
|
515
|
+
"centroid_min_points_ms1"
|
|
516
|
+
],
|
|
500
517
|
algo=centroid_algo,
|
|
501
518
|
)
|
|
502
519
|
elif spect.ms_level == 2:
|
|
503
520
|
spect = spect.centroid(
|
|
504
521
|
tolerance=self.parameters["mz_tol_ms2_da"],
|
|
505
522
|
ppm=self.parameters["mz_tol_ms2_ppm"],
|
|
506
|
-
min_points=self.parameters[
|
|
523
|
+
min_points=self.parameters[
|
|
524
|
+
"centroid_min_points_ms2"
|
|
525
|
+
],
|
|
507
526
|
algo=centroid_algo,
|
|
508
527
|
)
|
|
509
528
|
if deisotope:
|
|
@@ -595,7 +614,9 @@ def export_dda_stats(self, filename="stats.csv"):
|
|
|
595
614
|
ms2_count = len(self.scans_df.filter(pl.col("ms_level") == 2))
|
|
596
615
|
features_count = len(self.features_df) if self.features_df is not None else 0
|
|
597
616
|
features_with_ms2 = (
|
|
598
|
-
self.features_df.filter(pl.col("ms2_scans").is_not_null()).height
|
|
617
|
+
self.features_df.filter(pl.col("ms2_scans").is_not_null()).height
|
|
618
|
+
if self.features_df is not None
|
|
619
|
+
else 0
|
|
599
620
|
)
|
|
600
621
|
|
|
601
622
|
# Initialize a dictionary to hold statistics
|
|
@@ -610,7 +631,9 @@ def export_dda_stats(self, filename="stats.csv"):
|
|
|
610
631
|
if "time_cycle" in self.scans_df.columns:
|
|
611
632
|
ms1_df = self.scans_df.filter(pl.col("ms_level") == 1)
|
|
612
633
|
avg_cycle_time = ms1_df["time_cycle"].mean()
|
|
613
|
-
stats["Average_cycle_time"] =
|
|
634
|
+
stats["Average_cycle_time"] = (
|
|
635
|
+
avg_cycle_time if avg_cycle_time is not None else ""
|
|
636
|
+
)
|
|
614
637
|
else:
|
|
615
638
|
stats["Average_cycle_time"] = 0
|
|
616
639
|
|
masster/spectrum.py
CHANGED
|
@@ -138,7 +138,7 @@ class Spectrum:
|
|
|
138
138
|
|
|
139
139
|
Example Usage:
|
|
140
140
|
>>> import numpy as np
|
|
141
|
-
>>> from
|
|
141
|
+
>>> from master import spec
|
|
142
142
|
>>> mz = np.array([100.0, 150.0, 200.0, 250.0])
|
|
143
143
|
>>> intensity = np.array([1000, 5000, 3000, 800])
|
|
144
144
|
>>> spectrum = spec(mz=mz, inty=intensity, ms_level=1)
|
masster/study/__init__.py
CHANGED
|
@@ -298,7 +298,11 @@ class align_defaults:
|
|
|
298
298
|
"dtype": str,
|
|
299
299
|
"description": "Method to use for extrapolation outside the data range in LOWESS",
|
|
300
300
|
"default": "four-point-linear",
|
|
301
|
-
"allowed_values": [
|
|
301
|
+
"allowed_values": [
|
|
302
|
+
"two-point-linear",
|
|
303
|
+
"four-point-linear",
|
|
304
|
+
"global-linear",
|
|
305
|
+
],
|
|
302
306
|
},
|
|
303
307
|
},
|
|
304
308
|
repr=False,
|
|
@@ -158,7 +158,9 @@ class identify_defaults:
|
|
|
158
158
|
if not isinstance(value, list):
|
|
159
159
|
return False
|
|
160
160
|
# For heteroatoms, ensure all elements are strings
|
|
161
|
-
if param_name == "heteroatoms" and not all(
|
|
161
|
+
if param_name == "heteroatoms" and not all(
|
|
162
|
+
isinstance(item, str) for item in value
|
|
163
|
+
):
|
|
162
164
|
return False
|
|
163
165
|
|
|
164
166
|
# Range validation for numeric types
|