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,119 @@
|
|
|
1
|
+
class SpectrumSearchResults:
|
|
2
|
+
"""Class for storing Search Results for a single Spectrum Query
|
|
3
|
+
|
|
4
|
+
Parameters
|
|
5
|
+
----------
|
|
6
|
+
query_spectrum : MassSpectrum
|
|
7
|
+
The queried mass spectrum
|
|
8
|
+
precursor_mz : float, optional
|
|
9
|
+
The queried precursor_mz. None is interpreted as an open query, i.e. no precursor_mz
|
|
10
|
+
spectral_similarity_search_results : dict
|
|
11
|
+
The search results for the queried spectrum, which will be unpacked into attributes
|
|
12
|
+
|
|
13
|
+
Attributes
|
|
14
|
+
----------
|
|
15
|
+
query_spectrum : MassSpectrum
|
|
16
|
+
The queried mass spectrum
|
|
17
|
+
query_spectrum_id : int
|
|
18
|
+
The id of the queried spectrum (the scan number within an MassSpectra object)
|
|
19
|
+
precursor_mz : float
|
|
20
|
+
The precursor m/z of the queried spectrum
|
|
21
|
+
|
|
22
|
+
Other Possible Attributes
|
|
23
|
+
-------------------------
|
|
24
|
+
ref_mol_id : str
|
|
25
|
+
The id of the molecule associated with the query spectrum in reference database
|
|
26
|
+
ref_ms_id : str
|
|
27
|
+
The id of the query spectrum in reference database
|
|
28
|
+
ref_precursor_mz : float
|
|
29
|
+
The precursor mass of the query spectrum
|
|
30
|
+
precursor_mz_error_ppm : float
|
|
31
|
+
The ppm error between the query spectrum and the reference spectrum
|
|
32
|
+
entropy_similarity : float
|
|
33
|
+
The entropy similarity between the query spectrum and the reference spectrum
|
|
34
|
+
ref_ion_type : str
|
|
35
|
+
The ion type of the reference spectrum, i.e. [M+H]+, [M+Na]+, etc.
|
|
36
|
+
query_mz_in_ref_n : list
|
|
37
|
+
The number of query m/z peaks that are in the reference spectrum
|
|
38
|
+
query_mz_in_ref_fract : float
|
|
39
|
+
The fraction of query m/z peaks that are in the reference spectrum
|
|
40
|
+
query_frag_types : list
|
|
41
|
+
The fragment types of the query spectrum that are in the reference spectrum,
|
|
42
|
+
i.e. LSF (lipid species fragments) or MSF (molecular species fragments),
|
|
43
|
+
generally used for only for lipidomics
|
|
44
|
+
ref_mz_in_query_n : list
|
|
45
|
+
The number of reference m/z peaks that are in the query spectrum
|
|
46
|
+
ref_mz_in_query_fract : float
|
|
47
|
+
The fraction of reference m/z peaks that are in the query spectrum
|
|
48
|
+
ref_frag_types : list
|
|
49
|
+
The fragment types of the reference spectrum,
|
|
50
|
+
i.e. LSF (lipid species fragments) or MSF (molecular species fragments),
|
|
51
|
+
generally used for only for lipidomics
|
|
52
|
+
database_name : str
|
|
53
|
+
The name of the associated database, i.e. "LipidBlast" or "GNPS"
|
|
54
|
+
|
|
55
|
+
Methods
|
|
56
|
+
-------
|
|
57
|
+
*to_dataframe().
|
|
58
|
+
Convert the SpectrumSearchResults to a pandas DataFrame
|
|
59
|
+
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
def __init__(
|
|
63
|
+
self, query_spectrum, precursor_mz, spectral_similarity_search_results
|
|
64
|
+
):
|
|
65
|
+
self.query_spectrum = query_spectrum
|
|
66
|
+
self.precursor_mz = precursor_mz
|
|
67
|
+
if query_spectrum is not None:
|
|
68
|
+
if query_spectrum.scan_number is not None:
|
|
69
|
+
self.query_spectrum_id = query_spectrum.scan_number
|
|
70
|
+
attribute_keys = [
|
|
71
|
+
"ref_mol_id",
|
|
72
|
+
"ref_ms_id",
|
|
73
|
+
"ref_precursor_mz",
|
|
74
|
+
"precursor_mz_error_ppm",
|
|
75
|
+
"ref_ion_type",
|
|
76
|
+
"entropy_similarity",
|
|
77
|
+
"query_mz_in_ref_n",
|
|
78
|
+
"query_mz_in_ref_fract",
|
|
79
|
+
"query_frag_types",
|
|
80
|
+
"ref_mz_in_query_n",
|
|
81
|
+
"ref_mz_in_query_fract",
|
|
82
|
+
"ref_frag_types",
|
|
83
|
+
"database_name",
|
|
84
|
+
]
|
|
85
|
+
for key in spectral_similarity_search_results.keys():
|
|
86
|
+
if key in attribute_keys:
|
|
87
|
+
setattr(self, key, spectral_similarity_search_results[key])
|
|
88
|
+
|
|
89
|
+
def to_dataframe(self, cols_to_drop=None):
|
|
90
|
+
"""Convert the SpectrumSearchResults to a pandas DataFrame
|
|
91
|
+
|
|
92
|
+
Parameters
|
|
93
|
+
----------
|
|
94
|
+
cols_to_drop : list, optional
|
|
95
|
+
A list of columns to drop from the DataFrame. Default is None.
|
|
96
|
+
|
|
97
|
+
Returns
|
|
98
|
+
-------
|
|
99
|
+
pandas.DataFrame
|
|
100
|
+
A DataFrame with the SpectrumSearchResults attributes as columns
|
|
101
|
+
|
|
102
|
+
"""
|
|
103
|
+
import pandas as pd
|
|
104
|
+
|
|
105
|
+
# get initial dict
|
|
106
|
+
df = pd.DataFrame.from_dict(self.__dict__).copy()
|
|
107
|
+
|
|
108
|
+
# remove ms2_spectrum column
|
|
109
|
+
df = df.drop(columns=["query_spectrum"])
|
|
110
|
+
|
|
111
|
+
# drop additional columns
|
|
112
|
+
if cols_to_drop is not None:
|
|
113
|
+
df = df.drop(columns=cols_to_drop)
|
|
114
|
+
|
|
115
|
+
# reorder to high to low entropy similarity
|
|
116
|
+
df = df.sort_values(by=["entropy_similarity"], ascending=False)
|
|
117
|
+
|
|
118
|
+
# rename id to query_scan_number
|
|
119
|
+
return pd.DataFrame(df)
|
|
File without changes
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
__author__ = "Yuri E. Corilo"
|
|
2
|
+
__date__ = "Feb 12, 2020"
|
|
3
|
+
|
|
4
|
+
from threading import Thread
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from corems.molecular_id.factory.EI_SQL import EI_LowRes_SQLite
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ReadNistMSI(Thread):
|
|
11
|
+
"""A class for reading NIST MSI files and storing the data in a SQLite database.
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
file_path : str
|
|
16
|
+
The path to the NIST MSI file.
|
|
17
|
+
url : str, optional
|
|
18
|
+
The URL for the SQLite database. Default is 'sqlite://'.
|
|
19
|
+
|
|
20
|
+
Raises
|
|
21
|
+
------
|
|
22
|
+
FileExistsError
|
|
23
|
+
If the specified file does not exist.
|
|
24
|
+
|
|
25
|
+
Attributes
|
|
26
|
+
----------
|
|
27
|
+
file_path : str
|
|
28
|
+
The path to the NIST MSI file.
|
|
29
|
+
url : str
|
|
30
|
+
The URL for the SQLite database.
|
|
31
|
+
sqlLite_obj : EI_LowRes_SQLite
|
|
32
|
+
The SQLite object for storing the compound data.
|
|
33
|
+
|
|
34
|
+
Methods
|
|
35
|
+
-------
|
|
36
|
+
* run().
|
|
37
|
+
Runs the thread and initializes the SQLite object.
|
|
38
|
+
* get_sqlLite_obj().
|
|
39
|
+
Returns the SQLite object.
|
|
40
|
+
* get_compound_data_dict_list().
|
|
41
|
+
Parses the NIST MSI file and returns a list of compound data dictionaries.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(self, file_path, url="sqlite://"):
|
|
45
|
+
Thread.__init__(self)
|
|
46
|
+
file_path = Path(file_path)
|
|
47
|
+
|
|
48
|
+
if not file_path.exists():
|
|
49
|
+
raise FileExistsError("File does not exist: " + file_path)
|
|
50
|
+
|
|
51
|
+
self.file_path = file_path
|
|
52
|
+
|
|
53
|
+
self.url = url
|
|
54
|
+
|
|
55
|
+
def run(self):
|
|
56
|
+
"""Runs the thread and initializes the SQLite object."""
|
|
57
|
+
self.sqlLite_obj = self.get_sqlLite_obj()
|
|
58
|
+
|
|
59
|
+
def get_sqlLite_obj(self):
|
|
60
|
+
"""Returns the SQLite object.
|
|
61
|
+
|
|
62
|
+
Returns
|
|
63
|
+
-------
|
|
64
|
+
EI_LowRes_SQLite
|
|
65
|
+
The SQLite object for storing the compound data.
|
|
66
|
+
"""
|
|
67
|
+
compound_data_dict_list = self.get_compound_data_dict_list()
|
|
68
|
+
|
|
69
|
+
sqlLite_obj = EI_LowRes_SQLite(url=self.url)
|
|
70
|
+
|
|
71
|
+
for data_dict in compound_data_dict_list:
|
|
72
|
+
if not data_dict.get("NUM PEAKS"):
|
|
73
|
+
data_dict["NUM PEAKS"] = len(data_dict.get("mz"))
|
|
74
|
+
if not data_dict.get("CASNO"):
|
|
75
|
+
data_dict["CASNO"] = data_dict.get("CAS")
|
|
76
|
+
if not data_dict["CASNO"]:
|
|
77
|
+
data_dict["CASNO"] = 0
|
|
78
|
+
# print(data_dict)
|
|
79
|
+
try:
|
|
80
|
+
sqlLite_obj.add_compound(data_dict)
|
|
81
|
+
except:
|
|
82
|
+
print(data_dict.get("NAME"))
|
|
83
|
+
|
|
84
|
+
return sqlLite_obj
|
|
85
|
+
|
|
86
|
+
def get_compound_data_dict_list(self):
|
|
87
|
+
"""Parses the NIST MSI file and returns a list of compound data dictionaries.
|
|
88
|
+
|
|
89
|
+
Returns
|
|
90
|
+
-------
|
|
91
|
+
list
|
|
92
|
+
A list of compound data dictionaries.
|
|
93
|
+
"""
|
|
94
|
+
list_dict_data = []
|
|
95
|
+
|
|
96
|
+
with open(self.file_path) as msifile:
|
|
97
|
+
content = msifile.readlines()
|
|
98
|
+
|
|
99
|
+
i = 0
|
|
100
|
+
|
|
101
|
+
dict_data = dict()
|
|
102
|
+
dict_data["mz"] = list()
|
|
103
|
+
dict_data["abundance"] = list()
|
|
104
|
+
# for line in content:
|
|
105
|
+
# print(line, line=="\n" )
|
|
106
|
+
|
|
107
|
+
while i < len(content):
|
|
108
|
+
split_line = content[i].split(":")
|
|
109
|
+
|
|
110
|
+
# empty line
|
|
111
|
+
if len(content[i]) == 1:
|
|
112
|
+
i += 1
|
|
113
|
+
if dict_data.get("NAME"):
|
|
114
|
+
list_dict_data.append(dict_data)
|
|
115
|
+
|
|
116
|
+
# print(dict_data)
|
|
117
|
+
dict_data = dict()
|
|
118
|
+
dict_data["mz"] = list()
|
|
119
|
+
dict_data["abundance"] = list()
|
|
120
|
+
|
|
121
|
+
# metadata, name, ri, rt etc
|
|
122
|
+
elif len(split_line) >= 2:
|
|
123
|
+
label = split_line[0]
|
|
124
|
+
value = ":".join(split_line[1:]).strip("\n").strip("")
|
|
125
|
+
dict_data[label] = value
|
|
126
|
+
i += 1
|
|
127
|
+
|
|
128
|
+
# mz and abundance pairs
|
|
129
|
+
elif len(split_line) == 1:
|
|
130
|
+
for s in content[i].strip("\n").strip("").split("(")[1:]:
|
|
131
|
+
values = s.split(" ")
|
|
132
|
+
|
|
133
|
+
if values[0] == "":
|
|
134
|
+
mz = values[1]
|
|
135
|
+
else:
|
|
136
|
+
mz = values[0]
|
|
137
|
+
|
|
138
|
+
abun = values[-2].strip(")")
|
|
139
|
+
|
|
140
|
+
dict_data["mz"].append(mz)
|
|
141
|
+
dict_data["abundance"].append(abun)
|
|
142
|
+
|
|
143
|
+
i += 1
|
|
144
|
+
# something else
|
|
145
|
+
else:
|
|
146
|
+
i += 1
|
|
147
|
+
|
|
148
|
+
return list_dict_data
|
|
File without changes
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
from math import exp
|
|
2
|
+
from threading import Thread
|
|
3
|
+
|
|
4
|
+
from numpy import power
|
|
5
|
+
|
|
6
|
+
from corems.molecular_id.calc.SpectralSimilarity import SpectralSimilarity
|
|
7
|
+
from corems.molecular_id.factory.EI_SQL import EI_LowRes_SQLite
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LowResMassSpectralMatch(Thread):
|
|
11
|
+
"""A class representing a low-resolution mass spectral match.
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
-----------
|
|
15
|
+
gcms_obj : object
|
|
16
|
+
The GC-MS object.
|
|
17
|
+
sql_obj : object, optional
|
|
18
|
+
The SQL object for database operations. Default is None.
|
|
19
|
+
calibration : bool, optional
|
|
20
|
+
Flag indicating if the match is for calibration. Default is False.
|
|
21
|
+
|
|
22
|
+
Attributes
|
|
23
|
+
-----------
|
|
24
|
+
gcms_obj : object
|
|
25
|
+
The GC-MS object.
|
|
26
|
+
sql_obj : object
|
|
27
|
+
The SQL object for database operations.
|
|
28
|
+
calibration : bool
|
|
29
|
+
Flag indicating if the match is for calibration.
|
|
30
|
+
|
|
31
|
+
Methods
|
|
32
|
+
--------
|
|
33
|
+
* metabolite_detector_score(gc_peak, ref_obj, spectral_simi).
|
|
34
|
+
Calculates the spectral similarity scores and the similarity score for a given GC peak and reference object.
|
|
35
|
+
* run().
|
|
36
|
+
Runs the low-resolution mass spectral match.
|
|
37
|
+
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
def __init__(self, gcms_obj, sql_obj=None, calibration=False):
|
|
41
|
+
Thread.__init__(self)
|
|
42
|
+
|
|
43
|
+
self.gcms_obj = gcms_obj
|
|
44
|
+
|
|
45
|
+
# initiated at create_molecular_database()
|
|
46
|
+
# self.dict_molecular_lookup_table = None
|
|
47
|
+
self.calibration = calibration
|
|
48
|
+
# reading local file for now,
|
|
49
|
+
if not sql_obj:
|
|
50
|
+
self.sql_obj = EI_LowRes_SQLite(
|
|
51
|
+
url=self.gcms_obj.molecular_search_settings.url_database
|
|
52
|
+
)
|
|
53
|
+
else:
|
|
54
|
+
self.sql_obj = sql_obj
|
|
55
|
+
|
|
56
|
+
def metabolite_detector_score(self, gc_peak, ref_obj, spectral_simi):
|
|
57
|
+
"""
|
|
58
|
+
Calculates the spectral similarity scores and the similarity score for a given GC peak and reference object.
|
|
59
|
+
|
|
60
|
+
Parameters
|
|
61
|
+
-----------
|
|
62
|
+
gc_peak : object
|
|
63
|
+
The GC peak object.
|
|
64
|
+
ref_obj : object
|
|
65
|
+
The reference object.
|
|
66
|
+
spectral_simi : object
|
|
67
|
+
The spectral similarity object.
|
|
68
|
+
|
|
69
|
+
Returns
|
|
70
|
+
--------
|
|
71
|
+
tuple
|
|
72
|
+
A tuple containing the spectral similarity scores, RI score, and similarity score.
|
|
73
|
+
|
|
74
|
+
"""
|
|
75
|
+
spectral_similarity_scores = {}
|
|
76
|
+
spectral_similarity_scores["cosine_correlation"] = (
|
|
77
|
+
spectral_simi.cosine_correlation()
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
if self.gcms_obj.molecular_search_settings.exploratory_mode:
|
|
81
|
+
spectral_similarity_scores["weighted_cosine_correlation"] = (
|
|
82
|
+
spectral_simi.weighted_cosine_correlation()
|
|
83
|
+
)
|
|
84
|
+
ss, ss_nist = spectral_simi.stein_scott()
|
|
85
|
+
spectral_similarity_scores["stein_scott_similarity"] = ss
|
|
86
|
+
spectral_similarity_scores["stein_scott_similarity_nist"] = ss_nist
|
|
87
|
+
|
|
88
|
+
spectral_similarity_scores["pearson_correlation"] = (
|
|
89
|
+
spectral_simi.pearson_correlation()
|
|
90
|
+
)
|
|
91
|
+
spectral_similarity_scores["spearman_correlation"] = (
|
|
92
|
+
spectral_simi.spearman_correlation()
|
|
93
|
+
)
|
|
94
|
+
spectral_similarity_scores["kendall_tau_correlation"] = (
|
|
95
|
+
spectral_simi.kendall_tau()
|
|
96
|
+
)
|
|
97
|
+
spectral_similarity_scores["euclidean_distance"] = (
|
|
98
|
+
spectral_simi.euclidean_distance()
|
|
99
|
+
)
|
|
100
|
+
spectral_similarity_scores["manhattan_distance"] = (
|
|
101
|
+
spectral_simi.manhattan_distance()
|
|
102
|
+
)
|
|
103
|
+
spectral_similarity_scores["jaccard_distance"] = (
|
|
104
|
+
spectral_simi.jaccard_distance()
|
|
105
|
+
)
|
|
106
|
+
spectral_similarity_scores["dft_correlation"] = (
|
|
107
|
+
spectral_simi.dft_correlation()
|
|
108
|
+
)
|
|
109
|
+
spectral_similarity_scores["dwt_correlation"] = (
|
|
110
|
+
spectral_simi.dwt_correlation()
|
|
111
|
+
)
|
|
112
|
+
spectral_similarity_scores.update(spectral_simi.extra_distances())
|
|
113
|
+
# print(spectral_similarity_scores)
|
|
114
|
+
# print(ref_obj.get('ri'), gc_peak.ri, self.gcms_obj.molecular_search_settings.ri_window)
|
|
115
|
+
|
|
116
|
+
ri_score = exp(
|
|
117
|
+
-1
|
|
118
|
+
* (
|
|
119
|
+
power((gc_peak.ri - ref_obj.get("ri")), 2)
|
|
120
|
+
/ (2 * power(self.gcms_obj.molecular_search_settings.ri_std, 2))
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
similarity_score = (
|
|
125
|
+
(spectral_similarity_scores.get("cosine_correlation") ** 2) * (ri_score)
|
|
126
|
+
) ** (1 / 3)
|
|
127
|
+
|
|
128
|
+
return spectral_similarity_scores, ri_score, similarity_score
|
|
129
|
+
|
|
130
|
+
def run(self):
|
|
131
|
+
"""Runs the low-resolution mass spectral match."""
|
|
132
|
+
# TODO select the best gcms peak
|
|
133
|
+
import tqdm
|
|
134
|
+
|
|
135
|
+
original_use_deconvolution = (
|
|
136
|
+
self.gcms_obj.chromatogram_settings.use_deconvolution
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
if not self.gcms_obj:
|
|
140
|
+
# Do not use deconvolution for the retention index calibration
|
|
141
|
+
|
|
142
|
+
if self.calibration:
|
|
143
|
+
self.gcms_obj.chromatogram_settings.use_deconvolution = False
|
|
144
|
+
|
|
145
|
+
self.gcms_obj.process_chromatogram()
|
|
146
|
+
|
|
147
|
+
self.gcms_obj.chromatogram_settings.use_deconvolution = (
|
|
148
|
+
original_use_deconvolution
|
|
149
|
+
)
|
|
150
|
+
verbose = self.gcms_obj.chromatogram_settings.verbose_processing
|
|
151
|
+
for gc_peak in tqdm.tqdm(self.gcms_obj, disable = not verbose):
|
|
152
|
+
if not self.calibration:
|
|
153
|
+
window = self.gcms_obj.molecular_search_settings.ri_search_range
|
|
154
|
+
|
|
155
|
+
ri = gc_peak.ri
|
|
156
|
+
|
|
157
|
+
min_mat_ri = (ri - window, ri + window)
|
|
158
|
+
|
|
159
|
+
ref_objs = self.sql_obj.query_min_max_ri(min_mat_ri)
|
|
160
|
+
|
|
161
|
+
else:
|
|
162
|
+
compound_names = self.gcms_obj.molecular_search_settings.ri_calibration_compound_names
|
|
163
|
+
|
|
164
|
+
window = self.gcms_obj.molecular_search_settings.rt_search_range
|
|
165
|
+
|
|
166
|
+
rt = gc_peak.retention_time
|
|
167
|
+
|
|
168
|
+
min_mat_rt = (rt - window, rt + window)
|
|
169
|
+
|
|
170
|
+
ref_objs = self.sql_obj.query_names_and_rt(min_mat_rt, compound_names)
|
|
171
|
+
|
|
172
|
+
for ref_obj in ref_objs:
|
|
173
|
+
# uses spectral similarly and uses a threshold to only select peaks with high data correlation
|
|
174
|
+
|
|
175
|
+
spectral_simi = SpectralSimilarity(
|
|
176
|
+
gc_peak.mass_spectrum.mz_abun_dict, ref_obj
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
if self.calibration:
|
|
180
|
+
spectral_similarity_scores = {}
|
|
181
|
+
spectral_similarity_scores["cosine_correlation"] = (
|
|
182
|
+
spectral_simi.cosine_correlation()
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# print(w_correlation_value,correlation_value )
|
|
186
|
+
if (
|
|
187
|
+
spectral_similarity_scores["cosine_correlation"]
|
|
188
|
+
>= self.gcms_obj.molecular_search_settings.correlation_threshold
|
|
189
|
+
):
|
|
190
|
+
gc_peak.add_compound(ref_obj, spectral_similarity_scores)
|
|
191
|
+
|
|
192
|
+
# use score, usually a combination of Retention index and Spectral Similarity
|
|
193
|
+
# Threshold is implemented by not necessarily used
|
|
194
|
+
else:
|
|
195
|
+
# m/q developed methods will be implemented here
|
|
196
|
+
spectral_similarity_scores, ri_score, similarity_score = (
|
|
197
|
+
self.metabolite_detector_score(gc_peak, ref_obj, spectral_simi)
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
# TODO need to add similarity score option in the parameters encapsulation class
|
|
201
|
+
|
|
202
|
+
if (
|
|
203
|
+
similarity_score
|
|
204
|
+
>= self.gcms_obj.molecular_search_settings.score_threshold
|
|
205
|
+
):
|
|
206
|
+
gc_peak.add_compound(
|
|
207
|
+
ref_obj,
|
|
208
|
+
spectral_similarity_scores,
|
|
209
|
+
ri_score,
|
|
210
|
+
similarity_score,
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
self.sql_obj.session.close()
|
|
214
|
+
self.sql_obj.engine.dispose()
|