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,402 @@
|
|
|
1
|
+
__author__ = "Yuri E. Corilo"
|
|
2
|
+
__date__ = "Jun 12, 2019"
|
|
3
|
+
|
|
4
|
+
import warnings
|
|
5
|
+
|
|
6
|
+
import pandas as pd
|
|
7
|
+
|
|
8
|
+
from corems.encapsulation.constant import Atoms, Labels
|
|
9
|
+
from corems.mass_spectrum.factory.MassSpectrumClasses import (
|
|
10
|
+
MassSpecCentroid,
|
|
11
|
+
MassSpecProfile,
|
|
12
|
+
)
|
|
13
|
+
from corems.mass_spectrum.input.baseClass import MassListBaseClass
|
|
14
|
+
from corems.molecular_formula.factory.MolecularFormulaFactory import MolecularFormula
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ReadCoremsMasslist(MassListBaseClass):
|
|
18
|
+
"""
|
|
19
|
+
The ReadCoremsMasslist object reads processed mass list data types
|
|
20
|
+
and returns the mass spectrum obj with the molecular formula obj
|
|
21
|
+
|
|
22
|
+
**Only available for centroid mass spectrum type:** it will ignore the parameter **isCentroid**
|
|
23
|
+
Please see MassListBaseClass for more details
|
|
24
|
+
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def get_mass_spectrum(
|
|
28
|
+
self, loadSettings: bool = True, auto_process: bool = True
|
|
29
|
+
) -> MassSpecCentroid:
|
|
30
|
+
"""
|
|
31
|
+
Get the mass spectrum object from the processed mass list data.
|
|
32
|
+
|
|
33
|
+
Parameters
|
|
34
|
+
----------
|
|
35
|
+
loadSettings : bool, optional
|
|
36
|
+
Whether to load the settings for the mass spectrum. Default is True.
|
|
37
|
+
auto_process : bool, optional
|
|
38
|
+
Whether to automatically process the mass spectrum on instantiation.
|
|
39
|
+
When False, molecular formulas are not attached; call
|
|
40
|
+
``process_mass_spec`` and then ``add_molecular_formula`` on the
|
|
41
|
+
returned object. Default is True.
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
MassSpecCentroid
|
|
46
|
+
The mass spectrum object.
|
|
47
|
+
|
|
48
|
+
Raises
|
|
49
|
+
------
|
|
50
|
+
ValueError
|
|
51
|
+
If the input file is not a valid CoreMS file.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
dataframe = self.get_dataframe()
|
|
55
|
+
|
|
56
|
+
if not set(
|
|
57
|
+
["H/C", "O/C", "Heteroatom Class", "Ion Type", "Is Isotopologue"]
|
|
58
|
+
).issubset(dataframe.columns):
|
|
59
|
+
raise ValueError(
|
|
60
|
+
"%s it is not a valid CoreMS file" % str(self.file_location)
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
self.check_columns(dataframe.columns)
|
|
64
|
+
|
|
65
|
+
dataframe.rename(columns=self.parameters.header_translate, inplace=True)
|
|
66
|
+
|
|
67
|
+
polarity = dataframe["Ion Charge"].values[0]
|
|
68
|
+
|
|
69
|
+
output_parameters = self.get_output_parameters(polarity)
|
|
70
|
+
|
|
71
|
+
mass_spec_obj = MassSpecCentroid(
|
|
72
|
+
dataframe.to_dict(orient="list"),
|
|
73
|
+
output_parameters,
|
|
74
|
+
auto_process=auto_process,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
if loadSettings is True:
|
|
78
|
+
self.load_settings(mass_spec_obj, output_parameters)
|
|
79
|
+
|
|
80
|
+
if auto_process:
|
|
81
|
+
self.add_molecular_formula(mass_spec_obj, dataframe)
|
|
82
|
+
|
|
83
|
+
return mass_spec_obj
|
|
84
|
+
|
|
85
|
+
def add_molecular_formula(self, mass_spec_obj, dataframe):
|
|
86
|
+
"""
|
|
87
|
+
Add molecular formula information to the mass spectrum object.
|
|
88
|
+
|
|
89
|
+
Parameters
|
|
90
|
+
----------
|
|
91
|
+
mass_spec_obj : MassSpecCentroid
|
|
92
|
+
The mass spectrum object to add the molecular formula to.
|
|
93
|
+
dataframe : pandas.DataFrame
|
|
94
|
+
The processed mass list data.
|
|
95
|
+
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
# check if is coreMS file
|
|
99
|
+
if "Is Isotopologue" in dataframe:
|
|
100
|
+
# Reindex dataframe to row index to avoid issues with duplicated indexes (e.g. when multiple formula map to single mz_exp)
|
|
101
|
+
dataframe = dataframe.reset_index(drop=True)
|
|
102
|
+
|
|
103
|
+
mz_exp_df = dataframe[Labels.mz].astype(float)
|
|
104
|
+
formula_df = dataframe[
|
|
105
|
+
dataframe.columns.intersection(Atoms.atoms_order)
|
|
106
|
+
].copy()
|
|
107
|
+
# Convert to numeric first (pandas 3.x may infer str dtype for
|
|
108
|
+
# HDF5-sourced atom count columns); coerce handles b"nan" bytes too
|
|
109
|
+
formula_df = formula_df.apply(pd.to_numeric, errors="coerce").fillna(0)
|
|
110
|
+
|
|
111
|
+
ion_type_df = dataframe["Ion Type"]
|
|
112
|
+
ion_charge_df = dataframe["Ion Charge"]
|
|
113
|
+
is_isotopologue_df = dataframe["Is Isotopologue"]
|
|
114
|
+
if "Adduct" in dataframe:
|
|
115
|
+
adduct_df = dataframe["Adduct"]
|
|
116
|
+
else:
|
|
117
|
+
adduct_df = None
|
|
118
|
+
|
|
119
|
+
mass_spec_mz_exp_list = mass_spec_obj.mz_exp
|
|
120
|
+
|
|
121
|
+
for df_index, mz_exp in enumerate(mz_exp_df):
|
|
122
|
+
bad_mf = False
|
|
123
|
+
counts = 0
|
|
124
|
+
|
|
125
|
+
ms_peak_index = list(mass_spec_mz_exp_list).index(float(mz_exp))
|
|
126
|
+
|
|
127
|
+
if "Is Isotopologue" in dataframe:
|
|
128
|
+
atoms = list(formula_df.columns.astype(str))
|
|
129
|
+
counts = list(formula_df.iloc[df_index].astype(int))
|
|
130
|
+
|
|
131
|
+
formula_dict = dict(zip(atoms, counts))
|
|
132
|
+
|
|
133
|
+
# Drop any atoms with 0 counts
|
|
134
|
+
formula_dict = {
|
|
135
|
+
atom: formula_dict[atom]
|
|
136
|
+
for atom in formula_dict
|
|
137
|
+
if formula_dict[atom] > 0
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if sum(counts) > 0:
|
|
141
|
+
ion_type = str(Labels.ion_type_translate.get(ion_type_df[df_index]))
|
|
142
|
+
if adduct_df is not None:
|
|
143
|
+
adduct_atom = str(adduct_df[df_index])
|
|
144
|
+
if adduct_atom == "None":
|
|
145
|
+
adduct_atom = None
|
|
146
|
+
else:
|
|
147
|
+
adduct_atom = None
|
|
148
|
+
|
|
149
|
+
# If not isotopologue, cast as MolecularFormula
|
|
150
|
+
if not bool(int(is_isotopologue_df[df_index])):
|
|
151
|
+
mfobj = MolecularFormula(
|
|
152
|
+
formula_dict,
|
|
153
|
+
int(ion_charge_df[df_index]),
|
|
154
|
+
mspeak_parent=mass_spec_obj[ms_peak_index],
|
|
155
|
+
ion_type=ion_type,
|
|
156
|
+
adduct_atom=adduct_atom,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
# if is isotopologue, recast as MolecularFormulaIsotopologue
|
|
160
|
+
if bool(int(is_isotopologue_df[df_index])):
|
|
161
|
+
# First make a MolecularFormula object for the parent so we can get probabilities etc
|
|
162
|
+
formula_list_parent = {}
|
|
163
|
+
for atom in formula_dict:
|
|
164
|
+
if atom in Atoms.isotopes.keys():
|
|
165
|
+
formula_list_parent[atom] = formula_dict[atom]
|
|
166
|
+
else:
|
|
167
|
+
# remove any numbers from the atom name to cast as a mono-isotopic atom
|
|
168
|
+
atom_mono = atom.strip("0123456789")
|
|
169
|
+
if (
|
|
170
|
+
atom_mono in Atoms.isotopes.keys()
|
|
171
|
+
and atom_mono in formula_list_parent.keys()
|
|
172
|
+
):
|
|
173
|
+
formula_list_parent[atom_mono] = (
|
|
174
|
+
formula_list_parent[atom_mono] + formula_dict[atom]
|
|
175
|
+
)
|
|
176
|
+
elif atom_mono in Atoms.isotopes.keys():
|
|
177
|
+
formula_list_parent[atom_mono] = formula_dict[atom]
|
|
178
|
+
else:
|
|
179
|
+
warnings.warn(f"Atom {atom} not in Atoms.atoms_order")
|
|
180
|
+
mono_index = int(dataframe.iloc[df_index]["Mono Isotopic Index"])
|
|
181
|
+
mono_mfobj = MolecularFormula(
|
|
182
|
+
formula_list_parent,
|
|
183
|
+
int(ion_charge_df[df_index]),
|
|
184
|
+
mspeak_parent=mass_spec_obj[mono_index],
|
|
185
|
+
ion_type=ion_type,
|
|
186
|
+
adduct_atom=adduct_atom,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
# Next, generate isotopologues from the parent
|
|
190
|
+
isos = list(
|
|
191
|
+
mono_mfobj.isotopologues(
|
|
192
|
+
min_abundance=mass_spec_obj.abundance.min()*0.01,
|
|
193
|
+
current_mono_abundance=mass_spec_obj[mono_index].abundance,
|
|
194
|
+
dynamic_range=mass_spec_obj.dynamic_range,
|
|
195
|
+
)
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
# Finally, find the isotopologue that matches the formula_dict
|
|
199
|
+
matched_isos = []
|
|
200
|
+
for iso in isos:
|
|
201
|
+
# If match was already found, exit the loop
|
|
202
|
+
if len(matched_isos) > 0:
|
|
203
|
+
break
|
|
204
|
+
else:
|
|
205
|
+
# Check the atoms match
|
|
206
|
+
if set(iso.atoms) == set(formula_dict.keys()):
|
|
207
|
+
# Check the values of the atoms match
|
|
208
|
+
if all(
|
|
209
|
+
[
|
|
210
|
+
iso[atom] == formula_dict[atom]
|
|
211
|
+
for atom in formula_dict
|
|
212
|
+
]
|
|
213
|
+
):
|
|
214
|
+
matched_isos.append(iso)
|
|
215
|
+
|
|
216
|
+
if len(matched_isos) == 0:
|
|
217
|
+
#FIXME: This should not occur see https://code.emsl.pnl.gov/mass-spectrometry/corems/-/issues/190
|
|
218
|
+
warnings.warn(f"No isotopologue matched the formula_dict: {formula_dict}")
|
|
219
|
+
bad_mf = True
|
|
220
|
+
else:
|
|
221
|
+
bad_mf = False
|
|
222
|
+
mfobj = matched_isos[0]
|
|
223
|
+
|
|
224
|
+
# Add the mono isotopic index, confidence score and isotopologue similarity
|
|
225
|
+
mfobj.mspeak_index_mono_isotopic = int(
|
|
226
|
+
dataframe.iloc[df_index]["Mono Isotopic Index"]
|
|
227
|
+
)
|
|
228
|
+
if not bad_mf:
|
|
229
|
+
# Add the confidence score and isotopologue similarity and average MZ error score
|
|
230
|
+
if "m/z Error Score" in dataframe:
|
|
231
|
+
mfobj._mass_error_average_score = float(
|
|
232
|
+
dataframe.iloc[df_index]["m/z Error Score"]
|
|
233
|
+
)
|
|
234
|
+
if "Confidence Score" in dataframe:
|
|
235
|
+
mfobj._confidence_score = float(
|
|
236
|
+
dataframe.iloc[df_index]["Confidence Score"]
|
|
237
|
+
)
|
|
238
|
+
if "Isotopologue Similarity" in dataframe:
|
|
239
|
+
mfobj._isotopologue_similarity = float(
|
|
240
|
+
dataframe.iloc[df_index]["Isotopologue Similarity"]
|
|
241
|
+
)
|
|
242
|
+
mass_spec_obj[ms_peak_index].add_molecular_formula(mfobj)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
class ReadMassList(MassListBaseClass):
|
|
246
|
+
"""
|
|
247
|
+
The ReadMassList object reads unprocessed mass list data types
|
|
248
|
+
and returns the mass spectrum object.
|
|
249
|
+
|
|
250
|
+
Parameters
|
|
251
|
+
----------
|
|
252
|
+
MassListBaseClass : class
|
|
253
|
+
The base class for reading mass list data types.
|
|
254
|
+
|
|
255
|
+
Methods
|
|
256
|
+
-------
|
|
257
|
+
* get_mass_spectrum(polarity, scan=0, auto_process=True, loadSettings=True). Reads mass list data types and returns the mass spectrum object.
|
|
258
|
+
|
|
259
|
+
"""
|
|
260
|
+
|
|
261
|
+
def get_mass_spectrum(
|
|
262
|
+
self,
|
|
263
|
+
polarity: int,
|
|
264
|
+
scan: int = 0,
|
|
265
|
+
auto_process: bool = True,
|
|
266
|
+
loadSettings: bool = True,
|
|
267
|
+
):
|
|
268
|
+
"""
|
|
269
|
+
Reads mass list data types and returns the mass spectrum object.
|
|
270
|
+
|
|
271
|
+
Parameters
|
|
272
|
+
----------
|
|
273
|
+
polarity : int
|
|
274
|
+
The polarity of the mass spectrum (+1 or -1).
|
|
275
|
+
scan : int, optional
|
|
276
|
+
The scan number of the mass spectrum (default is 0).
|
|
277
|
+
auto_process : bool, optional
|
|
278
|
+
Flag indicating whether to automatically process the mass spectrum (default is True).
|
|
279
|
+
loadSettings : bool, optional
|
|
280
|
+
Flag indicating whether to load settings for the mass spectrum (default is True).
|
|
281
|
+
|
|
282
|
+
Returns
|
|
283
|
+
-------
|
|
284
|
+
mass_spec : MassSpecCentroid or MassSpecProfile
|
|
285
|
+
The mass spectrum object.
|
|
286
|
+
|
|
287
|
+
"""
|
|
288
|
+
|
|
289
|
+
# delimiter = " " or " " or "," or "\t" etc
|
|
290
|
+
|
|
291
|
+
if self.isCentroid:
|
|
292
|
+
dataframe = self.get_dataframe()
|
|
293
|
+
|
|
294
|
+
self.check_columns(dataframe.columns)
|
|
295
|
+
|
|
296
|
+
self.clean_data_frame(dataframe)
|
|
297
|
+
|
|
298
|
+
dataframe.rename(columns=self.parameters.header_translate, inplace=True)
|
|
299
|
+
|
|
300
|
+
output_parameters = self.get_output_parameters(polarity)
|
|
301
|
+
|
|
302
|
+
mass_spec = MassSpecCentroid(
|
|
303
|
+
dataframe.to_dict(orient="list"),
|
|
304
|
+
output_parameters,
|
|
305
|
+
auto_process=auto_process,
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
if loadSettings:
|
|
309
|
+
self.load_settings(mass_spec, output_parameters)
|
|
310
|
+
|
|
311
|
+
return mass_spec
|
|
312
|
+
|
|
313
|
+
else:
|
|
314
|
+
dataframe = self.get_dataframe()
|
|
315
|
+
|
|
316
|
+
self.check_columns(dataframe.columns)
|
|
317
|
+
|
|
318
|
+
output_parameters = self.get_output_parameters(polarity)
|
|
319
|
+
|
|
320
|
+
self.clean_data_frame(dataframe)
|
|
321
|
+
|
|
322
|
+
dataframe.rename(columns=self.parameters.header_translate, inplace=True)
|
|
323
|
+
|
|
324
|
+
mass_spec = MassSpecProfile(
|
|
325
|
+
dataframe.to_dict(orient="list"),
|
|
326
|
+
output_parameters,
|
|
327
|
+
auto_process=auto_process,
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
if loadSettings:
|
|
331
|
+
self.load_settings(mass_spec, output_parameters)
|
|
332
|
+
|
|
333
|
+
return mass_spec
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
class ReadBrukerXMLList(MassListBaseClass):
|
|
337
|
+
"""
|
|
338
|
+
The ReadBrukerXMLList object reads Bruker XML objects
|
|
339
|
+
and returns the mass spectrum object.
|
|
340
|
+
See MassListBaseClass for details
|
|
341
|
+
|
|
342
|
+
Parameters
|
|
343
|
+
----------
|
|
344
|
+
MassListBaseClass : class
|
|
345
|
+
The base class for reading mass list data types and returning the mass spectrum object.
|
|
346
|
+
|
|
347
|
+
Methods
|
|
348
|
+
-------
|
|
349
|
+
* get_mass_spectrum(polarity: bool = None, scan: int = 0, auto_process: bool = True, loadSettings: bool = True). Reads mass list data types and returns the mass spectrum object.
|
|
350
|
+
|
|
351
|
+
"""
|
|
352
|
+
|
|
353
|
+
def get_mass_spectrum(
|
|
354
|
+
self,
|
|
355
|
+
polarity: bool = None,
|
|
356
|
+
scan: int = 0,
|
|
357
|
+
auto_process: bool = True,
|
|
358
|
+
loadSettings: bool = True,
|
|
359
|
+
):
|
|
360
|
+
"""
|
|
361
|
+
Reads mass list data types and returns the mass spectrum object.
|
|
362
|
+
|
|
363
|
+
Parameters
|
|
364
|
+
----------
|
|
365
|
+
polarity : bool, optional
|
|
366
|
+
The polarity of the mass spectrum. Can be +1 or -1. If not provided, it will be determined from the XML file.
|
|
367
|
+
scan : int, optional
|
|
368
|
+
The scan number of the mass spectrum. Default is 0.
|
|
369
|
+
auto_process : bool, optional
|
|
370
|
+
Whether to automatically process the mass spectrum. Default is True.
|
|
371
|
+
loadSettings : bool, optional
|
|
372
|
+
Whether to load the settings for the mass spectrum. Default is True.
|
|
373
|
+
|
|
374
|
+
Returns
|
|
375
|
+
-------
|
|
376
|
+
mass_spec : MassSpecCentroid
|
|
377
|
+
The mass spectrum object representing the centroided mass spectrum.
|
|
378
|
+
"""
|
|
379
|
+
# delimiter = " " or " " or "," or "\t" etc
|
|
380
|
+
|
|
381
|
+
if polarity == None:
|
|
382
|
+
polarity = self.get_xml_polarity()
|
|
383
|
+
dataframe = self.get_dataframe()
|
|
384
|
+
|
|
385
|
+
self.check_columns(dataframe.columns)
|
|
386
|
+
|
|
387
|
+
self.clean_data_frame(dataframe)
|
|
388
|
+
|
|
389
|
+
dataframe.rename(columns=self.parameters.header_translate, inplace=True)
|
|
390
|
+
|
|
391
|
+
output_parameters = self.get_output_parameters(polarity)
|
|
392
|
+
|
|
393
|
+
mass_spec = MassSpecCentroid(
|
|
394
|
+
dataframe.to_dict(orient="list"),
|
|
395
|
+
output_parameters,
|
|
396
|
+
auto_process=auto_process,
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
if loadSettings:
|
|
400
|
+
self.load_settings(mass_spec, output_parameters)
|
|
401
|
+
|
|
402
|
+
return mass_spec
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
__author__ = "Yuri E. Corilo"
|
|
2
|
+
__date__ = "Oct 23, 2019"
|
|
3
|
+
|
|
4
|
+
from corems.encapsulation.constant import Labels
|
|
5
|
+
from corems.encapsulation.factory.parameters import default_parameters
|
|
6
|
+
from corems.mass_spectrum.factory.MassSpectrumClasses import (
|
|
7
|
+
MassSpecCentroid,
|
|
8
|
+
MassSpecProfile,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def ms_from_array_profile(
|
|
13
|
+
mz,
|
|
14
|
+
abundance,
|
|
15
|
+
dataname: str,
|
|
16
|
+
polarity: int = -1,
|
|
17
|
+
auto_process: bool = True,
|
|
18
|
+
data_type: str = Labels.simulated_profile,
|
|
19
|
+
):
|
|
20
|
+
"""Create a MassSpecProfile object from an array of m/z values and abundance values.
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
mz : numpy.ndarray
|
|
25
|
+
Array of m/z values.
|
|
26
|
+
abundance : numpy.ndarray
|
|
27
|
+
Array of abundance values.
|
|
28
|
+
dataname : str
|
|
29
|
+
Name of the data.
|
|
30
|
+
polarity : int, optional
|
|
31
|
+
Polarity of the data. The default is -1.
|
|
32
|
+
auto_process : bool, optional
|
|
33
|
+
Flag to automatically process the data. The default is True.
|
|
34
|
+
data_type : str, optional
|
|
35
|
+
Type of the data. The default is Labels.simulated_profile.
|
|
36
|
+
|
|
37
|
+
Returns
|
|
38
|
+
-------
|
|
39
|
+
MassSpecProfile
|
|
40
|
+
The created MassSpecProfile object.
|
|
41
|
+
"""
|
|
42
|
+
data_dict = {Labels.mz: mz, Labels.abundance: abundance}
|
|
43
|
+
|
|
44
|
+
output_parameters = get_output_parameters(polarity, dataname)
|
|
45
|
+
|
|
46
|
+
output_parameters[Labels.label] = data_type
|
|
47
|
+
|
|
48
|
+
ms = MassSpecProfile(data_dict, output_parameters, auto_process=auto_process)
|
|
49
|
+
|
|
50
|
+
return ms
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def ms_from_array_centroid(
|
|
54
|
+
mz,
|
|
55
|
+
abundance,
|
|
56
|
+
rp: list[float],
|
|
57
|
+
s2n: list[float],
|
|
58
|
+
dataname: str,
|
|
59
|
+
polarity: int = -1,
|
|
60
|
+
auto_process: bool = True,
|
|
61
|
+
):
|
|
62
|
+
"""Create a MassSpecCentroid object from an array of m/z values, abundance values, resolution power, and signal-to-noise ratio.
|
|
63
|
+
|
|
64
|
+
Parameters
|
|
65
|
+
----------
|
|
66
|
+
mz : numpy.ndarray
|
|
67
|
+
Array of m/z values.
|
|
68
|
+
abundance : numpy.ndarray
|
|
69
|
+
Array of abundance values.
|
|
70
|
+
rp : list(float)
|
|
71
|
+
List of resolving power values.
|
|
72
|
+
s2n : list(float)
|
|
73
|
+
List of signal-to-noise ratio values.
|
|
74
|
+
dataname : str
|
|
75
|
+
Name of the data.
|
|
76
|
+
polarity : int, optional
|
|
77
|
+
Polarity of the data. The default is -1.
|
|
78
|
+
auto_process : bool, optional
|
|
79
|
+
|
|
80
|
+
Returns
|
|
81
|
+
-------
|
|
82
|
+
MassSpecCentroid
|
|
83
|
+
The created MassSpecCentroid object.
|
|
84
|
+
"""
|
|
85
|
+
data_dict = {
|
|
86
|
+
Labels.mz: mz,
|
|
87
|
+
Labels.abundance: abundance,
|
|
88
|
+
Labels.s2n: s2n,
|
|
89
|
+
Labels.rp: rp,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
output_parameters = get_output_parameters(polarity, dataname)
|
|
93
|
+
output_parameters[Labels.label] = Labels.corems_centroid
|
|
94
|
+
|
|
95
|
+
return MassSpecCentroid(data_dict, output_parameters, auto_process)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def get_output_parameters(polarity: int, file_location: str):
|
|
99
|
+
"""Generate the output parameters for creating a MassSpecProfile or MassSpecCentroid object.
|
|
100
|
+
|
|
101
|
+
Parameters
|
|
102
|
+
----------
|
|
103
|
+
polarity : int
|
|
104
|
+
Polarity of the data.
|
|
105
|
+
file_location : str
|
|
106
|
+
File location.
|
|
107
|
+
|
|
108
|
+
Returns
|
|
109
|
+
-------
|
|
110
|
+
dict
|
|
111
|
+
Output parameters.
|
|
112
|
+
"""
|
|
113
|
+
d_params = default_parameters(file_location)
|
|
114
|
+
|
|
115
|
+
d_params["analyzer"] = "Generic Simulated"
|
|
116
|
+
|
|
117
|
+
d_params["instrument_label"] = "Generic Simulated"
|
|
118
|
+
|
|
119
|
+
d_params["polarity"] = polarity
|
|
120
|
+
|
|
121
|
+
d_params["filename_path"] = file_location
|
|
122
|
+
|
|
123
|
+
d_params["mobility_scan"] = 0
|
|
124
|
+
|
|
125
|
+
d_params["mobility_rt"] = 0
|
|
126
|
+
|
|
127
|
+
d_params["scan_number"] = 0
|
|
128
|
+
|
|
129
|
+
d_params["rt"] = 0
|
|
130
|
+
|
|
131
|
+
d_params[Labels.label] = Labels.simulated_profile
|
|
132
|
+
|
|
133
|
+
return d_params
|
|
File without changes
|