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,436 @@
|
|
|
1
|
+
__author__ = "Yuri E. Corilo"
|
|
2
|
+
__date__ = "03/31/2020"
|
|
3
|
+
|
|
4
|
+
from threading import Thread
|
|
5
|
+
from pandas import DataFrame
|
|
6
|
+
from numpy import hstack, inf, isnan, where, array
|
|
7
|
+
from tqdm import tqdm
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MassErrorPrediction(Thread):
|
|
11
|
+
"""Class for mass error prediction.
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
mass_spectrum : list
|
|
16
|
+
List of mass spectrum objects.
|
|
17
|
+
mz_overlay : int, optional
|
|
18
|
+
The mz overlay value for peak simulation. Default is 10.
|
|
19
|
+
rp_increments : int, optional
|
|
20
|
+
The resolving power increments for peak simulation. Default is 10000.
|
|
21
|
+
base_line_target : float, optional
|
|
22
|
+
The target value for the baseline resolution. Default is 0.01.
|
|
23
|
+
max_interation : int, optional
|
|
24
|
+
The maximum number of iterations for peak simulation. Default is 1000.
|
|
25
|
+
interpolation : str, optional
|
|
26
|
+
The interpolation method for missing data. Default is 'linear'.
|
|
27
|
+
|
|
28
|
+
Attributes
|
|
29
|
+
----------
|
|
30
|
+
mass_spectrum_obj : list
|
|
31
|
+
List of mass spectrum objects.
|
|
32
|
+
mz_overlay : int
|
|
33
|
+
The mz overlay value for peak simulation.
|
|
34
|
+
rp_increments : int
|
|
35
|
+
The resolving power increments for peak simulation.
|
|
36
|
+
base_line_target : float
|
|
37
|
+
The target value for the baseline resolution.
|
|
38
|
+
max_interation : int
|
|
39
|
+
The maximum number of iterations for peak simulation.
|
|
40
|
+
df : DataFrame or None
|
|
41
|
+
The calculated error distribution dataframe.
|
|
42
|
+
interpolation : str
|
|
43
|
+
The interpolation method for missing data.
|
|
44
|
+
|
|
45
|
+
Methods
|
|
46
|
+
-------
|
|
47
|
+
* run().
|
|
48
|
+
Runs the mass error prediction calculation.
|
|
49
|
+
* get_results().
|
|
50
|
+
Returns the calculated error distribution dataframe.
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
mass_spectrum,
|
|
57
|
+
mz_overlay=10,
|
|
58
|
+
rp_increments=10000,
|
|
59
|
+
base_line_target: float = 0.01,
|
|
60
|
+
max_interation=1000,
|
|
61
|
+
interpolation="linear",
|
|
62
|
+
):
|
|
63
|
+
Thread.__init__(self)
|
|
64
|
+
|
|
65
|
+
self.mass_spectrum_obj = mass_spectrum
|
|
66
|
+
|
|
67
|
+
self.mz_overlay = mz_overlay
|
|
68
|
+
|
|
69
|
+
self.rp_increments = rp_increments
|
|
70
|
+
|
|
71
|
+
self.base_line_target = base_line_target
|
|
72
|
+
|
|
73
|
+
self.max_interation = max_interation
|
|
74
|
+
|
|
75
|
+
self.df = None
|
|
76
|
+
|
|
77
|
+
self.interpolation = interpolation
|
|
78
|
+
|
|
79
|
+
def run(self):
|
|
80
|
+
"""Runs the mass error prediction calculation."""
|
|
81
|
+
self.df = self.calc_error_dist()
|
|
82
|
+
|
|
83
|
+
def get_results(self):
|
|
84
|
+
"""Returns the calculated error distribution dataframe."""
|
|
85
|
+
|
|
86
|
+
if not self.df:
|
|
87
|
+
self.run()
|
|
88
|
+
|
|
89
|
+
return self.df
|
|
90
|
+
|
|
91
|
+
def calc_error_dist(self):
|
|
92
|
+
"""Calculate the error distribution."""
|
|
93
|
+
verbose = self.mass_spectrum_obj.parameters.mass_spectrum.verbose_processing
|
|
94
|
+
results_list = []
|
|
95
|
+
|
|
96
|
+
indexes_without_results = list(range(len(self.mass_spectrum_obj)))
|
|
97
|
+
# loop trough mass spectrum
|
|
98
|
+
for peak_obj_idx, peak_obj in enumerate(tqdm(self.mass_spectrum_obj), disable=not verbose):
|
|
99
|
+
# access ms peaks triplets ( peak_obj_idx -1, peak_obj_idx, and peak_obj_idx + 1)
|
|
100
|
+
# check lower and upper boundaries to not excesses mass spectrum range
|
|
101
|
+
|
|
102
|
+
if peak_obj_idx != 0 and peak_obj_idx != len(self.mass_spectrum_obj) - 1:
|
|
103
|
+
# current peak_obj initialted in the loop expression
|
|
104
|
+
# geting the peak on the left (previous_peak_obj) and the one in the right position (next_peak_obj)
|
|
105
|
+
next_peak_obj = self.mass_spectrum_obj[peak_obj_idx + 1]
|
|
106
|
+
previous_peak_obj = self.mass_spectrum_obj[peak_obj_idx - 1]
|
|
107
|
+
|
|
108
|
+
# check mz range defined in max_mz variable and check if peaks have same nominal mz
|
|
109
|
+
# keeping same mz for better plotting representation only, remove it for production
|
|
110
|
+
if (
|
|
111
|
+
peak_obj.nominal_mz_exp == next_peak_obj.nominal_mz_exp
|
|
112
|
+
and peak_obj.nominal_mz_exp == previous_peak_obj.nominal_mz_exp
|
|
113
|
+
):
|
|
114
|
+
# simulate peak shape
|
|
115
|
+
sim_mz, sim_abun = peak_obj.gaussian(mz_overlay=self.mz_overlay)
|
|
116
|
+
# update_plot(sim_mz,sim_abun, 0.5)
|
|
117
|
+
|
|
118
|
+
# simulate peak shape
|
|
119
|
+
next_sim_mz, next_sim_abun = next_peak_obj.gaussian(
|
|
120
|
+
mz_overlay=self.mz_overlay
|
|
121
|
+
)
|
|
122
|
+
# update_plot(next_sim_mz, next_sim_abun, 0.5)
|
|
123
|
+
|
|
124
|
+
# simulate peak shape
|
|
125
|
+
previous_sim_mz, previous_sim_abun = previous_peak_obj.gaussian(
|
|
126
|
+
mz_overlay=self.mz_overlay
|
|
127
|
+
)
|
|
128
|
+
# update_plot(previous_sim_mz, previous_sim_abun, 0.5)
|
|
129
|
+
|
|
130
|
+
sim_mz_domain, summed_peaks_abun = self.sum_data(
|
|
131
|
+
(
|
|
132
|
+
(previous_sim_mz, previous_sim_abun),
|
|
133
|
+
(sim_mz, sim_abun),
|
|
134
|
+
(next_sim_mz, next_sim_abun),
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
# update_plot(sim_mz_domain,summed_peaks_abun, 0.5)
|
|
138
|
+
|
|
139
|
+
# sum simulated abundances
|
|
140
|
+
# summed_peaks_abun = (sim_abun + next_sim_abun + previous_sim_abun)
|
|
141
|
+
|
|
142
|
+
# normalize abundances to 0-1
|
|
143
|
+
# summed_peaks_abun = summed_peaks_abun/(max(summed_peaks_abun))
|
|
144
|
+
|
|
145
|
+
# find appexes location (mz) and magnitude
|
|
146
|
+
mz_centroid, abund_centroid = self.find_peak_apex(
|
|
147
|
+
sim_mz_domain, summed_peaks_abun
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
# find valley location (mz_min_valley) and magnitude (abund_min_valley)
|
|
151
|
+
mz_min_valley, abund_min_valley = self.find_peak_valley(
|
|
152
|
+
sim_mz_domain, summed_peaks_abun
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
# clear delta_rp (global implementation) and store choose resolving power increments
|
|
156
|
+
delta_rp = self.rp_increments
|
|
157
|
+
|
|
158
|
+
# used to limited number of iterations
|
|
159
|
+
i = 0
|
|
160
|
+
j = 0
|
|
161
|
+
|
|
162
|
+
# TODO: fit peak shape and decide best fit #gaussian, lorentz and voigt
|
|
163
|
+
# plot_triplets(mz_centroid,abund_centroid, mz_min_valley, abund_min_valley, sim_mz_domain, summed_peaks_abun )
|
|
164
|
+
if len(mz_centroid) == 2:
|
|
165
|
+
while len(mz_centroid) < 3 and i <= self.max_interation:
|
|
166
|
+
previous_sim_mz, previous_sim_abun = (
|
|
167
|
+
previous_peak_obj.gaussian(
|
|
168
|
+
delta_rp=delta_rp, mz_overlay=self.mz_overlay
|
|
169
|
+
)
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
sim_mz, sim_abun = peak_obj.gaussian(
|
|
173
|
+
delta_rp=delta_rp, mz_overlay=self.mz_overlay
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
next_sim_mz, next_sim_abun = next_peak_obj.gaussian(
|
|
177
|
+
delta_rp=delta_rp, mz_overlay=self.mz_overlay
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
sim_mz_domain, summed_peaks_abun = self.sum_data(
|
|
181
|
+
(
|
|
182
|
+
(previous_sim_mz, previous_sim_abun),
|
|
183
|
+
(sim_mz, sim_abun),
|
|
184
|
+
(next_sim_mz, next_sim_abun),
|
|
185
|
+
)
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
# update_plot(sim_mz_domain, summed_peaks_abun, 0.01)
|
|
189
|
+
|
|
190
|
+
mz_centroid, abund_centroid = self.find_peak_apex(
|
|
191
|
+
sim_mz_domain, summed_peaks_abun
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
delta_rp += self.rp_increments
|
|
195
|
+
|
|
196
|
+
i += 1
|
|
197
|
+
|
|
198
|
+
mz_min_valley, abund_min_valley = self.find_peak_valley(
|
|
199
|
+
sim_mz_domain, summed_peaks_abun
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
if len(mz_centroid) == 3 and len(abund_min_valley) == 2:
|
|
203
|
+
# increase all three peak resolving power until both valley magnitude is bellow the defined target
|
|
204
|
+
# calculate peak shapes with the needed resolving power to have a baseline resolution for all peaks
|
|
205
|
+
# calculate mass difference (ppm) between original centroid and the new simulated peak.
|
|
206
|
+
|
|
207
|
+
while (
|
|
208
|
+
abund_min_valley[0] > self.base_line_target
|
|
209
|
+
or abund_min_valley[1] > self.base_line_target
|
|
210
|
+
and j <= self.max_interation
|
|
211
|
+
):
|
|
212
|
+
previous_sim_mz, previous_sim_abun = (
|
|
213
|
+
previous_peak_obj.gaussian(
|
|
214
|
+
delta_rp=delta_rp, mz_overlay=self.mz_overlay
|
|
215
|
+
)
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
sim_mz, sim_abun = peak_obj.gaussian(
|
|
219
|
+
delta_rp=delta_rp, mz_overlay=self.mz_overlay
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
next_sim_mz, next_sim_abun = next_peak_obj.gaussian(
|
|
223
|
+
delta_rp=delta_rp, mz_overlay=self.mz_overlay
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
sim_mz_domain, summed_peaks_abun = self.sum_data(
|
|
227
|
+
(
|
|
228
|
+
(previous_sim_mz, previous_sim_abun),
|
|
229
|
+
(sim_mz, sim_abun),
|
|
230
|
+
(next_sim_mz, next_sim_abun),
|
|
231
|
+
)
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
# update_plot(sim_mz_domain, summed_peaks_abun, 0.001)
|
|
235
|
+
|
|
236
|
+
# summed_peaks_abun = (sim_abun + next_sim_abun + previous_sim_abun)
|
|
237
|
+
|
|
238
|
+
# find appexes location (mz) and magnitude
|
|
239
|
+
mz_centroid, abund_centroid = self.find_peak_apex(
|
|
240
|
+
sim_mz_domain, summed_peaks_abun
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
# find valley location (mz_min_valley) and magnitude (abund_min_valley)
|
|
244
|
+
summed_peaks_abun = summed_peaks_abun / (
|
|
245
|
+
summed_peaks_abun.max()
|
|
246
|
+
)
|
|
247
|
+
mz_min_valley, abund_min_valley = self.find_peak_valley(
|
|
248
|
+
sim_mz_domain, summed_peaks_abun
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
if len(abund_min_valley) != 2:
|
|
252
|
+
break
|
|
253
|
+
|
|
254
|
+
delta_rp += self.rp_increments
|
|
255
|
+
j += 1
|
|
256
|
+
|
|
257
|
+
# plot_triplets(mz_centroid,abund_centroid, mz_min_valley, abund_min_valley, sim_mz_domain, summed_peaks_abun )
|
|
258
|
+
|
|
259
|
+
# plot_triplets(mz_centroid,abund_centroid, mz_min_valley, abund_min_valley, sim_mz_domain, summed_peaks_abun )
|
|
260
|
+
|
|
261
|
+
mass_shift_ppp = self.calc_error(
|
|
262
|
+
mz_centroid[1], peak_obj.mz_exp, 1000000
|
|
263
|
+
)
|
|
264
|
+
# delta_mz = mz_centroid[1] - peak_obj.mz_exp
|
|
265
|
+
height_shift_per = self.calc_error(
|
|
266
|
+
abund_centroid[1], peak_obj.abundance, 100
|
|
267
|
+
)
|
|
268
|
+
# excitation_amplitude = str(mass_spectrum_obj.filename.stem).split("ex")[1].split("pc")[0]
|
|
269
|
+
# ion_time = str(mass_spectrum_obj.filename.stem).split("0pt")[1].split("s")[0]
|
|
270
|
+
peak_obj.predicted_std = mass_shift_ppp
|
|
271
|
+
|
|
272
|
+
results_list.append(
|
|
273
|
+
{
|
|
274
|
+
"ms_index_position": peak_obj_idx,
|
|
275
|
+
"predicted_std": mass_shift_ppp,
|
|
276
|
+
"mz_exp": peak_obj.mz_exp,
|
|
277
|
+
"nominal_mz_exp": peak_obj.nominal_mz_exp,
|
|
278
|
+
"predicted_mz": mz_centroid[1],
|
|
279
|
+
"s2n": peak_obj.signal_to_noise,
|
|
280
|
+
"peak_height": peak_obj.abundance,
|
|
281
|
+
"predicted_peak_height": abund_centroid[1],
|
|
282
|
+
"peak_height_error": height_shift_per,
|
|
283
|
+
"resolving_power": peak_obj.resolving_power,
|
|
284
|
+
# "excitation_amplitude" : excitation_amplitude,
|
|
285
|
+
# "ion_time" : ion_time
|
|
286
|
+
}
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
indexes_without_results.remove(peak_obj_idx)
|
|
290
|
+
# elif len(mz_centroid) == 3 and len(abund_min_valley) != 2:
|
|
291
|
+
|
|
292
|
+
for peak_obj_idx in indexes_without_results:
|
|
293
|
+
results_list.append(
|
|
294
|
+
{
|
|
295
|
+
"ms_index_position": peak_obj_idx,
|
|
296
|
+
"mz_exp": self.mass_spectrum_obj[peak_obj_idx].mz_exp,
|
|
297
|
+
"nominal_mz_exp": self.mass_spectrum_obj[
|
|
298
|
+
peak_obj_idx
|
|
299
|
+
].nominal_mz_exp,
|
|
300
|
+
"s2n": self.mass_spectrum_obj[peak_obj_idx].signal_to_noise,
|
|
301
|
+
"peak_height": self.mass_spectrum_obj[peak_obj_idx].abundance,
|
|
302
|
+
"resolving_power": self.mass_spectrum_obj[
|
|
303
|
+
peak_obj_idx
|
|
304
|
+
].resolving_power,
|
|
305
|
+
# "excitation_amplitude" : excitation_amplitude,
|
|
306
|
+
# "ion_time" : ion_time
|
|
307
|
+
}
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
df = DataFrame(results_list).sort_values("mz_exp")
|
|
311
|
+
|
|
312
|
+
df.interpolate(method="linear", limit_direction="backward", inplace=True)
|
|
313
|
+
df.interpolate(method="linear", limit_direction="forward", inplace=True)
|
|
314
|
+
|
|
315
|
+
# TODO improve interpolation for missing data
|
|
316
|
+
# f1 = interpolate.interp1d(x1, y1, kind='quadratic',fill_value="extrapolate")
|
|
317
|
+
|
|
318
|
+
for peak_obj_idx in indexes_without_results:
|
|
319
|
+
predicted_std = df.loc[peak_obj_idx].predicted_std
|
|
320
|
+
|
|
321
|
+
self.mass_spectrum_obj[peak_obj_idx].predicted_std = predicted_std
|
|
322
|
+
|
|
323
|
+
return df
|
|
324
|
+
|
|
325
|
+
def sum_data(self, tuple_mz_abun_list: tuple):
|
|
326
|
+
"""Sum the abundances of the simulated peaks.
|
|
327
|
+
|
|
328
|
+
Parameters
|
|
329
|
+
------
|
|
330
|
+
tuple_mz_abun_list : tuple
|
|
331
|
+
A tuple containing the mz and abundance lists.
|
|
332
|
+
|
|
333
|
+
Returns
|
|
334
|
+
-------
|
|
335
|
+
tuple
|
|
336
|
+
A tuple containing the summed mz and abundance lists.
|
|
337
|
+
|
|
338
|
+
"""
|
|
339
|
+
all_mz = {}
|
|
340
|
+
|
|
341
|
+
for mz_list, abun_list in tuple_mz_abun_list:
|
|
342
|
+
for index, mz in enumerate(mz_list):
|
|
343
|
+
abundance = abun_list[index]
|
|
344
|
+
|
|
345
|
+
if mz in all_mz:
|
|
346
|
+
all_mz[mz] = all_mz[mz] + abundance
|
|
347
|
+
else:
|
|
348
|
+
all_mz[mz] = abundance
|
|
349
|
+
|
|
350
|
+
mz_all = []
|
|
351
|
+
abun_all = []
|
|
352
|
+
|
|
353
|
+
for mz in sorted(all_mz):
|
|
354
|
+
mz_all.append(mz)
|
|
355
|
+
abun_all.append(all_mz[mz])
|
|
356
|
+
|
|
357
|
+
return array(mz_all), array(abun_all)
|
|
358
|
+
|
|
359
|
+
def calc_error(self, mass_ref, mass_sim, factor):
|
|
360
|
+
"""Calculate the error between two values.
|
|
361
|
+
|
|
362
|
+
Parameters
|
|
363
|
+
----------
|
|
364
|
+
mass_ref : float
|
|
365
|
+
The reference value.
|
|
366
|
+
mass_sim : float
|
|
367
|
+
The simulated value.
|
|
368
|
+
factor : float
|
|
369
|
+
The factor to multiply the error by.
|
|
370
|
+
|
|
371
|
+
Returns
|
|
372
|
+
-------
|
|
373
|
+
float
|
|
374
|
+
The calculated error.
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
"""
|
|
378
|
+
return (mass_sim - mass_ref / mass_ref) * factor
|
|
379
|
+
|
|
380
|
+
def find_peak_apex(self, mz, abund):
|
|
381
|
+
"""Find the peak apex.
|
|
382
|
+
|
|
383
|
+
Parameters
|
|
384
|
+
------
|
|
385
|
+
mz : array
|
|
386
|
+
The mz array.
|
|
387
|
+
abund : array
|
|
388
|
+
The abundance array.
|
|
389
|
+
|
|
390
|
+
Returns
|
|
391
|
+
-------
|
|
392
|
+
tuple
|
|
393
|
+
A tuple containing the peak apex mass and abundance.
|
|
394
|
+
|
|
395
|
+
"""
|
|
396
|
+
dy = abund[1:] - abund[:-1]
|
|
397
|
+
|
|
398
|
+
# replaces nan for infinity'''
|
|
399
|
+
indices_nan = where(isnan(abund))[0]
|
|
400
|
+
|
|
401
|
+
if indices_nan.size:
|
|
402
|
+
abund[indices_nan] = inf
|
|
403
|
+
dy[where(isnan(dy))[0]] = inf
|
|
404
|
+
|
|
405
|
+
indexes = where((hstack((dy, 0)) < 0) & (hstack((0, dy)) > 0))[0]
|
|
406
|
+
|
|
407
|
+
if indexes.size:
|
|
408
|
+
return mz[indexes], abund[indexes]
|
|
409
|
+
|
|
410
|
+
def find_peak_valley(self, mz, abund):
|
|
411
|
+
"""Find the peak valley.
|
|
412
|
+
|
|
413
|
+
Parameters
|
|
414
|
+
------
|
|
415
|
+
mz : array
|
|
416
|
+
The mz array.
|
|
417
|
+
abund : array
|
|
418
|
+
The abundance array.
|
|
419
|
+
|
|
420
|
+
Returns
|
|
421
|
+
-------
|
|
422
|
+
tuple
|
|
423
|
+
A tuple containing the peak valley mz and abundance.
|
|
424
|
+
"""
|
|
425
|
+
dy = abund[1:] - abund[:-1]
|
|
426
|
+
|
|
427
|
+
# replaces nan for infinity
|
|
428
|
+
indices_nan = where(isnan(abund))[0]
|
|
429
|
+
|
|
430
|
+
if indices_nan.size:
|
|
431
|
+
abund[indices_nan] = inf
|
|
432
|
+
dy[where(isnan(dy))[0]] = inf
|
|
433
|
+
|
|
434
|
+
indexes = where((hstack((dy, 0)) > 0) & (hstack((0, dy)) < 0))[0]
|
|
435
|
+
|
|
436
|
+
return mz[indexes], abund[indexes]
|