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,283 @@
|
|
|
1
|
+
##### CWD 2021-09-29
|
|
2
|
+
####Replicate isotope pattern algorithm in python for a single file and peak pair.
|
|
3
|
+
|
|
4
|
+
import warnings
|
|
5
|
+
warnings.filterwarnings("ignore")
|
|
6
|
+
|
|
7
|
+
import sys
|
|
8
|
+
sys.path.append("./")
|
|
9
|
+
|
|
10
|
+
from tqdm import tqdm
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import pandas as pd
|
|
14
|
+
import numpy as np
|
|
15
|
+
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
import matplotlib.pyplot as plt
|
|
19
|
+
# from PySide2.QtWidgets import QFileDialog, QApplication
|
|
20
|
+
# from PySide2.QtCore import Qt
|
|
21
|
+
|
|
22
|
+
from corems.mass_spectra.input import rawFileReader
|
|
23
|
+
from corems.molecular_id.factory.classification import HeteroatomsClassification, Labels
|
|
24
|
+
from corems.molecular_id.search.priorityAssignment import OxygenPriorityAssignment
|
|
25
|
+
from corems.molecular_id.search.molecularFormulaSearch import SearchMolecularFormulas
|
|
26
|
+
from corems.encapsulation.factory.parameters import MSParameters
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
#set file here
|
|
30
|
+
file_location = "tests/tests_data/icpms/rmb_161221_kansas_h2o_2"
|
|
31
|
+
|
|
32
|
+
#Set peak detection threshold method
|
|
33
|
+
MSParameters.mass_spectrum.noise_threshold_method = 'relative_abundance'
|
|
34
|
+
MSParameters.mass_spectrum.noise_threshold_min_relative_abundance = 1
|
|
35
|
+
|
|
36
|
+
MSParameters.mass_spectrum.noise_threshold_method = 'log'
|
|
37
|
+
MSParameters.mass_spectrum.noise_threshold_min_s2n = 10
|
|
38
|
+
|
|
39
|
+
#Parser for thermo RAW files.
|
|
40
|
+
parser = rawFileReader.ImportMassSpectraThermoMSFileReader(file_location)
|
|
41
|
+
|
|
42
|
+
t_ion_chromatogram = parser.get_tic()
|
|
43
|
+
|
|
44
|
+
t_ion_subset=t_ion_chromatogram[(t_ion_chromatogram["Time"]>8) & (t_ion_chromatogram["Time"]<9)]
|
|
45
|
+
|
|
46
|
+
#print(t_ion_chromatogram['Time'])
|
|
47
|
+
#print(parser.start_scan)
|
|
48
|
+
#print(parser.end_scan)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
#Function for obtaining extracted ion chromatogram
|
|
52
|
+
def get_EIC(parser,mass,dmz,scanrange):
|
|
53
|
+
|
|
54
|
+
EIC = np.zeros((len(scanrange),3)) ## scan, time, eic
|
|
55
|
+
EIC[:,0] = scanrange
|
|
56
|
+
for scan in tqdm(scanrange, desc = 'extracting ion chromatogram'):
|
|
57
|
+
|
|
58
|
+
scanStatistics = parser.iRawDataPlus.GetScanStatsForScanNumber(scan)
|
|
59
|
+
EIC[np.where(EIC[:,0] == scan),1] = scanStatistics.StartTime
|
|
60
|
+
|
|
61
|
+
current_dictionary = parser.get_data(scan,1,scan_type="Profile")
|
|
62
|
+
current = np.zeros((len(current_dictionary['m/z']),2))
|
|
63
|
+
current[:,0] = current_dictionary['m/z']
|
|
64
|
+
current[:,1] = current_dictionary['Peak Height']
|
|
65
|
+
subset = current[abs(current[:,0] - mass) < dmz]
|
|
66
|
+
|
|
67
|
+
EIC[np.where(EIC[:,0] == scan),2] =sum(subset[:,1])
|
|
68
|
+
return(EIC)
|
|
69
|
+
|
|
70
|
+
scanrange=range(parser.start_scan,parser.end_scan)
|
|
71
|
+
mass=677
|
|
72
|
+
dmz=1
|
|
73
|
+
|
|
74
|
+
EIC=get_EIC(parser,mass,dmz,scanrange)
|
|
75
|
+
|
|
76
|
+
fig, host = plt.subplots()
|
|
77
|
+
host.plot(EIC[:,1],EIC[:,2])
|
|
78
|
+
host.set_xlabel('Time (min)')
|
|
79
|
+
host.set_ylabel('Intensity (counts)')
|
|
80
|
+
plt.show()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
#Get MS1 scans numbers only.
|
|
86
|
+
first_scan = parser.start_scan
|
|
87
|
+
final_scan =parser.end_scan
|
|
88
|
+
scanrange = range(first_scan, final_scan)
|
|
89
|
+
|
|
90
|
+
MSn = np.zeros((len(scanrange),3)) ## scan, time, n
|
|
91
|
+
MSn[:,0] = scanrange
|
|
92
|
+
for scan in tqdm(range(parser.start_scan, parser.end_scan), desc = 'extracting MS1 scans'):
|
|
93
|
+
|
|
94
|
+
scanStatistics = parser.iRawDataPlus.GetScanStatsForScanNumber(scan)
|
|
95
|
+
MSn[np.where(MSn[:,0] == scan),1] = scanStatistics.StartTime
|
|
96
|
+
MSn[np.where(MSn[:,0] == scan),2] = int(parser.get_scan_header(scan)['Master Scan Number:'])
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
MS1scans=MSn[np.where(MSn[:,2] == 0)]
|
|
100
|
+
#MS1scans={'scan':MS1scans[:,0], 'time':MS1scans[:,1], 'n':MS1scans[:,2]}
|
|
101
|
+
#MSn_dict={'scan':MSn[:,0], 'time':MSn[:,1], 'n':MSn[:,2]}
|
|
102
|
+
#scanrange=MS1scans['scan']
|
|
103
|
+
scanrange=MS1scans[:,0]
|
|
104
|
+
|
|
105
|
+
mass=677
|
|
106
|
+
dmz=1
|
|
107
|
+
|
|
108
|
+
EIC=get_EIC(parser,mass,dmz,scanrange)
|
|
109
|
+
|
|
110
|
+
fig, host = plt.subplots()
|
|
111
|
+
host.plot(EIC[:,1],EIC[:,2])
|
|
112
|
+
host.set_xlabel('Time (min)')
|
|
113
|
+
host.set_ylabel('Intensity (counts)')
|
|
114
|
+
plt.show()
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
#Import LC-ICPMS data and plot it:
|
|
119
|
+
|
|
120
|
+
import csv
|
|
121
|
+
|
|
122
|
+
icpfile = "tests/tests_data/icpms/161220_soils_hypercarb_3_kansas_qH2O.csv"
|
|
123
|
+
|
|
124
|
+
icpdata = np.genfromtxt(icpfile, dtype=float, delimiter=',', names=True)
|
|
125
|
+
|
|
126
|
+
fig, host = plt.subplots()
|
|
127
|
+
host.plot(icpdata['Time_56Fe'],icpdata['56Fe'])
|
|
128
|
+
host.set_xlabel('Time (s)')
|
|
129
|
+
host.set_ylabel('56Fe intensity (counts)')
|
|
130
|
+
plt.show()
|
|
131
|
+
|
|
132
|
+
fig, host = plt.subplots()
|
|
133
|
+
host.plot(icpdata['Time_63Cu'],icpdata['63Cu'])
|
|
134
|
+
host.set_xlabel('Time (s)')
|
|
135
|
+
host.set_ylabel('63Cu intensity (counts)')
|
|
136
|
+
plt.show()
|
|
137
|
+
|
|
138
|
+
fig, host = plt.subplots()
|
|
139
|
+
host.plot(icpdata['Time_59Co'],icpdata['59Co'])
|
|
140
|
+
host.set_xlabel('Time (s)')
|
|
141
|
+
host.set_ylabel('59Co intensity (counts)')
|
|
142
|
+
plt.show()
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
#Pick out a time-slice of the ICPMS data that will be correlated w/ EIC data.
|
|
148
|
+
|
|
149
|
+
timestart=535
|
|
150
|
+
timestop=575
|
|
151
|
+
icpi="59Co"
|
|
152
|
+
icpt="Time_" + icpi
|
|
153
|
+
icpslice = icpdata[np.where((icpdata[icpt] >= timestart) & (icpdata[icpt] <= timestop))]
|
|
154
|
+
|
|
155
|
+
fig, host = plt.subplots()
|
|
156
|
+
host.plot(icpslice[icpt],icpslice[icpi])
|
|
157
|
+
host.set_xlabel('Time (s)')
|
|
158
|
+
host.set_ylabel(icpi+' intensity (counts)')
|
|
159
|
+
plt.show()
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
#Correlate every ESIMS mz detected across the time range with the metal intensity.
|
|
164
|
+
#This section obtains EIC's for every m/z over the time range.
|
|
165
|
+
|
|
166
|
+
MS1scans=MSn[np.where(MSn[:,2] == 0)]
|
|
167
|
+
scans=MS1scans[np.where((MS1scans[:,1] >= timestart/60) & (MS1scans[:,1] <= timestop/60))][:,0].tolist()
|
|
168
|
+
parser.chromatogram_settings.scans = scans
|
|
169
|
+
|
|
170
|
+
AverageMS = parser.get_average_mass_spectrum()
|
|
171
|
+
AverageMS.plot_mz_domain_profile()
|
|
172
|
+
|
|
173
|
+
plt.show()
|
|
174
|
+
|
|
175
|
+
print(AverageMS.mz_exp.size)
|
|
176
|
+
|
|
177
|
+
scanrange=scans
|
|
178
|
+
|
|
179
|
+
EICdict = {}
|
|
180
|
+
|
|
181
|
+
for mz in AverageMS.mz_exp[1:20]:
|
|
182
|
+
#EIC = pd.DataFrame(index=scanrange, columns=['Time', 'EIC'])
|
|
183
|
+
EIC = np.zeros((len(scanrange),3)) ## scan, time, eic
|
|
184
|
+
EIC[:,0] = scanrange
|
|
185
|
+
mass=mz
|
|
186
|
+
dmz=0.002
|
|
187
|
+
print('m/z: ',mz)
|
|
188
|
+
EIC=get_EIC(parser,mass,dmz,scanrange)
|
|
189
|
+
EICdict[mz]=EIC
|
|
190
|
+
|
|
191
|
+
# sums all the mass spectra
|
|
192
|
+
mass_spectrum = parser.get_average_mass_spectrum()
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
mass_spectrum.plot_mz_domain_profile()
|
|
196
|
+
plt.show()
|
|
197
|
+
|
|
198
|
+
mass_spectrum.plot_profile_and_noise_threshold()
|
|
199
|
+
plt.show()
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
mass_spectrum.molecular_search_settings.error_method = 'None'
|
|
203
|
+
mass_spectrum.molecular_search_settings.min_ppm_error = -5
|
|
204
|
+
mass_spectrum.molecular_search_settings.max_ppm_error = 5
|
|
205
|
+
|
|
206
|
+
mass_spectrum.molecular_search_settings.url_database = None
|
|
207
|
+
mass_spectrum.molecular_search_settings.min_dbe = 0
|
|
208
|
+
mass_spectrum.molecular_search_settings.max_dbe = 50
|
|
209
|
+
|
|
210
|
+
mass_spectrum.molecular_search_settings.usedAtoms['C'] = (1, 100)
|
|
211
|
+
mass_spectrum.molecular_search_settings.usedAtoms['H'] = (4, 200)
|
|
212
|
+
mass_spectrum.molecular_search_settings.usedAtoms['O'] = (1, 30)
|
|
213
|
+
mass_spectrum.molecular_search_settings.usedAtoms['N'] = (0, 0)
|
|
214
|
+
mass_spectrum.molecular_search_settings.usedAtoms['S'] = (0, 0)
|
|
215
|
+
mass_spectrum.molecular_search_settings.usedAtoms['Cl'] = (0, 0)
|
|
216
|
+
mass_spectrum.molecular_search_settings.usedAtoms['Br'] = (0, 0)
|
|
217
|
+
mass_spectrum.molecular_search_settings.usedAtoms['P'] = (0, 0)
|
|
218
|
+
mass_spectrum.molecular_search_settings.usedAtoms['Na'] = (0, 0)
|
|
219
|
+
|
|
220
|
+
mass_spectrum.molecular_search_settings.isProtonated = True
|
|
221
|
+
mass_spectrum.molecular_search_settings.isRadical = False
|
|
222
|
+
mass_spectrum.molecular_search_settings.isAdduct = False
|
|
223
|
+
|
|
224
|
+
# mass_spectrum.filter_by_max_resolving_power(15, 2)
|
|
225
|
+
SearchMolecularFormulas(mass_spectrum, first_hit=False).run_worker_mass_spectrum()
|
|
226
|
+
|
|
227
|
+
mass_spectrum.percentile_assigned(report_error=True)
|
|
228
|
+
mass_spectrum.molecular_search_settings.score_method = "prob_score"
|
|
229
|
+
mass_spectrum.molecular_search_settings.output_score_method = "prob_score"
|
|
230
|
+
|
|
231
|
+
# export_calc_isotopologues(mass_spectrum, "15T_Neg_ESI_SRFA_Calc_Isotopologues")
|
|
232
|
+
|
|
233
|
+
mass_spectrum_by_classes = HeteroatomsClassification(mass_spectrum, choose_molecular_formula=True)
|
|
234
|
+
|
|
235
|
+
mass_spectrum_by_classes.plot_ms_assigned_unassigned()
|
|
236
|
+
plt.show()
|
|
237
|
+
mass_spectrum_by_classes.plot_mz_error()
|
|
238
|
+
plt.show()
|
|
239
|
+
mass_spectrum_by_classes.plot_ms_class("O2")
|
|
240
|
+
plt.show()
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
mass_spectrum.molecular_search_settings.error_method = 'None'
|
|
246
|
+
mass_spectrum.molecular_search_settings.min_ppm_error = -2
|
|
247
|
+
mass_spectrum.molecular_search_settings.max_ppm_error = 4
|
|
248
|
+
|
|
249
|
+
mass_spectrum.molecular_search_settings.url_database = None
|
|
250
|
+
mass_spectrum.molecular_search_settings.min_dbe = 0
|
|
251
|
+
mass_spectrum.molecular_search_settings.max_dbe = 50
|
|
252
|
+
|
|
253
|
+
mass_spectrum.molecular_search_settings.usedAtoms['C'] = (1, 100)
|
|
254
|
+
mass_spectrum.molecular_search_settings.usedAtoms['H'] = (4, 200)
|
|
255
|
+
mass_spectrum.molecular_search_settings.usedAtoms['O'] = (1, 30)
|
|
256
|
+
mass_spectrum.molecular_search_settings.usedAtoms['N'] = (0, 6)
|
|
257
|
+
mass_spectrum.molecular_search_settings.usedAtoms['S'] = (0, 0)
|
|
258
|
+
mass_spectrum.molecular_search_settings.usedAtoms['Cl'] = (0, 0)
|
|
259
|
+
mass_spectrum.molecular_search_settings.usedAtoms['Br'] = (0, 0)
|
|
260
|
+
mass_spectrum.molecular_search_settings.usedAtoms['P'] = (0, 0)
|
|
261
|
+
mass_spectrum.molecular_search_settings.usedAtoms['Na'] = (0, 0)
|
|
262
|
+
|
|
263
|
+
mass_spectrum.molecular_search_settings.isProtonated = True
|
|
264
|
+
mass_spectrum.molecular_search_settings.isRadical = False
|
|
265
|
+
mass_spectrum.molecular_search_settings.isAdduct = False
|
|
266
|
+
|
|
267
|
+
# mass_spectrum.filter_by_max_resolving_power(15, 2)
|
|
268
|
+
SearchMolecularFormulas(mass_spectrum, first_hit=False).run_worker_mass_spectrum()
|
|
269
|
+
|
|
270
|
+
mass_spectrum.percentile_assigned(report_error=True)
|
|
271
|
+
mass_spectrum.molecular_search_settings.score_method = "prob_score"
|
|
272
|
+
mass_spectrum.molecular_search_settings.output_score_method = "prob_score"
|
|
273
|
+
|
|
274
|
+
# export_calc_isotopologues(mass_spectrum, "15T_Neg_ESI_SRFA_Calc_Isotopologues")
|
|
275
|
+
|
|
276
|
+
mass_spectrum_by_classes = HeteroatomsClassification(mass_spectrum, choose_molecular_formula=True)
|
|
277
|
+
|
|
278
|
+
mass_spectrum_by_classes.plot_ms_assigned_unassigned()
|
|
279
|
+
plt.show()
|
|
280
|
+
mass_spectrum_by_classes.plot_mz_error()
|
|
281
|
+
plt.show()
|
|
282
|
+
mass_spectrum_by_classes.plot_ms_class("O2")
|
|
283
|
+
plt.show()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# This script demonstrates how to set global parameters and instantiate a mass spectrum object using them
|
|
2
|
+
|
|
3
|
+
from corems.encapsulation.factory.parameters import MSParameters
|
|
4
|
+
from corems.transient.input.brukerSolarix import ReadBrukerSolarix
|
|
5
|
+
|
|
6
|
+
# Set global parameters and instantiate a mass spectrum object using them
|
|
7
|
+
## Note that the default noise_threshold_method is 'log'
|
|
8
|
+
MSParameters.mass_spectrum.noise_threshold_method = 'relative_abundance'
|
|
9
|
+
|
|
10
|
+
parser = ReadBrukerSolarix("tests/tests_data/ftms/ESI_NEG_SRFA.d")
|
|
11
|
+
bruker_transient = parser.get_transient()
|
|
12
|
+
mass_spectrum_i = bruker_transient.get_mass_spectrum(plot_result=False, auto_process=False)
|
|
13
|
+
print(mass_spectrum_i.parameters.mass_spectrum.noise_threshold_method) # relative_abundance
|
|
14
|
+
|
|
15
|
+
# Create a new MSParameters instance with default parameters and assign it to the mass spectrum object
|
|
16
|
+
new_msparams = MSParameters(use_defaults=True)
|
|
17
|
+
mass_spectrum_i.parameters = new_msparams
|
|
18
|
+
print(mass_spectrum_i.parameters.mass_spectrum.noise_threshold_method) # log
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
import pandas as pd
|
|
5
|
+
|
|
6
|
+
def merge_files(file_paths: list, output_filename:str, variable: str = 'Peak Height'):
|
|
7
|
+
|
|
8
|
+
master_data_dict = []
|
|
9
|
+
list_filenames = []
|
|
10
|
+
for filepath in file_paths:
|
|
11
|
+
|
|
12
|
+
filepath = Path(filepath)
|
|
13
|
+
|
|
14
|
+
with filepath.open('r') as f:
|
|
15
|
+
|
|
16
|
+
#data = json.loads(json.load(f))
|
|
17
|
+
|
|
18
|
+
df = pd.read_csv(f)
|
|
19
|
+
idx = df.groupby(['Molecular Formula'])['Confidence Score'].transform(max) == df['Confidence Score']
|
|
20
|
+
|
|
21
|
+
df = df[idx]
|
|
22
|
+
df.fillna(0, inplace=True)
|
|
23
|
+
|
|
24
|
+
name_column = "{} ({})".format(variable, filepath.stem)
|
|
25
|
+
|
|
26
|
+
df.rename({variable: name_column}, inplace=True, axis=1)
|
|
27
|
+
|
|
28
|
+
list_filenames.append(name_column)
|
|
29
|
+
master_data_dict.extend(df.to_dict('records'))
|
|
30
|
+
|
|
31
|
+
formula_dict = {}
|
|
32
|
+
for record in master_data_dict:
|
|
33
|
+
molecular_formula = record.get('Molecular Formula')
|
|
34
|
+
|
|
35
|
+
if molecular_formula in formula_dict.keys():
|
|
36
|
+
formula_dict[molecular_formula].append(record)
|
|
37
|
+
else:
|
|
38
|
+
formula_dict[molecular_formula] = [record]
|
|
39
|
+
|
|
40
|
+
def dict_mean(dict_list, average_keys):
|
|
41
|
+
mean_dict = {}
|
|
42
|
+
|
|
43
|
+
for key in average_keys:
|
|
44
|
+
|
|
45
|
+
mean_dict[key] = sum(d[key] for d in dict_list) / len(dict_list)
|
|
46
|
+
|
|
47
|
+
return mean_dict
|
|
48
|
+
|
|
49
|
+
average_records = []
|
|
50
|
+
|
|
51
|
+
average_keys = ['m/z', 'Calibrated m/z', 'Calculated m/z', 'Peak Area', 'Resolving Power', 'S/N', 'm/z Error (ppm)', 'm/z Error Score',
|
|
52
|
+
'Isotopologue Similarity', 'Mono Isotopic Index', 'Confidence Score']
|
|
53
|
+
average_keys.extend(list_filenames)
|
|
54
|
+
|
|
55
|
+
for formula, records in formula_dict.items():
|
|
56
|
+
|
|
57
|
+
#mean_dict = dict_mean(records, average_keys)
|
|
58
|
+
mean_dict = {}
|
|
59
|
+
for record in records:
|
|
60
|
+
#get the selected variable
|
|
61
|
+
for filename in list_filenames:
|
|
62
|
+
if filename in record.keys():
|
|
63
|
+
mean_dict[filename] = record[filename]
|
|
64
|
+
|
|
65
|
+
for record in records:
|
|
66
|
+
#than get the rest of the data
|
|
67
|
+
for key in record.keys():
|
|
68
|
+
if key not in average_keys:
|
|
69
|
+
mean_dict[key] = record[key]
|
|
70
|
+
|
|
71
|
+
average_records.append(mean_dict)
|
|
72
|
+
master_df = pd.DataFrame(average_records)
|
|
73
|
+
|
|
74
|
+
master_df.set_index('Molecular Formula', inplace=True)
|
|
75
|
+
print(master_df)
|
|
76
|
+
|
|
77
|
+
master_df.to_csv('{}.csv'.format(output_filename))
|
|
78
|
+
#grouped = master_df.groupby(["Molecular Formula", "Sample Name", "Peak Height"])
|
|
79
|
+
|
|
80
|
+
if __name__ == '__main__':
|
|
81
|
+
|
|
82
|
+
file_paths = ['tests/tests_data/ftms/Auto_SRFA_QC.csv', 'tests/tests_data/ftms/Auto_SRFA_QC II.csv']
|
|
83
|
+
output_path = 'test_aggregation'
|
|
84
|
+
merge_files(file_paths, output_path)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import pprint, sys
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
sys.path.append("./")
|
|
6
|
+
from corems.encapsulation.factory.parameters import MSParameters
|
|
7
|
+
from corems.encapsulation.input import parameter_from_json
|
|
8
|
+
from corems.mass_spectrum.input.numpyArray import ms_from_array_centroid
|
|
9
|
+
from corems.molecular_id.search.molecularFormulaSearch import SearchMolecularFormulas
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def run_molecular_formula_search(mz, parameters_filepath=None):
|
|
13
|
+
|
|
14
|
+
mz = [mz]
|
|
15
|
+
abundance = [1]
|
|
16
|
+
rp, s2n = [[1],[1]]
|
|
17
|
+
|
|
18
|
+
MSParameters.mass_spectrum.noise_threshold_method = 'relative_abundance'
|
|
19
|
+
MSParameters.mass_spectrum.noise_threshold_absolute_abundance = 0
|
|
20
|
+
|
|
21
|
+
MSParameters.molecular_search.url_database = ''
|
|
22
|
+
MSParameters.molecular_search.error_method = 'None'
|
|
23
|
+
MSParameters.molecular_search.min_ppm_error = -10
|
|
24
|
+
MSParameters.molecular_search.max_ppm_error = 10
|
|
25
|
+
MSParameters.molecular_search.mz_error_range = 1
|
|
26
|
+
MSParameters.molecular_search.isProtonated = True
|
|
27
|
+
MSParameters.molecular_search.isRadical= False
|
|
28
|
+
MSParameters.molecular_search.isAdduct= False
|
|
29
|
+
|
|
30
|
+
usedatoms = {'C': (1,100) , 'H': (4,200), 'O': (0,10), 'N': (0,1), 'P': (0,1)}
|
|
31
|
+
MSParameters.molecular_search.usedAtoms = usedatoms
|
|
32
|
+
MSParameters.molecular_search.usedAtoms = usedatoms
|
|
33
|
+
mass_spectrum_obj = ms_from_array_centroid(mz, abundance, rp, s2n, 'single mf search', polarity=1, auto_process=True)
|
|
34
|
+
|
|
35
|
+
if parameters_filepath:
|
|
36
|
+
|
|
37
|
+
parameter_from_json.load_and_set_parameters_ms(mass_spectrum_obj, parameters_path=parameters_filepath)
|
|
38
|
+
|
|
39
|
+
mass_spectrum_obj.settings.noise_threshold_method = 'relative threshold'
|
|
40
|
+
mass_spectrum_obj.molecular_search_settings.use_min_peaks_filter = False
|
|
41
|
+
mass_spectrum_obj.molecular_search_settings.use_min_peaks_filter = 10
|
|
42
|
+
mass_spectrum_obj.molecular_search_settings.use_isotopologue_filter = False
|
|
43
|
+
|
|
44
|
+
print('Searching for molecular formulas within %.3f and %.3f ppm' % (mass_spectrum_obj.molecular_search_settings.min_ppm_error, mass_spectrum_obj.molecular_search_settings.max_ppm_error))
|
|
45
|
+
|
|
46
|
+
SearchMolecularFormulas(mass_spectrum_obj, find_isotopologues=True).run_worker_ms_peaks([mass_spectrum_obj[0]])
|
|
47
|
+
|
|
48
|
+
ms_peak = mass_spectrum_obj[0]
|
|
49
|
+
|
|
50
|
+
if ms_peak:
|
|
51
|
+
|
|
52
|
+
header = ['Molecular Formula', 'Calculated m/z', 'Mass Error', 'DBE', 'Ion Type']
|
|
53
|
+
|
|
54
|
+
results = []
|
|
55
|
+
|
|
56
|
+
for formula in ms_peak:
|
|
57
|
+
|
|
58
|
+
results.append([formula.string, formula.mz_calc, formula.mz_error, formula.dbe, formula.ion_type])
|
|
59
|
+
|
|
60
|
+
pprint.pprint(results)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
else:
|
|
64
|
+
|
|
65
|
+
print("Could not find a possible molecular formula match for the m/z %.5f" % mz[0])
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
|
|
69
|
+
run_molecular_formula_search(760.58156938877)
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Test script to validate all example notebooks can execute without errors.
|
|
4
|
+
"""
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import argparse
|
|
9
|
+
|
|
10
|
+
# Patterns in stderr that indicate an external service is unavailable.
|
|
11
|
+
# Failures matching these patterns are treated as warnings (skipped) rather
|
|
12
|
+
# than hard failures so that transient infrastructure outages do not break CI.
|
|
13
|
+
EXTERNAL_SERVICE_ERROR_PATTERNS = [
|
|
14
|
+
"HTTPError",
|
|
15
|
+
"ConnectionError",
|
|
16
|
+
"requests.exceptions",
|
|
17
|
+
"503 Server Error",
|
|
18
|
+
"502 Bad Gateway",
|
|
19
|
+
"504 Gateway",
|
|
20
|
+
"Service Temporarily Unavailable",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _is_external_service_failure(stderr: str) -> bool:
|
|
25
|
+
"""Return True if stderr indicates an unavailable external service."""
|
|
26
|
+
return any(pattern in stderr for pattern in EXTERNAL_SERVICE_ERROR_PATTERNS)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Return values: True = pass, False = fail, None = skipped (external service)
|
|
30
|
+
def test_notebook(notebook_path):
|
|
31
|
+
"""Test a single notebook by converting it."""
|
|
32
|
+
print(f"\n{'='*60}")
|
|
33
|
+
print(f"Testing: {notebook_path.name}")
|
|
34
|
+
print(f"{'='*60}")
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
subprocess.run(
|
|
38
|
+
[
|
|
39
|
+
sys.executable,
|
|
40
|
+
"-m",
|
|
41
|
+
"nbconvert",
|
|
42
|
+
"--to",
|
|
43
|
+
"notebook",
|
|
44
|
+
"--execute",
|
|
45
|
+
"--ExecutePreprocessor.timeout=300",
|
|
46
|
+
"--output",
|
|
47
|
+
f"/tmp/{notebook_path.stem}_test.ipynb",
|
|
48
|
+
str(notebook_path),
|
|
49
|
+
],
|
|
50
|
+
capture_output=True,
|
|
51
|
+
text=True,
|
|
52
|
+
check=True,
|
|
53
|
+
)
|
|
54
|
+
print(f"✓ {notebook_path.name} passed")
|
|
55
|
+
return True
|
|
56
|
+
except subprocess.CalledProcessError as e:
|
|
57
|
+
if _is_external_service_failure(e.stderr):
|
|
58
|
+
print(f"⚠ {notebook_path.name} skipped (external service unavailable)")
|
|
59
|
+
print(f"STDERR:\n{e.stderr[-2000:]}")
|
|
60
|
+
return None
|
|
61
|
+
print(f"✗ {notebook_path.name} failed")
|
|
62
|
+
print(f"STDOUT:\n{e.stdout}")
|
|
63
|
+
print(f"STDERR:\n{e.stderr}")
|
|
64
|
+
return False
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def discover_notebooks(notebooks_dir):
|
|
68
|
+
"""Discover all notebooks in the notebooks directory (non-recursive)."""
|
|
69
|
+
all_notebooks = []
|
|
70
|
+
for notebook_path in sorted(notebooks_dir.glob("*.ipynb")):
|
|
71
|
+
# Exclude checkpoint files
|
|
72
|
+
if ".ipynb_checkpoints" not in str(notebook_path):
|
|
73
|
+
all_notebooks.append(notebook_path)
|
|
74
|
+
return all_notebooks
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def main():
|
|
78
|
+
"""Run tests on all notebooks or a selected notebook."""
|
|
79
|
+
parser = argparse.ArgumentParser(description="Execute example notebooks with nbconvert")
|
|
80
|
+
parser.add_argument(
|
|
81
|
+
"--notebook",
|
|
82
|
+
"-n",
|
|
83
|
+
help="Notebook filename or path to run (e.g., LCMS_Tutorial.ipynb)",
|
|
84
|
+
)
|
|
85
|
+
args = parser.parse_args()
|
|
86
|
+
|
|
87
|
+
notebooks_dir = Path(__file__).parent / "notebooks"
|
|
88
|
+
|
|
89
|
+
if not notebooks_dir.exists():
|
|
90
|
+
print(f"Error: notebooks directory not found at {notebooks_dir}")
|
|
91
|
+
sys.exit(1)
|
|
92
|
+
|
|
93
|
+
if args.notebook:
|
|
94
|
+
notebook_arg = Path(args.notebook)
|
|
95
|
+
candidate = notebook_arg if notebook_arg.is_absolute() else notebooks_dir / notebook_arg
|
|
96
|
+
candidate = candidate.resolve()
|
|
97
|
+
|
|
98
|
+
if not candidate.exists():
|
|
99
|
+
print(f"Error: notebook not found: {args.notebook}")
|
|
100
|
+
sys.exit(1)
|
|
101
|
+
notebooks = [candidate]
|
|
102
|
+
else:
|
|
103
|
+
# Discover all notebooks automatically
|
|
104
|
+
notebooks = discover_notebooks(notebooks_dir)
|
|
105
|
+
|
|
106
|
+
if not notebooks:
|
|
107
|
+
print("No notebooks found to test")
|
|
108
|
+
sys.exit(1)
|
|
109
|
+
|
|
110
|
+
print(f"Found {len(notebooks)} notebook(s) to test")
|
|
111
|
+
|
|
112
|
+
results = {}
|
|
113
|
+
for notebook_path in notebooks:
|
|
114
|
+
results[notebook_path.name] = test_notebook(notebook_path)
|
|
115
|
+
|
|
116
|
+
print(f"\n{'='*60}")
|
|
117
|
+
print("SUMMARY")
|
|
118
|
+
print(f"{'='*60}")
|
|
119
|
+
|
|
120
|
+
passed = sum(1 for v in results.values() if v is True)
|
|
121
|
+
skipped = sum(1 for v in results.values() if v is None)
|
|
122
|
+
failed = sum(1 for v in results.values() if v is False)
|
|
123
|
+
total = len(results)
|
|
124
|
+
|
|
125
|
+
for notebook, result in results.items():
|
|
126
|
+
if result is True:
|
|
127
|
+
status = "✓ PASS"
|
|
128
|
+
elif result is None:
|
|
129
|
+
status = "⚠ SKIP"
|
|
130
|
+
else:
|
|
131
|
+
status = "✗ FAIL"
|
|
132
|
+
print(f"{status}: {notebook}")
|
|
133
|
+
|
|
134
|
+
print(f"\n{passed}/{total} notebooks passed, {skipped} skipped (external service), {failed} failed")
|
|
135
|
+
|
|
136
|
+
if failed > 0:
|
|
137
|
+
sys.exit(1)
|
|
138
|
+
|
|
139
|
+
if skipped > 0:
|
|
140
|
+
print("\nSome notebooks were skipped due to unavailable external services.")
|
|
141
|
+
else:
|
|
142
|
+
print("\nAll tests passed!")
|
|
143
|
+
|
|
144
|
+
if __name__ == "__main__":
|
|
145
|
+
main()
|
|
Binary file
|