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,217 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
warnings.filterwarnings("ignore")
|
|
3
|
+
|
|
4
|
+
import sys
|
|
5
|
+
sys.path.append("./")
|
|
6
|
+
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from multiprocessing import Pool
|
|
9
|
+
import cProfile
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
from corems.molecular_id.input.nistMSI import ReadNistMSI
|
|
13
|
+
from corems.mass_spectra.input.andiNetCDF import ReadAndiNetCDF
|
|
14
|
+
from corems.molecular_id.search.compoundSearch import LowResMassSpectralMatch
|
|
15
|
+
from corems.mass_spectra.calc.GC_RI_Calibration import get_rt_ri_pairs
|
|
16
|
+
from support_code.nmdc.filefinder import get_dirname, get_filename
|
|
17
|
+
|
|
18
|
+
import glob
|
|
19
|
+
|
|
20
|
+
def start_sql_from_file():
|
|
21
|
+
|
|
22
|
+
ref_lib_path = Path.cwd() / "tests/tests_data/gcms/" / "PNNLMetV20191015.MSL"
|
|
23
|
+
sql_obj = ReadNistMSI(ref_lib_path).get_sqlLite_obj()
|
|
24
|
+
return sql_obj
|
|
25
|
+
|
|
26
|
+
def sql_database(file_location):
|
|
27
|
+
|
|
28
|
+
sqlLite_obj = ReadNistMSI(file_location).get_sqlLite_obj()
|
|
29
|
+
|
|
30
|
+
min_max_rt = (18.037, 18.037)
|
|
31
|
+
min_max_ri = (1637.30, 1737.30)
|
|
32
|
+
|
|
33
|
+
sqlLite_obj.query_min_max_ri((1637.30, 1638.30))
|
|
34
|
+
sqlLite_obj.query_min_max_rt((17.111, 18.111))
|
|
35
|
+
sqlLite_obj.query_min_max_ri_and_rt((1637.30, 1638.30), (17.111, 18.111))
|
|
36
|
+
|
|
37
|
+
def stand_alone():
|
|
38
|
+
|
|
39
|
+
file_path = get_filename()
|
|
40
|
+
|
|
41
|
+
reader_gcms = ReadAndiNetCDF(file_path)
|
|
42
|
+
|
|
43
|
+
reader_gcms.run()
|
|
44
|
+
|
|
45
|
+
gcms = reader_gcms.get_gcms_obj()
|
|
46
|
+
|
|
47
|
+
gcms.process_chromatogram()
|
|
48
|
+
|
|
49
|
+
def get_gcms(file_path):
|
|
50
|
+
|
|
51
|
+
reader_gcms = ReadAndiNetCDF(file_path)
|
|
52
|
+
|
|
53
|
+
reader_gcms.run()
|
|
54
|
+
|
|
55
|
+
gcms = reader_gcms.get_gcms_obj()
|
|
56
|
+
|
|
57
|
+
# gcms.process_chromatogram()
|
|
58
|
+
|
|
59
|
+
return gcms
|
|
60
|
+
|
|
61
|
+
def get_reference_dict(calibration_file_path=False):
|
|
62
|
+
|
|
63
|
+
from PySide2.QtWidgets import QFileDialog, QApplication
|
|
64
|
+
from PySide2.QtCore import Qt
|
|
65
|
+
|
|
66
|
+
if not calibration_file_path:
|
|
67
|
+
app = QApplication(sys.argv)
|
|
68
|
+
file_dialog = QFileDialog()
|
|
69
|
+
file_dialog.setWindowFlags(Qt.WindowStaysOnTopHint)
|
|
70
|
+
file_path = file_dialog.getOpenFileName(None, "FAMES REF FILE", filter="*.cdf")[0]
|
|
71
|
+
file_dialog.close()
|
|
72
|
+
app.exit()
|
|
73
|
+
else:
|
|
74
|
+
file_path = calibration_file_path
|
|
75
|
+
|
|
76
|
+
if not file_path:
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
else:
|
|
80
|
+
|
|
81
|
+
gcms_ref_obj = get_gcms(file_path)
|
|
82
|
+
# sql_obj = start_sql_from_file()
|
|
83
|
+
rt_ri_pairs = get_rt_ri_pairs(gcms_ref_obj) # sql_obj=sql_obj)
|
|
84
|
+
# !!!!!! READ !!!!! use the previous two lines if db/pnnl_lowres_gcms_compounds.sqlite does not exist
|
|
85
|
+
# and comment the next line
|
|
86
|
+
# rt_ri_pairs = get_rt_ri_pairs(gcms_ref_obj)
|
|
87
|
+
|
|
88
|
+
return rt_ri_pairs, file_path
|
|
89
|
+
|
|
90
|
+
def run(args):
|
|
91
|
+
|
|
92
|
+
file_path, ref_dict, cal_file_path = args
|
|
93
|
+
|
|
94
|
+
gcms = get_gcms(file_path)
|
|
95
|
+
|
|
96
|
+
gcms.process_chromatogram()
|
|
97
|
+
|
|
98
|
+
gcms.calibrate_ri(ref_dict, cal_file_path)
|
|
99
|
+
|
|
100
|
+
# sql_obj = start_sql_from_file()
|
|
101
|
+
|
|
102
|
+
lowResSearch = LowResMassSpectralMatch(gcms) # sql_obj=sql_obj)
|
|
103
|
+
# !!!!!! READ !!!!! use the previous two lines if db/pnnl_lowres_gcms_compounds.sqlite does not exist
|
|
104
|
+
# and comment the next line
|
|
105
|
+
# lowResSearch = LowResMassSpectralMatch(gcms)
|
|
106
|
+
lowResSearch.run()
|
|
107
|
+
|
|
108
|
+
return gcms
|
|
109
|
+
|
|
110
|
+
def auto_calibrate_and_search(file_locations, output_file_name, jobs, calibration_file_path):
|
|
111
|
+
|
|
112
|
+
ref_dict, cal_file_path = get_reference_dict(calibration_file_path=calibration_file_path)
|
|
113
|
+
|
|
114
|
+
if ref_dict:
|
|
115
|
+
|
|
116
|
+
# run in multiprocessing mode
|
|
117
|
+
pool = Pool(jobs)
|
|
118
|
+
args = [(file_path, ref_dict, cal_file_path) for file_path in file_locations]
|
|
119
|
+
gcmss = pool.map(run, args)
|
|
120
|
+
pool.close()
|
|
121
|
+
pool.join()
|
|
122
|
+
for gcms in gcmss:
|
|
123
|
+
|
|
124
|
+
gcms.to_hdf()
|
|
125
|
+
gcms.to_csv(output_file_name)
|
|
126
|
+
# print(output_file_name)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def calibrate_and_search(out_put_file_name, jobs):
|
|
130
|
+
|
|
131
|
+
from PySide2.QtWidgets import QFileDialog
|
|
132
|
+
from PySide2.QtCore import Qt
|
|
133
|
+
|
|
134
|
+
ref_dict, cal_file_path = get_reference_dict()
|
|
135
|
+
if ref_dict:
|
|
136
|
+
|
|
137
|
+
file_dialog = QFileDialog()
|
|
138
|
+
file_dialog.setWindowFlags(Qt.WindowStaysOnTopHint)
|
|
139
|
+
|
|
140
|
+
if file_dialog:
|
|
141
|
+
|
|
142
|
+
file_locations = file_dialog.getOpenFileNames(None, "Standard Compounds Files", filter="*.cdf")
|
|
143
|
+
file_dialog.close()
|
|
144
|
+
|
|
145
|
+
# run in multiprocessing mode
|
|
146
|
+
pool = Pool(jobs)
|
|
147
|
+
args = [(file_path, ref_dict, cal_file_path) for file_path in file_locations[0]]
|
|
148
|
+
gcmss = pool.map(run, args)
|
|
149
|
+
pool.close()
|
|
150
|
+
pool.join()
|
|
151
|
+
|
|
152
|
+
for file_index, gcms in enumerate(gcmss):
|
|
153
|
+
|
|
154
|
+
file_path = Path(file_locations[0][file_index])
|
|
155
|
+
# print(out_put_file_name)
|
|
156
|
+
|
|
157
|
+
gcms.to_csv(out_put_file_name, write_metadata=True, id_label="emsl:")
|
|
158
|
+
|
|
159
|
+
# gcms.to_excel(out_put_file_name)
|
|
160
|
+
# gcms.to_pandas(out_put_file_name)
|
|
161
|
+
gcms.to_hdf()
|
|
162
|
+
|
|
163
|
+
# df = gcms.get_dataframe()
|
|
164
|
+
# json_data = gcms.to_json()
|
|
165
|
+
|
|
166
|
+
# print(json_data)
|
|
167
|
+
|
|
168
|
+
# gcms.plot_processed_chromatogram()
|
|
169
|
+
|
|
170
|
+
# gcms.plot_gc_peaks()
|
|
171
|
+
|
|
172
|
+
# gcms.plot_chromatogram()
|
|
173
|
+
|
|
174
|
+
# gcms.plot_smoothed_chromatogram()
|
|
175
|
+
|
|
176
|
+
# gcms.plot_baseline_subtraction()
|
|
177
|
+
|
|
178
|
+
# gcms.plot_detected_baseline()
|
|
179
|
+
|
|
180
|
+
# matplotlib.pyplot.show()
|
|
181
|
+
|
|
182
|
+
def worker(args):
|
|
183
|
+
|
|
184
|
+
cProfile.runctx('run(args)', globals(), locals(), 'gc-ms.prof')
|
|
185
|
+
|
|
186
|
+
def auto_process(jobs):
|
|
187
|
+
|
|
188
|
+
import os
|
|
189
|
+
rootdir = get_dirname()
|
|
190
|
+
|
|
191
|
+
out_put_file_names = list(os.walk(rootdir))[0][1]
|
|
192
|
+
|
|
193
|
+
# print(out_put_file_names[0])
|
|
194
|
+
for out_put_file_name in out_put_file_names:
|
|
195
|
+
# print(out_put_file_name)
|
|
196
|
+
|
|
197
|
+
file_locations = glob.glob(str((rootdir / out_put_file_name)) + "/*.cdf")
|
|
198
|
+
calibration_file_path = ''
|
|
199
|
+
for file_path in file_locations:
|
|
200
|
+
if "FAME" in file_path:
|
|
201
|
+
calibration_file_path = file_path
|
|
202
|
+
if calibration_file_path:
|
|
203
|
+
auto_calibrate_and_search(file_locations, out_put_file_name, jobs, calibration_file_path)
|
|
204
|
+
else:
|
|
205
|
+
print("Could not find a calibration experimental file for {}".format(out_put_file_name))
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
if __name__ == '__main__':
|
|
209
|
+
# import matplotlib
|
|
210
|
+
# matplotlib.use('TkAgg')
|
|
211
|
+
# %%
|
|
212
|
+
cores = 4
|
|
213
|
+
out_put_file_group_name = 'sql_test'
|
|
214
|
+
calibrate_and_search(out_put_file_group_name, cores)
|
|
215
|
+
# start_sql_from_file()
|
|
216
|
+
# auto_process(cores)
|
|
217
|
+
# stand_alone()
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
__author__ = "Yuri E. Corilo"
|
|
2
|
+
__date__ = "Jun 09, 2021"
|
|
3
|
+
|
|
4
|
+
import warnings
|
|
5
|
+
warnings.filterwarnings("ignore")
|
|
6
|
+
|
|
7
|
+
import sys
|
|
8
|
+
sys.path.append("./")
|
|
9
|
+
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
import matplotlib.pyplot as plt
|
|
13
|
+
# from PySide2.QtWidgets import QFileDialog, QApplication
|
|
14
|
+
# from PySide2.QtCore import Qt
|
|
15
|
+
|
|
16
|
+
from corems.mass_spectra.input import rawFileReader
|
|
17
|
+
from corems.molecular_id.factory.classification import HeteroatomsClassification, Labels
|
|
18
|
+
from corems.molecular_id.search.priorityAssignment import OxygenPriorityAssignment
|
|
19
|
+
from corems.molecular_id.search.molecularFormulaSearch import SearchMolecularFormulas
|
|
20
|
+
from corems.encapsulation.factory.parameters import MSParameters
|
|
21
|
+
|
|
22
|
+
def run_thermo(file_location):
|
|
23
|
+
|
|
24
|
+
MSParameters.mass_spectrum.noise_threshold_method = 'relative_abundance'
|
|
25
|
+
MSParameters.mass_spectrum.noise_threshold_min_relative_abundance = 0.1
|
|
26
|
+
|
|
27
|
+
# MSParameters.mass_spectrum.noise_threshold_method = 'log'
|
|
28
|
+
# MSParameters.mass_spectrum.noise_threshold_min_s2n = 6
|
|
29
|
+
|
|
30
|
+
parser = rawFileReader.ImportMassSpectraThermoMSFileReader(file_location)
|
|
31
|
+
|
|
32
|
+
parser.chromatogram_settings.scans = (-1, -1)
|
|
33
|
+
|
|
34
|
+
tic_data, ax = parser.get_tic(ms_type='MS', plot=True)
|
|
35
|
+
|
|
36
|
+
plt.show()
|
|
37
|
+
|
|
38
|
+
print(parser.get_all_filters())
|
|
39
|
+
|
|
40
|
+
transient_time_list = parser.get_icr_transient_times()
|
|
41
|
+
|
|
42
|
+
print(transient_time_list)
|
|
43
|
+
|
|
44
|
+
# sums all the mass spectra
|
|
45
|
+
mass_spectrum = parser.get_average_mass_spectrum()
|
|
46
|
+
|
|
47
|
+
# sums scans in selected range
|
|
48
|
+
parser.chromatogram_settings.scans = (1, 10)
|
|
49
|
+
|
|
50
|
+
mass_spectrum = parser.get_average_mass_spectrum()
|
|
51
|
+
|
|
52
|
+
parser.chromatogram_settings.scans = [1]
|
|
53
|
+
# sums scans in selected range
|
|
54
|
+
mass_spectrum = parser.get_average_mass_spectrum()
|
|
55
|
+
|
|
56
|
+
return mass_spectrum
|
|
57
|
+
|
|
58
|
+
def run_assignment(file_location):
|
|
59
|
+
|
|
60
|
+
# mass_spectrum = run_bruker(file_location)
|
|
61
|
+
# mass_spectrum = get_masslist(file_location)
|
|
62
|
+
mass_spectrum = run_thermo(file_location)
|
|
63
|
+
|
|
64
|
+
mass_spectrum.molecular_search_settings.error_method = 'None'
|
|
65
|
+
mass_spectrum.molecular_search_settings.min_ppm_error = -5
|
|
66
|
+
mass_spectrum.molecular_search_settings.max_ppm_error = 5
|
|
67
|
+
|
|
68
|
+
mass_spectrum.molecular_search_settings.url_database = None
|
|
69
|
+
mass_spectrum.molecular_search_settings.min_dbe = 0
|
|
70
|
+
mass_spectrum.molecular_search_settings.max_dbe = 50
|
|
71
|
+
|
|
72
|
+
mass_spectrum.molecular_search_settings.usedAtoms['C'] = (1, 100)
|
|
73
|
+
mass_spectrum.molecular_search_settings.usedAtoms['H'] = (4, 200)
|
|
74
|
+
mass_spectrum.molecular_search_settings.usedAtoms['O'] = (1, 30)
|
|
75
|
+
mass_spectrum.molecular_search_settings.usedAtoms['N'] = (0, 0)
|
|
76
|
+
mass_spectrum.molecular_search_settings.usedAtoms['S'] = (0, 0)
|
|
77
|
+
mass_spectrum.molecular_search_settings.usedAtoms['Cl'] = (0, 0)
|
|
78
|
+
mass_spectrum.molecular_search_settings.usedAtoms['Br'] = (0, 0)
|
|
79
|
+
mass_spectrum.molecular_search_settings.usedAtoms['P'] = (0, 0)
|
|
80
|
+
mass_spectrum.molecular_search_settings.usedAtoms['Na'] = (0, 0)
|
|
81
|
+
|
|
82
|
+
mass_spectrum.molecular_search_settings.isProtonated = True
|
|
83
|
+
mass_spectrum.molecular_search_settings.isRadical = False
|
|
84
|
+
mass_spectrum.molecular_search_settings.isAdduct = False
|
|
85
|
+
|
|
86
|
+
# mass_spectrum.filter_by_max_resolving_power(15, 2)
|
|
87
|
+
SearchMolecularFormulas(mass_spectrum, first_hit=False).run_worker_mass_spectrum()
|
|
88
|
+
|
|
89
|
+
mass_spectrum.percentile_assigned(report_error=True)
|
|
90
|
+
mass_spectrum.molecular_search_settings.score_method = "prob_score"
|
|
91
|
+
mass_spectrum.molecular_search_settings.output_score_method = "prob_score"
|
|
92
|
+
|
|
93
|
+
# export_calc_isotopologues(mass_spectrum, "15T_Neg_ESI_SRFA_Calc_Isotopologues")
|
|
94
|
+
|
|
95
|
+
mass_spectrum_by_classes = HeteroatomsClassification(mass_spectrum, choose_molecular_formula=True)
|
|
96
|
+
|
|
97
|
+
mass_spectrum_by_classes.plot_ms_assigned_unassigned()
|
|
98
|
+
plt.show()
|
|
99
|
+
mass_spectrum_by_classes.plot_mz_error()
|
|
100
|
+
plt.show()
|
|
101
|
+
mass_spectrum_by_classes.plot_ms_class("O2")
|
|
102
|
+
plt.show()
|
|
103
|
+
# dataframe = mass_spectrum_by_classes.to_dataframe()
|
|
104
|
+
return mass_spectrum
|
|
105
|
+
|
|
106
|
+
# class_plot(dataframe)
|
|
107
|
+
|
|
108
|
+
if __name__ == "__main__":
|
|
109
|
+
|
|
110
|
+
# app = QApplication(sys.argv)
|
|
111
|
+
# file_dialog = QFileDialog()
|
|
112
|
+
# file_dialog.setWindowFlags(Qt.WindowStaysOnTopHint)
|
|
113
|
+
# file_location = file_dialog.getOpenFileName()[0]
|
|
114
|
+
# app.quit()
|
|
115
|
+
|
|
116
|
+
file_location = "tests/tests_data/ftms/Exploris_SRFA_Example.raw"
|
|
117
|
+
# change parameters here
|
|
118
|
+
|
|
119
|
+
mass_spectrum = run_thermo(file_location)
|
|
120
|
+
|
|
121
|
+
print("acquisition_time:", mass_spectrum.acquisition_time )
|
|
122
|
+
ax = mass_spectrum.plot_mz_domain_profile()
|
|
123
|
+
|
|
124
|
+
#for mspeak in mass_spectrum:
|
|
125
|
+
# mspeak.plot(ax=ax)
|
|
126
|
+
#plt.show()
|
|
127
|
+
#plt.savefig("test.png")
|
|
128
|
+
|
|
129
|
+
#mass_spectrum.plot_profile_and_noise_threshold()
|
|
130
|
+
#plt.show()
|
|
131
|
+
#plt.savefig("test.png")
|
|
132
|
+
|
|
133
|
+
mass_spectrum = run_assignment(file_location)
|
|
134
|
+
|
|
135
|
+
mass_spectrum.to_csv(mass_spectrum.sample_name)
|
|
136
|
+
# print("polarity", mass_spectrum.polarity)
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
##### CWD 2021-10-27
|
|
2
|
+
#### (1) import .csv with LC-ICPMS data; (2) for each metal, pick peaks; (3) return dictionary with RT as key, metal as value
|
|
3
|
+
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from typing import Dict, List, Tuple
|
|
6
|
+
import warnings
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
sys.path.append("./")
|
|
10
|
+
warnings.filterwarnings("ignore")
|
|
11
|
+
|
|
12
|
+
import pandas as pd
|
|
13
|
+
import matplotlib.pyplot as plt
|
|
14
|
+
import numpy as np
|
|
15
|
+
|
|
16
|
+
from corems.encapsulation.factory.parameters import LCMSParameters
|
|
17
|
+
from corems.mass_spectra.input import rawFileReader
|
|
18
|
+
from corems.mass_spectra.calc import SignalProcessing as sp
|
|
19
|
+
from corems.molecular_id.search.molecularFormulaSearch import SearchMolecularFormulas
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class TIC_Data:
|
|
23
|
+
'''
|
|
24
|
+
Scans: [int]
|
|
25
|
+
original thermo scan numbers
|
|
26
|
+
Time: [floats]
|
|
27
|
+
list of retention times
|
|
28
|
+
TIC: [floats]
|
|
29
|
+
total ion chromatogram
|
|
30
|
+
Apexes: [int]
|
|
31
|
+
original thermo apex scan number after peak picking
|
|
32
|
+
'''
|
|
33
|
+
|
|
34
|
+
scans : List[int] = field(default_factory=list)
|
|
35
|
+
time : List[float] = field(default_factory=list)
|
|
36
|
+
tic : List[float] = field(default_factory=list)
|
|
37
|
+
apexes : List[int] = field(default_factory=list)
|
|
38
|
+
|
|
39
|
+
@dataclass
|
|
40
|
+
class EIC_Data:
|
|
41
|
+
'''
|
|
42
|
+
Scans: [int]
|
|
43
|
+
original thermo scan numbers
|
|
44
|
+
Time: [floats]
|
|
45
|
+
list of retention times
|
|
46
|
+
EIC: [floats]
|
|
47
|
+
extracted ion chromatogram
|
|
48
|
+
Apexes: [int]
|
|
49
|
+
original thermo apex scan number after peak picking
|
|
50
|
+
|
|
51
|
+
'''
|
|
52
|
+
metal: str
|
|
53
|
+
scans : List[int] = field(default_factory=list)
|
|
54
|
+
time : List[float] = field(default_factory=list)
|
|
55
|
+
eic : List[float] = field(default_factory=list)
|
|
56
|
+
apexes : List[int] = field(default_factory=list)
|
|
57
|
+
|
|
58
|
+
def eic_centroid_detector(max_tic, eic_data:EIC_Data, parameters:LCMSParameters, smooth=True):
|
|
59
|
+
# Do peak picking and store results inside EIC_Data class
|
|
60
|
+
|
|
61
|
+
max_prominence = parameters.lc_ms.peak_max_prominence_percent
|
|
62
|
+
|
|
63
|
+
max_height = parameters.lc_ms.peak_height_max_percent
|
|
64
|
+
|
|
65
|
+
signal_threshold = parameters.lc_ms.eic_signal_threshold
|
|
66
|
+
|
|
67
|
+
min_peak_datapoints = parameters.lc_ms.min_peak_datapoints
|
|
68
|
+
|
|
69
|
+
correct_baseline = parameters.lc_ms.correct_eic_baseline
|
|
70
|
+
|
|
71
|
+
peak_derivative_threshold = parameters.lc_ms.peak_derivative_threshold
|
|
72
|
+
|
|
73
|
+
if smooth:
|
|
74
|
+
|
|
75
|
+
eic_signal = smooth_signal(eic_data.eic, parameters)
|
|
76
|
+
|
|
77
|
+
else:
|
|
78
|
+
|
|
79
|
+
eic_signal = eic_data.eic
|
|
80
|
+
|
|
81
|
+
peak_indexes_generator = sp.peak_picking_first_derivative(eic_data.time, eic_signal, max_height, max_prominence,
|
|
82
|
+
max(eic_signal), min_peak_datapoints,
|
|
83
|
+
peak_derivative_threshold,
|
|
84
|
+
signal_threshold=signal_threshold,
|
|
85
|
+
correct_baseline=correct_baseline,
|
|
86
|
+
check_abundance=True,
|
|
87
|
+
plot_res=False,)
|
|
88
|
+
eic_data.apexes = [i for i in peak_indexes_generator]
|
|
89
|
+
|
|
90
|
+
plt.plot(eic_data.time/60, eic_signal, label=eic_data.metal)
|
|
91
|
+
|
|
92
|
+
for peak_index in eic_data.apexes:
|
|
93
|
+
plt.plot(eic_data.time[peak_index[1]]/60, eic_signal[peak_index[1]], marker='x')
|
|
94
|
+
|
|
95
|
+
plt.xlabel('Retention Time (min)')
|
|
96
|
+
plt.ylabel('Intensity (cps)')
|
|
97
|
+
plt.legend()
|
|
98
|
+
plt.show()
|
|
99
|
+
|
|
100
|
+
def smooth_signal(signal, parameters:LCMSParameters):
|
|
101
|
+
|
|
102
|
+
implemented_smooth_method = parameters.lc_ms.implemented_smooth_method
|
|
103
|
+
|
|
104
|
+
pol_order = parameters.lc_ms.savgol_pol_order
|
|
105
|
+
|
|
106
|
+
smooth_method = parameters.lc_ms.smooth_method
|
|
107
|
+
|
|
108
|
+
window_len = parameters.lc_ms.smooth_window
|
|
109
|
+
|
|
110
|
+
return sp.smooth_signal(signal, window_len, smooth_method, pol_order, implemented_smooth_method)
|
|
111
|
+
|
|
112
|
+
def get_data(icpdata: pd.DataFrame, parameters:LCMSParameters) -> Tuple[TIC_Data, Dict[str, EIC_Data]]:
|
|
113
|
+
|
|
114
|
+
eic_metal_dict = {}
|
|
115
|
+
|
|
116
|
+
tic_data = TIC_Data(time= [], scans= [], tic= [], apexes= [])
|
|
117
|
+
|
|
118
|
+
tic = np.zeros(len(icpdata))
|
|
119
|
+
|
|
120
|
+
scans = icpdata.Number
|
|
121
|
+
|
|
122
|
+
for columns_label in icpdata.columns[1:]:
|
|
123
|
+
|
|
124
|
+
if columns_label[0:4] == 'Time':
|
|
125
|
+
|
|
126
|
+
rts = icpdata[columns_label].to_numpy()
|
|
127
|
+
|
|
128
|
+
metal_label = columns_label.replace('Time ', '')
|
|
129
|
+
|
|
130
|
+
eic_signal = icpdata[metal_label]
|
|
131
|
+
|
|
132
|
+
tic = tic + eic_signal
|
|
133
|
+
|
|
134
|
+
eic_data = EIC_Data(metal= metal_label, time= rts,
|
|
135
|
+
scans= scans, eic= eic_signal, apexes= [])
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
eic_metal_dict[metal_label] = eic_data
|
|
139
|
+
|
|
140
|
+
tic_data.scans = scans
|
|
141
|
+
tic_data.tic = list(tic)
|
|
142
|
+
|
|
143
|
+
#fig, ax = plt.subplots()
|
|
144
|
+
#ax.plot(rts, smooth_signal(tic_data.tic, parameters))
|
|
145
|
+
plt.xlabel('Retention Time')
|
|
146
|
+
plt.ylabel('Intensity (cps)')
|
|
147
|
+
plt.show()
|
|
148
|
+
|
|
149
|
+
return tic_data, eic_metal_dict
|
|
150
|
+
|
|
151
|
+
def get_metal_data(icpfile, parameters:LCMSParameters):
|
|
152
|
+
|
|
153
|
+
icpdata = pd.read_csv(icpfile, sep=',')
|
|
154
|
+
|
|
155
|
+
tic_data, dict_metal_eicdata = get_data(icpdata, parameters)
|
|
156
|
+
|
|
157
|
+
max_tic = max(tic_data.tic)
|
|
158
|
+
|
|
159
|
+
for metal, eic_data in dict_metal_eicdata.items():
|
|
160
|
+
|
|
161
|
+
eic_centroid_detector(max_tic, eic_data, parameters)
|
|
162
|
+
|
|
163
|
+
#print(metal, eic_data.apexes)
|
|
164
|
+
|
|
165
|
+
return dict_metal_eicdata
|
|
166
|
+
|
|
167
|
+
def search_ms1_data(icrfile:str, dict_metal_eicdata: Dict[str, EIC_Data], parameters:LCMSParameters):
|
|
168
|
+
|
|
169
|
+
'''place holder for parsing and search LC FT-MS data'''
|
|
170
|
+
|
|
171
|
+
lcms_obj, parser = run_thermo(icrfile, parameters)
|
|
172
|
+
|
|
173
|
+
tic_data, ax_tic = lcms_obj.get_tic(ms_type='MS !d', peak_detection=True,
|
|
174
|
+
smooth=False, plot=True)
|
|
175
|
+
|
|
176
|
+
plt.show()
|
|
177
|
+
|
|
178
|
+
for metal, eic_data in dict_metal_eicdata.items():
|
|
179
|
+
|
|
180
|
+
print(metal, eic_data.apexes)
|
|
181
|
+
|
|
182
|
+
for peak_indexex in eic_data.apexes:
|
|
183
|
+
|
|
184
|
+
ftms_scans_index = ([find_nearest_scan(eic_data.time[i], tic_data) for i in peak_indexex])
|
|
185
|
+
ftms_scans = [tic_data.scans[i] for i in ftms_scans_index]
|
|
186
|
+
ftms_times = [tic_data.time[i] for i in ftms_scans_index]
|
|
187
|
+
|
|
188
|
+
retention_time = tic_data.time[ftms_scans_index[1]]
|
|
189
|
+
|
|
190
|
+
print(ftms_scans)
|
|
191
|
+
print(ftms_times)
|
|
192
|
+
|
|
193
|
+
parser.chromatogram_settings.scans = (ftms_scans[0], ftms_scans[-1])
|
|
194
|
+
|
|
195
|
+
mass_spec = parser.get_average_mass_spectrum(auto_process=False)
|
|
196
|
+
mass_spec.retention_time = retention_time
|
|
197
|
+
|
|
198
|
+
mass_spec.settings = parameters.mass_spectrum
|
|
199
|
+
mass_spec.molecular_search_settings = parameters.ms1_molecular_search
|
|
200
|
+
mass_spec.mspeaks_settings = parameters.ms_peak
|
|
201
|
+
mass_spec.process_mass_spec()
|
|
202
|
+
|
|
203
|
+
metal_atom = ''.join(i for i in metal if not i.isdigit())
|
|
204
|
+
mass_spec.molecular_search_settings.usedAtoms[metal_atom] = (1,1)
|
|
205
|
+
|
|
206
|
+
ax = mass_spec.plot_profile_and_noise_threshold()
|
|
207
|
+
|
|
208
|
+
SearchMolecularFormulas(mass_spec, first_hit=False).run_worker_mass_spectrum()
|
|
209
|
+
mass_spec.molecular_search_settings.usedAtoms[metal_atom] = (0,0)
|
|
210
|
+
|
|
211
|
+
mass_spec.percentile_assigned(report_error=True)
|
|
212
|
+
print(metal)
|
|
213
|
+
filename = '{}_rt{}_{}'.format(metal, retention_time, mass_spec.sample_name).replace(".", "_")
|
|
214
|
+
print(filename)
|
|
215
|
+
mass_spec.to_csv(filename, write_metadata=False)
|
|
216
|
+
|
|
217
|
+
for peak in mass_spec:
|
|
218
|
+
|
|
219
|
+
for mf in peak:
|
|
220
|
+
is_assigned = True
|
|
221
|
+
|
|
222
|
+
annotation = "Mol. Form = {}\nm\z = {:.4f}\nerror = {:.4f}\nconfidence score = {:.2f}\nisotopologue score = {:.2f}".format(mf.string_formated, peak.mz_exp, mf.mz_error, mf.confidence_score, mf.isotopologue_similarity)
|
|
223
|
+
|
|
224
|
+
ax.annotate(annotation , xy=(peak.mz_exp, peak.abundance),
|
|
225
|
+
xytext=(+3, np.sign(peak.abundance)*-40), textcoords="offset points",
|
|
226
|
+
horizontalalignment="left",
|
|
227
|
+
verticalalignment="bottom" if peak.abundance > 0 else "top")
|
|
228
|
+
plt.show()
|
|
229
|
+
#time_range.append([eic_data.time[i]/60 for i in peak_indexex])
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def run_thermo(file_location, parameters:LCMSParameters) -> Tuple[rawFileReader.DataDependentLCMS, rawFileReader.ImportDataDependentThermoMSFileReader]:
|
|
234
|
+
|
|
235
|
+
#LCMSParameters.lc_ms.smooth_window = 3
|
|
236
|
+
|
|
237
|
+
#LCMSParameters.lc_ms.min_peak_datapoints = 5
|
|
238
|
+
#LCMSParameters.lc_ms.peak_height_min_percent = 1
|
|
239
|
+
#LCMSParameters.lc_ms.peak_derivative_threshold = 1
|
|
240
|
+
|
|
241
|
+
#LCMSParameters.lc_ms.peak_max_prominence_percent = 1
|
|
242
|
+
#LCMSParameters.lc_ms.peak_height_max_percent = 1
|
|
243
|
+
|
|
244
|
+
parser = rawFileReader.ImportDataDependentThermoMSFileReader(file_location)
|
|
245
|
+
parser.parameters = parameters
|
|
246
|
+
|
|
247
|
+
parser.find_nearest_scan()
|
|
248
|
+
|
|
249
|
+
lcms_obj = parser.get_lcms_obj()
|
|
250
|
+
|
|
251
|
+
return lcms_obj, parser
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def find_nearest_scan(rt, ftms_data):
|
|
255
|
+
|
|
256
|
+
lst = np.asarray(ftms_data.time)
|
|
257
|
+
|
|
258
|
+
idx = (np.abs(lst - (rt/60))).argmin()
|
|
259
|
+
|
|
260
|
+
return idx
|
|
261
|
+
|
|
262
|
+
if __name__ == '__main__':
|
|
263
|
+
|
|
264
|
+
#icpfile = "tests/tests_data/icpms/cwd_211018_day7_8_c18_1uMcobalamin_10uL.csv"
|
|
265
|
+
icpfile = 'tests/tests_data/icpms/161220_soils_hypercarb_3_kansas_qH2O.csv'
|
|
266
|
+
icrfile = "tests/tests_data/icpms/rmb_161221_kansas_h2o_2.raw"
|
|
267
|
+
|
|
268
|
+
parameters = LCMSParameters()
|
|
269
|
+
|
|
270
|
+
parameters.lc_ms.smooth_window = 301
|
|
271
|
+
parameters.lc_ms.eic_signal_threshold = 1 #0-1
|
|
272
|
+
parameters.lc_ms.min_peak_datapoints = 5
|
|
273
|
+
parameters.lc_ms.correct_eic_baseline = False
|
|
274
|
+
parameters.lc_ms.peak_max_prominence_percent = 0.1
|
|
275
|
+
parameters.lc_ms.peak_height_max_percent = 1
|
|
276
|
+
|
|
277
|
+
parameters.mass_spectrum.noise_threshold_method = 'log'
|
|
278
|
+
parameters.mass_spectrum.noise_threshold_min_std = 1
|
|
279
|
+
|
|
280
|
+
parameters.ms1_molecular_search.error_method = 'None'
|
|
281
|
+
parameters.ms1_molecular_search.min_ppm_error = -1
|
|
282
|
+
parameters.ms1_molecular_search.max_ppm_error = 1
|
|
283
|
+
|
|
284
|
+
parameters.ms1_molecular_search.usedAtoms['C'] = (10, 100)
|
|
285
|
+
parameters.ms1_molecular_search.usedAtoms['H'] = (4, 200)
|
|
286
|
+
parameters.ms1_molecular_search.usedAtoms['O'] = (1, 30)
|
|
287
|
+
parameters.ms1_molecular_search.usedAtoms['N'] = (1, 12)
|
|
288
|
+
parameters.ms1_molecular_search.usedAtoms['S'] = (0, 0)
|
|
289
|
+
|
|
290
|
+
parameters.ms1_molecular_search.isProtonated = True
|
|
291
|
+
parameters.ms1_molecular_search.isRadical = False
|
|
292
|
+
parameters.ms1_molecular_search.isAdduct = False
|
|
293
|
+
|
|
294
|
+
dict_metal_eicdata = get_metal_data(icpfile, parameters)
|
|
295
|
+
|
|
296
|
+
icr_data = search_ms1_data(icrfile, dict_metal_eicdata, parameters)
|
|
297
|
+
|