CoreMS 4.0.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.
- corems/__init__.py +63 -0
- corems/chroma_peak/__init__.py +0 -0
- corems/chroma_peak/calc/ChromaPeakCalc.py +480 -0
- corems/chroma_peak/calc/__init__.py +0 -0
- corems/chroma_peak/calc/subset.py +196 -0
- corems/chroma_peak/factory/__init__.py +0 -0
- corems/chroma_peak/factory/chroma_peak_classes.py +1178 -0
- corems/encapsulation/__init__.py +0 -0
- corems/encapsulation/constant.py +1283 -0
- corems/encapsulation/factory/__init__.py +0 -0
- corems/encapsulation/factory/parameters.py +392 -0
- corems/encapsulation/factory/processingSetting.py +1244 -0
- corems/encapsulation/input/__init__.py +0 -0
- corems/encapsulation/input/parameter_from_json.py +579 -0
- corems/encapsulation/output/__init__.py +0 -0
- corems/encapsulation/output/parameter_to_dict.py +142 -0
- corems/encapsulation/output/parameter_to_json.py +332 -0
- corems/mass_spectra/__init__.py +0 -0
- corems/mass_spectra/calc/GC_Calc.py +84 -0
- corems/mass_spectra/calc/GC_Deconvolution.py +558 -0
- corems/mass_spectra/calc/GC_RI_Calibration.py +44 -0
- corems/mass_spectra/calc/MZSearch.py +249 -0
- corems/mass_spectra/calc/SignalProcessing.py +656 -0
- corems/mass_spectra/calc/__init__.py +0 -0
- corems/mass_spectra/calc/lc_calc.py +5790 -0
- corems/mass_spectra/calc/lc_calc_operations.py +1127 -0
- corems/mass_spectra/factory/GC_Class.py +791 -0
- corems/mass_spectra/factory/__init__.py +0 -0
- corems/mass_spectra/factory/chromat_data.py +51 -0
- corems/mass_spectra/factory/lc_class.py +2721 -0
- corems/mass_spectra/input/__init__.py +0 -0
- corems/mass_spectra/input/andiNetCDF.py +200 -0
- corems/mass_spectra/input/boosterHDF5.py +216 -0
- corems/mass_spectra/input/brukerSolarix.py +153 -0
- corems/mass_spectra/input/brukerSolarix_utils.py +73 -0
- corems/mass_spectra/input/corems_hdf5.py +1710 -0
- corems/mass_spectra/input/massList.py +133 -0
- corems/mass_spectra/input/mzml.py +668 -0
- corems/mass_spectra/input/parserbase.py +239 -0
- corems/mass_spectra/input/rawFileReader.py +1839 -0
- corems/mass_spectra/output/__init__.py +0 -0
- corems/mass_spectra/output/export.py +2800 -0
- corems/mass_spectrum/__init__.py +0 -0
- corems/mass_spectrum/calc/AutoRecalibration.py +237 -0
- corems/mass_spectrum/calc/Calibration.py +602 -0
- corems/mass_spectrum/calc/CalibrationCalc.py +253 -0
- corems/mass_spectrum/calc/KendrickGroup.py +239 -0
- corems/mass_spectrum/calc/MassErrorPrediction.py +436 -0
- corems/mass_spectrum/calc/MassSpectrumCalc.py +303 -0
- corems/mass_spectrum/calc/MeanResolvingPowerFilter.py +212 -0
- corems/mass_spectrum/calc/NoiseCalc.py +371 -0
- corems/mass_spectrum/calc/NoiseCalc_Bayes.py +93 -0
- corems/mass_spectrum/calc/PeakPicking.py +994 -0
- corems/mass_spectrum/calc/__init__.py +0 -0
- corems/mass_spectrum/factory/MassSpectrumClasses.py +1753 -0
- corems/mass_spectrum/factory/__init__.py +0 -0
- corems/mass_spectrum/input/__init__.py +0 -0
- corems/mass_spectrum/input/baseClass.py +531 -0
- corems/mass_spectrum/input/boosterHDF5.py +161 -0
- corems/mass_spectrum/input/coremsHDF5.py +475 -0
- corems/mass_spectrum/input/massList.py +402 -0
- corems/mass_spectrum/input/numpyArray.py +133 -0
- corems/mass_spectrum/output/__init__.py +0 -0
- corems/mass_spectrum/output/export.py +841 -0
- corems/molecular_formula/__init__.py +0 -0
- corems/molecular_formula/calc/MolecularFormulaCalc.py +885 -0
- corems/molecular_formula/calc/__init__.py +0 -0
- corems/molecular_formula/factory/MolecularFormulaFactory.py +895 -0
- corems/molecular_formula/factory/__init__.py +0 -0
- corems/molecular_formula/input/__init__.py +0 -0
- corems/molecular_formula/input/masslist_ref.py +355 -0
- corems/molecular_id/__init__.py +0 -0
- corems/molecular_id/calc/ClusterFilter.py +251 -0
- corems/molecular_id/calc/MolecularFilter.py +122 -0
- corems/molecular_id/calc/SpectralSimilarity.py +632 -0
- corems/molecular_id/calc/__init__.py +0 -0
- corems/molecular_id/calc/math_distance.py +1637 -0
- corems/molecular_id/data/FAMES_REF.msp +980 -0
- corems/molecular_id/data/PNNLMetV20191015.msp +157267 -0
- corems/molecular_id/factory/EI_SQL.py +650 -0
- corems/molecular_id/factory/MolecularLookupTable.py +914 -0
- corems/molecular_id/factory/__init__.py +0 -0
- corems/molecular_id/factory/classification.py +884 -0
- corems/molecular_id/factory/lipid_molecular_metadata.py +50 -0
- corems/molecular_id/factory/molecularSQL.py +827 -0
- corems/molecular_id/factory/spectrum_search_results.py +119 -0
- corems/molecular_id/input/__init__.py +0 -0
- corems/molecular_id/input/nistMSI.py +148 -0
- corems/molecular_id/search/__init__.py +0 -0
- corems/molecular_id/search/compoundSearch.py +214 -0
- corems/molecular_id/search/database_interfaces.py +1527 -0
- corems/molecular_id/search/findOxygenPeaks.py +330 -0
- corems/molecular_id/search/lcms_spectral_search.py +348 -0
- corems/molecular_id/search/molecularFormulaSearch.py +1117 -0
- corems/molecular_id/search/priorityAssignment.py +723 -0
- corems/ms_peak/__init__.py +0 -0
- corems/ms_peak/calc/MSPeakCalc.py +1010 -0
- corems/ms_peak/calc/__init__.py +0 -0
- corems/ms_peak/factory/MSPeakClasses.py +542 -0
- corems/ms_peak/factory/__init__.py +0 -0
- corems/transient/__init__.py +0 -0
- corems/transient/calc/TransientCalc.py +362 -0
- corems/transient/calc/__init__.py +0 -0
- corems/transient/factory/TransientClasses.py +457 -0
- corems/transient/factory/__init__.py +0 -0
- corems/transient/input/__init__.py +0 -0
- corems/transient/input/brukerSolarix.py +461 -0
- corems/transient/input/midasDatFile.py +172 -0
- corems-4.0.0.dist-info/METADATA +475 -0
- corems-4.0.0.dist-info/RECORD +171 -0
- corems-4.0.0.dist-info/WHEEL +5 -0
- corems-4.0.0.dist-info/licenses/LICENSE +22 -0
- corems-4.0.0.dist-info/top_level.txt +4 -0
- examples/archive/scripts/CoreMS_tutorial.py +94 -0
- examples/archive/scripts/DI HR-MS Halogens Bruker.py +196 -0
- examples/archive/scripts/DI HR-MS MassList.py +385 -0
- examples/archive/scripts/GC-MS MetabRef.py +213 -0
- examples/archive/scripts/GC-MS NetCDF.py +217 -0
- examples/archive/scripts/HR-MS Thermo Raw 21T.py +136 -0
- examples/archive/scripts/LC-ICPMS_metal_peaks.py +297 -0
- examples/archive/scripts/LCMS-Thermo.py +460 -0
- examples/archive/scripts/LCMS_isotopes.py +283 -0
- examples/archive/scripts/MSParams_example.py +21 -0
- examples/archive/scripts/Molecular Formula Data Aggreation.py +84 -0
- examples/archive/scripts/Single Mz Search.py +69 -0
- examples/test_notebooks.py +145 -0
- ext_lib/ChemstationMSFileReader.dll +0 -0
- ext_lib/ChemstationMSFileReader.xml +126 -0
- ext_lib/RawFileReaderLicense.doc +0 -0
- ext_lib/ThermoFisher.CommonCore.BackgroundSubtraction.dll +0 -0
- ext_lib/ThermoFisher.CommonCore.BackgroundSubtraction.xml +2307 -0
- ext_lib/ThermoFisher.CommonCore.Data.dll +0 -0
- ext_lib/ThermoFisher.CommonCore.Data.xml +28974 -0
- ext_lib/ThermoFisher.CommonCore.MassPrecisionEstimator.dll +0 -0
- ext_lib/ThermoFisher.CommonCore.MassPrecisionEstimator.xml +241 -0
- ext_lib/ThermoFisher.CommonCore.RawFileReader.dll +0 -0
- ext_lib/ThermoFisher.CommonCore.RawFileReader.xml +31174 -0
- ext_lib/__init__.py +0 -0
- ext_lib/dotnet/OpenMcdf.Extensions.dll +0 -0
- ext_lib/dotnet/OpenMcdf.dll +0 -0
- ext_lib/dotnet/OpenMcdf.xml +1154 -0
- ext_lib/dotnet/System.IO.FileSystem.AccessControl.dll +0 -0
- ext_lib/dotnet/System.IO.FileSystem.AccessControl.xml +506 -0
- ext_lib/dotnet/System.Security.AccessControl.dll +0 -0
- ext_lib/dotnet/System.Security.AccessControl.xml +2043 -0
- ext_lib/dotnet/System.Security.Principal.Windows.dll +0 -0
- ext_lib/dotnet/System.Security.Principal.Windows.xml +1011 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.BackgroundSubtraction.dll +0 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.BackgroundSubtraction.xml +2307 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.Data.dll +0 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.Data.xml +29148 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.MassPrecisionEstimator.dll +0 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.MassPrecisionEstimator.xml +241 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.RawFileReader.dll +0 -0
- ext_lib/dotnet/ThermoFisher.CommonCore.RawFileReader.xml +31492 -0
- ext_lib/version +18 -0
- support_code/atom_parsers/AtomsDescription.py +359 -0
- support_code/atom_parsers/CreateAtomsDescription.py +56 -0
- support_code/nmdc/filefinder.py +90 -0
- support_code/nmdc/lipidomics/lipidomics_workflow.py +748 -0
- support_code/nmdc/lipidomics/manifest_examples.py +49 -0
- support_code/nmdc/metabolomics/gcms_workflow.py +158 -0
- support_code/nmdc/metabolomics/lcms_metabolomics_targeted_search.py +59 -0
- support_code/nmdc/metabolomics/lcms_metabolomics_workflow.py +248 -0
- support_code/nmdc/metabolomics/metabolomics_collection.py +628 -0
- support_code/nmdc/metadata/dms_api.py +42 -0
- support_code/nmdc/nom/archived_scripts/nmdc_metadata_gen.py +288 -0
- support_code/nmdc/nom/archived_scripts/nom_grow_workflow.py +209 -0
- support_code/nmdc/nom/nom_workflow.py +312 -0
- support_code/windows_only_importers/BrukerCompassXtract.py +180 -0
- support_code/windows_only_importers/ThermoMSFileReader.py +405 -0
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
from comtypes import byref
|
|
2
|
+
from comtypes.automation import BSTR, VARIANT
|
|
3
|
+
from comtypes.client import CreateObject
|
|
4
|
+
from ctypes import c_double, c_long
|
|
5
|
+
|
|
6
|
+
from corems.encapsulation.factory.parameters import default_parameters
|
|
7
|
+
from corems.mass_spectra.factory.LC_Class import LCMSBase
|
|
8
|
+
from corems.mass_spectrum.factory.MassSpectrumClasses import MassSpecProfile, MassSpecCentroid
|
|
9
|
+
from corems.encapsulation.constant import Labels
|
|
10
|
+
|
|
11
|
+
from threading import Thread
|
|
12
|
+
import multiprocessing
|
|
13
|
+
import numpy
|
|
14
|
+
|
|
15
|
+
__author__ = "Yuri E. Corilo"
|
|
16
|
+
__date__ = "July 9, 2019"
|
|
17
|
+
|
|
18
|
+
from threading import Thread
|
|
19
|
+
from typing import List, Dict, Any, Tuple
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
class ImportMassSpectraThermoMSFileReader(Thread):
|
|
23
|
+
"""
|
|
24
|
+
A class for importing mass spectra from Thermo MS file reader.
|
|
25
|
+
|
|
26
|
+
Parameters:
|
|
27
|
+
-----------
|
|
28
|
+
file_location : str
|
|
29
|
+
The file location of the Thermo MS file.
|
|
30
|
+
|
|
31
|
+
Attributes:
|
|
32
|
+
-----------
|
|
33
|
+
thermo_Library : object
|
|
34
|
+
The Thermo MS file reader library object.
|
|
35
|
+
res : int
|
|
36
|
+
The result of setting the current controller.
|
|
37
|
+
LCMS : LCMSBase
|
|
38
|
+
The LCMSBase object for storing the imported mass spectra.
|
|
39
|
+
_initial_scan_number : int
|
|
40
|
+
The initial scan number for importing mass spectra.
|
|
41
|
+
_final_scan_number : int
|
|
42
|
+
The final scan number for importing mass spectra.
|
|
43
|
+
file_location : str
|
|
44
|
+
The file location of the Thermo MS file.
|
|
45
|
+
|
|
46
|
+
Properties:
|
|
47
|
+
-----------
|
|
48
|
+
initial_scan_number : int
|
|
49
|
+
The initial scan number for importing mass spectra.
|
|
50
|
+
final_scan_number : int
|
|
51
|
+
The final scan number for importing mass spectra.
|
|
52
|
+
|
|
53
|
+
Methods:
|
|
54
|
+
--------
|
|
55
|
+
check_scan(scan: int) -> bool:
|
|
56
|
+
Check if the given scan number is valid.
|
|
57
|
+
run() -> None:
|
|
58
|
+
Automatically process mass spectrum in a separate thread.
|
|
59
|
+
get_mass_spectra(auto_process: bool=True) -> LCMSBase:
|
|
60
|
+
Get the imported mass spectra.
|
|
61
|
+
check_load_success() -> bool:
|
|
62
|
+
Check if the Thermo MS file was loaded successfully.
|
|
63
|
+
get_filter_for_scan_num(scan_number: int) -> List[str]:
|
|
64
|
+
Get the filter for the given scan number.
|
|
65
|
+
check_full_scan(scan_number: int) -> bool:
|
|
66
|
+
Check if the scan is a full scan.
|
|
67
|
+
get_polarity_mode(scan_number: int) -> int:
|
|
68
|
+
Get the polarity mode for the given scan number.
|
|
69
|
+
get_data(scan: int, d_parameter: Dict[str, Any]) -> Dict[str, np.ndarray]:
|
|
70
|
+
Get the data for the given scan number.
|
|
71
|
+
get_scans_numbers() -> int:
|
|
72
|
+
Get the total number of scans in the Thermo MS file.
|
|
73
|
+
get_ScanHeaderInfoForScanNum(scan_number: int) -> Tuple[float, float]:
|
|
74
|
+
Get the retention time and TIC for the given scan number.
|
|
75
|
+
is_profile_scan_for_scan_num(scan_number: int) -> bool:
|
|
76
|
+
Check if the scan is a profile scan.
|
|
77
|
+
_import_mass_spectra(d_params: Dict[str, Any], auto_process: bool=True) -> None:
|
|
78
|
+
Import the mass spectra from the Thermo MS file.
|
|
79
|
+
get_lcms() -> LCMSBase:
|
|
80
|
+
Get the LCMSBase object.
|
|
81
|
+
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
def __init__(self, file_location: str):
|
|
85
|
+
Thread.__init__(self)
|
|
86
|
+
self.thermo_Library = CreateObject("MSFileReader.XRawfile")
|
|
87
|
+
self.thermo_Library.open(file_location)
|
|
88
|
+
self.res: int = self.thermo_Library.SetCurrentController(0, 1)
|
|
89
|
+
self.check_load_success()
|
|
90
|
+
self.LCMS: LCMSBase = LCMSBase(file_location)
|
|
91
|
+
self._initial_scan_number: int = 1
|
|
92
|
+
self._final_scan_number: int = self.get_scans_numbers()
|
|
93
|
+
self.file_location: str = file_location
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def initial_scan_number(self) -> int:
|
|
97
|
+
return self._initial_scan_number
|
|
98
|
+
|
|
99
|
+
@initial_scan_number.setter
|
|
100
|
+
def initial_scan_number(self, start_scan_number: int) -> None:
|
|
101
|
+
if self.check_scan(start_scan_number):
|
|
102
|
+
self._initial_scan_number = start_scan_number
|
|
103
|
+
else:
|
|
104
|
+
raise Exception(
|
|
105
|
+
"startscan and finalscan should be less than %s"
|
|
106
|
+
% self.get_scans_numbers()
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def final_scan_number(self) -> int:
|
|
111
|
+
return self._final_scan_number
|
|
112
|
+
|
|
113
|
+
@final_scan_number.setter
|
|
114
|
+
def final_scan_number(self, final_scan_number: int) -> None:
|
|
115
|
+
if self.check_scan(final_scan_number):
|
|
116
|
+
self._final_scan_number = final_scan_number
|
|
117
|
+
else:
|
|
118
|
+
raise Exception(
|
|
119
|
+
"startscan and finalscan should be less than %s"
|
|
120
|
+
% self.get_scans_numbers()
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
def check_scan(self, scan: int) -> bool:
|
|
124
|
+
"""
|
|
125
|
+
Check if the given scan number is valid.
|
|
126
|
+
|
|
127
|
+
Parameters:
|
|
128
|
+
-----------
|
|
129
|
+
scan : int
|
|
130
|
+
The scan number to check.
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
--------
|
|
134
|
+
bool
|
|
135
|
+
True if the scan number is valid, False otherwise.
|
|
136
|
+
"""
|
|
137
|
+
scan_numbers = self.get_scans_numbers()
|
|
138
|
+
return scan <= scan_numbers
|
|
139
|
+
|
|
140
|
+
def run(self) -> None:
|
|
141
|
+
"""
|
|
142
|
+
Automatically process mass spectrum in a separate thread.
|
|
143
|
+
"""
|
|
144
|
+
d_parameters = default_parameters(self.file_location)
|
|
145
|
+
self._import_mass_spectra(d_parameters)
|
|
146
|
+
|
|
147
|
+
def get_mass_spectra(self, auto_process: bool=True) -> LCMSBase:
|
|
148
|
+
"""
|
|
149
|
+
Get the imported mass spectra.
|
|
150
|
+
|
|
151
|
+
Parameters:
|
|
152
|
+
-----------
|
|
153
|
+
auto_process : bool, optional
|
|
154
|
+
Whether to automatically process the mass spectra, by default True.
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
--------
|
|
158
|
+
LCMSBase
|
|
159
|
+
The LCMSBase object containing the imported mass spectra.
|
|
160
|
+
"""
|
|
161
|
+
d_parameters = default_parameters(self.file_location)
|
|
162
|
+
self._import_mass_spectra(d_parameters, auto_process=auto_process)
|
|
163
|
+
return self.LCMS
|
|
164
|
+
|
|
165
|
+
def check_load_success(self) -> bool:
|
|
166
|
+
"""
|
|
167
|
+
Check if the Thermo MS file was loaded successfully.
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
--------
|
|
171
|
+
bool
|
|
172
|
+
True if the Thermo MS file was loaded successfully, False otherwise.
|
|
173
|
+
"""
|
|
174
|
+
if self.res == 0:
|
|
175
|
+
self.break_it = False
|
|
176
|
+
return True
|
|
177
|
+
else:
|
|
178
|
+
raise ImportError(str(self.res))
|
|
179
|
+
|
|
180
|
+
def get_filter_for_scan_num(self, scan_number: int) -> List[str]:
|
|
181
|
+
"""
|
|
182
|
+
Get the filter for the given scan number.
|
|
183
|
+
|
|
184
|
+
Parameters:
|
|
185
|
+
-----------
|
|
186
|
+
scan_number : int
|
|
187
|
+
The scan number.
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
--------
|
|
191
|
+
List[str]
|
|
192
|
+
The filter for the given scan number.
|
|
193
|
+
"""
|
|
194
|
+
str_filter = BSTR(None)
|
|
195
|
+
error = self.thermo_Library.GetFilterForScanNum(scan_number, byref(str_filter))
|
|
196
|
+
if error:
|
|
197
|
+
raise IOError(
|
|
198
|
+
"scan %i GetFilterForScanNum error : %s" % (scan_number, str(error))
|
|
199
|
+
)
|
|
200
|
+
else:
|
|
201
|
+
return str(str_filter.value).split()
|
|
202
|
+
|
|
203
|
+
def check_full_scan(self, scan_number: int) -> bool:
|
|
204
|
+
"""
|
|
205
|
+
Check if the scan is a full scan.
|
|
206
|
+
|
|
207
|
+
Parameters:
|
|
208
|
+
-----------
|
|
209
|
+
scan_number : int
|
|
210
|
+
The scan number.
|
|
211
|
+
|
|
212
|
+
Returns:
|
|
213
|
+
--------
|
|
214
|
+
bool
|
|
215
|
+
True if the scan is a full scan, False otherwise.
|
|
216
|
+
"""
|
|
217
|
+
scan_mode_symbol = self.get_filter_for_scan_num(scan_number)[4]
|
|
218
|
+
return scan_mode_symbol == "Full"
|
|
219
|
+
|
|
220
|
+
def get_polarity_mode(self, scan_number: int) -> int:
|
|
221
|
+
"""
|
|
222
|
+
Get the polarity mode for the given scan number.
|
|
223
|
+
|
|
224
|
+
Parameters:
|
|
225
|
+
-----------
|
|
226
|
+
scan_number : int
|
|
227
|
+
The scan number.
|
|
228
|
+
|
|
229
|
+
Returns:
|
|
230
|
+
--------
|
|
231
|
+
int
|
|
232
|
+
The polarity mode (-1 for negative, 1 for positive).
|
|
233
|
+
"""
|
|
234
|
+
polarity_symbol = self.get_filter_for_scan_num(scan_number)[1]
|
|
235
|
+
if polarity_symbol == "+":
|
|
236
|
+
return 1
|
|
237
|
+
elif polarity_symbol == "-":
|
|
238
|
+
return -1
|
|
239
|
+
else:
|
|
240
|
+
raise Exception("Polarity Mode Unknown, please set it manually")
|
|
241
|
+
|
|
242
|
+
def get_data(self, scan: int, d_parameter: Dict[str, Any]) -> Dict[str, np.ndarray]:
|
|
243
|
+
"""
|
|
244
|
+
Get the data for the given scan number.
|
|
245
|
+
|
|
246
|
+
Parameters:
|
|
247
|
+
-----------
|
|
248
|
+
scan : int
|
|
249
|
+
The scan number.
|
|
250
|
+
d_parameter : Dict[str, Any]
|
|
251
|
+
The dictionary of parameters.
|
|
252
|
+
|
|
253
|
+
Returns:
|
|
254
|
+
--------
|
|
255
|
+
Dict[str, np.ndarray]
|
|
256
|
+
The data dictionary containing the mass list, abundance list, retention time, and signal-to-noise ratio.
|
|
257
|
+
"""
|
|
258
|
+
scan = c_long(scan)
|
|
259
|
+
pvarLabels = VARIANT()
|
|
260
|
+
pvarFlags = VARIANT()
|
|
261
|
+
self.thermo_Library.GetLabelData(pvarLabels, pvarFlags, scan)
|
|
262
|
+
scans_labels = np.array(pvarLabels.value)
|
|
263
|
+
mz = scans_labels[0]
|
|
264
|
+
magnitude = scans_labels[1]
|
|
265
|
+
rp = scans_labels[2]
|
|
266
|
+
base_noise = scans_labels[3]
|
|
267
|
+
noise = scans_labels[4]
|
|
268
|
+
array_noise_std = (np.array(noise) - np.array(base_noise)) / 3
|
|
269
|
+
l_signal_to_noise = np.array(magnitude) / array_noise_std
|
|
270
|
+
d_parameter["baseline_noise"] = np.average(array_noise_std)
|
|
271
|
+
d_parameter["baseline_noise_std"] = np.std(array_noise_std)
|
|
272
|
+
data_dict = {
|
|
273
|
+
Labels.mz: mz,
|
|
274
|
+
Labels.abundance: magnitude,
|
|
275
|
+
Labels.rp: rp,
|
|
276
|
+
Labels.s2n: l_signal_to_noise,
|
|
277
|
+
}
|
|
278
|
+
return data_dict
|
|
279
|
+
|
|
280
|
+
def get_scans_numbers(self) -> int:
|
|
281
|
+
"""
|
|
282
|
+
Get the total number of scans in the Thermo MS file.
|
|
283
|
+
|
|
284
|
+
Returns:
|
|
285
|
+
--------
|
|
286
|
+
int
|
|
287
|
+
The total number of scans.
|
|
288
|
+
"""
|
|
289
|
+
nScans = c_long()
|
|
290
|
+
self.thermo_Library.GetNumSpectra(nScans)
|
|
291
|
+
return int(nScans.value)
|
|
292
|
+
|
|
293
|
+
def get_ScanHeaderInfoForScanNum(self, scan_number: int) -> Tuple[float, float]:
|
|
294
|
+
"""
|
|
295
|
+
Get the retention time and TIC for the given scan number.
|
|
296
|
+
|
|
297
|
+
Parameters:
|
|
298
|
+
-----------
|
|
299
|
+
scan_number : int
|
|
300
|
+
The scan number.
|
|
301
|
+
|
|
302
|
+
Returns:
|
|
303
|
+
--------
|
|
304
|
+
Tuple[float, float]
|
|
305
|
+
The retention time and TIC.
|
|
306
|
+
"""
|
|
307
|
+
nScanNumber = c_long(scan_number)
|
|
308
|
+
nPackets = c_long(0)
|
|
309
|
+
dRetantionTime = c_double(0.0)
|
|
310
|
+
dLowMass = c_double(0.0)
|
|
311
|
+
dHighMass = c_double(0.0)
|
|
312
|
+
dTIC = c_double(0.0)
|
|
313
|
+
dBasePeakMass = c_double(0.0)
|
|
314
|
+
dBasePeakIntensity = c_double(0.0)
|
|
315
|
+
nChannels = c_long(0)
|
|
316
|
+
bUniformTime = c_long(False)
|
|
317
|
+
dFrequency = c_double(0.0)
|
|
318
|
+
self.thermo_Library.GetScanHeaderInfoForScanNum(
|
|
319
|
+
nScanNumber,
|
|
320
|
+
nPackets,
|
|
321
|
+
dRetantionTime,
|
|
322
|
+
dLowMass,
|
|
323
|
+
dHighMass,
|
|
324
|
+
dTIC,
|
|
325
|
+
dBasePeakMass,
|
|
326
|
+
dBasePeakIntensity,
|
|
327
|
+
nChannels,
|
|
328
|
+
bUniformTime,
|
|
329
|
+
dFrequency,
|
|
330
|
+
)
|
|
331
|
+
return dRetantionTime.value, dTIC.value
|
|
332
|
+
|
|
333
|
+
def is_profile_scan_for_scan_num(self, scan_number: int) -> bool:
|
|
334
|
+
"""
|
|
335
|
+
Check if the scan is a profile scan.
|
|
336
|
+
|
|
337
|
+
Parameters:
|
|
338
|
+
-----------
|
|
339
|
+
scan_number : int
|
|
340
|
+
The scan number.
|
|
341
|
+
|
|
342
|
+
Returns:
|
|
343
|
+
--------
|
|
344
|
+
bool
|
|
345
|
+
True if the scan is a profile scan, False otherwise.
|
|
346
|
+
"""
|
|
347
|
+
IsProfileScan = c_long()
|
|
348
|
+
error = self.thermo_Library.IsProfileScanForScanNum(
|
|
349
|
+
c_long(scan_number), byref(IsProfileScan)
|
|
350
|
+
)
|
|
351
|
+
if error:
|
|
352
|
+
raise IOError("IsProfileScanForScanNum error :", error)
|
|
353
|
+
# print (IsProfileScan.value, bool(1))
|
|
354
|
+
return bool(IsProfileScan.value)
|
|
355
|
+
|
|
356
|
+
def _import_mass_spectra(self, d_params: Dict[str, Any], auto_process: bool=True) -> None:
|
|
357
|
+
"""
|
|
358
|
+
Import the mass spectra from the Thermo MS file.
|
|
359
|
+
|
|
360
|
+
Parameters:
|
|
361
|
+
-----------
|
|
362
|
+
d_params : Dict[str, Any]
|
|
363
|
+
The dictionary of parameters.
|
|
364
|
+
auto_process : bool, optional
|
|
365
|
+
Whether to automatically process the mass spectra, by default True.
|
|
366
|
+
"""
|
|
367
|
+
results = []
|
|
368
|
+
if self.check_load_success():
|
|
369
|
+
list_Tics = list()
|
|
370
|
+
list_RetentionTimeSeconds = list()
|
|
371
|
+
list_scans = list()
|
|
372
|
+
for scan_number in range(
|
|
373
|
+
self.initial_scan_number, self.final_scan_number + 1
|
|
374
|
+
):
|
|
375
|
+
if self.check_full_scan(scan_number):
|
|
376
|
+
if self.is_profile_scan_for_scan_num(scan_number):
|
|
377
|
+
d_params["label"] = Labels.thermo_centroid
|
|
378
|
+
d_params["polarity"] = self.get_polarity_mode(scan_number)
|
|
379
|
+
d_params["rt"], TIC = self.get_ScanHeaderInfoForScanNum(
|
|
380
|
+
scan_number
|
|
381
|
+
)
|
|
382
|
+
d_params["scan_number"] = scan_number
|
|
383
|
+
list_RetentionTimeSeconds.append(d_params.get("rt"))
|
|
384
|
+
list_Tics.append(TIC)
|
|
385
|
+
list_scans.append(scan_number)
|
|
386
|
+
data_dict = self.get_data(scan_number, d_params)
|
|
387
|
+
mass_spec = MassSpecCentroid(data_dict, d_params)
|
|
388
|
+
self.LCMS.add_mass_spectrum(mass_spec)
|
|
389
|
+
self.LCMS.retention_time = list_RetentionTimeSeconds
|
|
390
|
+
self.LCMS.set_tic_list(list_Tics)
|
|
391
|
+
self.LCMS.set_scans_number_list(list_scans)
|
|
392
|
+
|
|
393
|
+
def get_lcms(self) -> LCMSBase:
|
|
394
|
+
"""
|
|
395
|
+
Get the LCMSBase object.
|
|
396
|
+
|
|
397
|
+
Returns:
|
|
398
|
+
--------
|
|
399
|
+
LCMSBase
|
|
400
|
+
The LCMSBase object.
|
|
401
|
+
"""
|
|
402
|
+
if self.LCMS.get(self._initial_scan_number):
|
|
403
|
+
return self.LCMS
|
|
404
|
+
else:
|
|
405
|
+
raise Exception("returning an empty LCMS class")
|