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