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.
Files changed (171) hide show
  1. corems/__init__.py +63 -0
  2. corems/chroma_peak/__init__.py +0 -0
  3. corems/chroma_peak/calc/ChromaPeakCalc.py +480 -0
  4. corems/chroma_peak/calc/__init__.py +0 -0
  5. corems/chroma_peak/calc/subset.py +196 -0
  6. corems/chroma_peak/factory/__init__.py +0 -0
  7. corems/chroma_peak/factory/chroma_peak_classes.py +1178 -0
  8. corems/encapsulation/__init__.py +0 -0
  9. corems/encapsulation/constant.py +1283 -0
  10. corems/encapsulation/factory/__init__.py +0 -0
  11. corems/encapsulation/factory/parameters.py +392 -0
  12. corems/encapsulation/factory/processingSetting.py +1244 -0
  13. corems/encapsulation/input/__init__.py +0 -0
  14. corems/encapsulation/input/parameter_from_json.py +579 -0
  15. corems/encapsulation/output/__init__.py +0 -0
  16. corems/encapsulation/output/parameter_to_dict.py +142 -0
  17. corems/encapsulation/output/parameter_to_json.py +332 -0
  18. corems/mass_spectra/__init__.py +0 -0
  19. corems/mass_spectra/calc/GC_Calc.py +84 -0
  20. corems/mass_spectra/calc/GC_Deconvolution.py +558 -0
  21. corems/mass_spectra/calc/GC_RI_Calibration.py +44 -0
  22. corems/mass_spectra/calc/MZSearch.py +249 -0
  23. corems/mass_spectra/calc/SignalProcessing.py +656 -0
  24. corems/mass_spectra/calc/__init__.py +0 -0
  25. corems/mass_spectra/calc/lc_calc.py +5790 -0
  26. corems/mass_spectra/calc/lc_calc_operations.py +1127 -0
  27. corems/mass_spectra/factory/GC_Class.py +791 -0
  28. corems/mass_spectra/factory/__init__.py +0 -0
  29. corems/mass_spectra/factory/chromat_data.py +51 -0
  30. corems/mass_spectra/factory/lc_class.py +2721 -0
  31. corems/mass_spectra/input/__init__.py +0 -0
  32. corems/mass_spectra/input/andiNetCDF.py +200 -0
  33. corems/mass_spectra/input/boosterHDF5.py +216 -0
  34. corems/mass_spectra/input/brukerSolarix.py +153 -0
  35. corems/mass_spectra/input/brukerSolarix_utils.py +73 -0
  36. corems/mass_spectra/input/corems_hdf5.py +1710 -0
  37. corems/mass_spectra/input/massList.py +133 -0
  38. corems/mass_spectra/input/mzml.py +668 -0
  39. corems/mass_spectra/input/parserbase.py +239 -0
  40. corems/mass_spectra/input/rawFileReader.py +1839 -0
  41. corems/mass_spectra/output/__init__.py +0 -0
  42. corems/mass_spectra/output/export.py +2800 -0
  43. corems/mass_spectrum/__init__.py +0 -0
  44. corems/mass_spectrum/calc/AutoRecalibration.py +237 -0
  45. corems/mass_spectrum/calc/Calibration.py +602 -0
  46. corems/mass_spectrum/calc/CalibrationCalc.py +253 -0
  47. corems/mass_spectrum/calc/KendrickGroup.py +239 -0
  48. corems/mass_spectrum/calc/MassErrorPrediction.py +436 -0
  49. corems/mass_spectrum/calc/MassSpectrumCalc.py +303 -0
  50. corems/mass_spectrum/calc/MeanResolvingPowerFilter.py +212 -0
  51. corems/mass_spectrum/calc/NoiseCalc.py +371 -0
  52. corems/mass_spectrum/calc/NoiseCalc_Bayes.py +93 -0
  53. corems/mass_spectrum/calc/PeakPicking.py +994 -0
  54. corems/mass_spectrum/calc/__init__.py +0 -0
  55. corems/mass_spectrum/factory/MassSpectrumClasses.py +1753 -0
  56. corems/mass_spectrum/factory/__init__.py +0 -0
  57. corems/mass_spectrum/input/__init__.py +0 -0
  58. corems/mass_spectrum/input/baseClass.py +531 -0
  59. corems/mass_spectrum/input/boosterHDF5.py +161 -0
  60. corems/mass_spectrum/input/coremsHDF5.py +475 -0
  61. corems/mass_spectrum/input/massList.py +402 -0
  62. corems/mass_spectrum/input/numpyArray.py +133 -0
  63. corems/mass_spectrum/output/__init__.py +0 -0
  64. corems/mass_spectrum/output/export.py +841 -0
  65. corems/molecular_formula/__init__.py +0 -0
  66. corems/molecular_formula/calc/MolecularFormulaCalc.py +885 -0
  67. corems/molecular_formula/calc/__init__.py +0 -0
  68. corems/molecular_formula/factory/MolecularFormulaFactory.py +895 -0
  69. corems/molecular_formula/factory/__init__.py +0 -0
  70. corems/molecular_formula/input/__init__.py +0 -0
  71. corems/molecular_formula/input/masslist_ref.py +355 -0
  72. corems/molecular_id/__init__.py +0 -0
  73. corems/molecular_id/calc/ClusterFilter.py +251 -0
  74. corems/molecular_id/calc/MolecularFilter.py +122 -0
  75. corems/molecular_id/calc/SpectralSimilarity.py +632 -0
  76. corems/molecular_id/calc/__init__.py +0 -0
  77. corems/molecular_id/calc/math_distance.py +1637 -0
  78. corems/molecular_id/data/FAMES_REF.msp +980 -0
  79. corems/molecular_id/data/PNNLMetV20191015.msp +157267 -0
  80. corems/molecular_id/factory/EI_SQL.py +650 -0
  81. corems/molecular_id/factory/MolecularLookupTable.py +914 -0
  82. corems/molecular_id/factory/__init__.py +0 -0
  83. corems/molecular_id/factory/classification.py +884 -0
  84. corems/molecular_id/factory/lipid_molecular_metadata.py +50 -0
  85. corems/molecular_id/factory/molecularSQL.py +827 -0
  86. corems/molecular_id/factory/spectrum_search_results.py +119 -0
  87. corems/molecular_id/input/__init__.py +0 -0
  88. corems/molecular_id/input/nistMSI.py +148 -0
  89. corems/molecular_id/search/__init__.py +0 -0
  90. corems/molecular_id/search/compoundSearch.py +214 -0
  91. corems/molecular_id/search/database_interfaces.py +1527 -0
  92. corems/molecular_id/search/findOxygenPeaks.py +330 -0
  93. corems/molecular_id/search/lcms_spectral_search.py +348 -0
  94. corems/molecular_id/search/molecularFormulaSearch.py +1117 -0
  95. corems/molecular_id/search/priorityAssignment.py +723 -0
  96. corems/ms_peak/__init__.py +0 -0
  97. corems/ms_peak/calc/MSPeakCalc.py +1010 -0
  98. corems/ms_peak/calc/__init__.py +0 -0
  99. corems/ms_peak/factory/MSPeakClasses.py +542 -0
  100. corems/ms_peak/factory/__init__.py +0 -0
  101. corems/transient/__init__.py +0 -0
  102. corems/transient/calc/TransientCalc.py +362 -0
  103. corems/transient/calc/__init__.py +0 -0
  104. corems/transient/factory/TransientClasses.py +457 -0
  105. corems/transient/factory/__init__.py +0 -0
  106. corems/transient/input/__init__.py +0 -0
  107. corems/transient/input/brukerSolarix.py +461 -0
  108. corems/transient/input/midasDatFile.py +172 -0
  109. corems-4.0.0.dist-info/METADATA +475 -0
  110. corems-4.0.0.dist-info/RECORD +171 -0
  111. corems-4.0.0.dist-info/WHEEL +5 -0
  112. corems-4.0.0.dist-info/licenses/LICENSE +22 -0
  113. corems-4.0.0.dist-info/top_level.txt +4 -0
  114. examples/archive/scripts/CoreMS_tutorial.py +94 -0
  115. examples/archive/scripts/DI HR-MS Halogens Bruker.py +196 -0
  116. examples/archive/scripts/DI HR-MS MassList.py +385 -0
  117. examples/archive/scripts/GC-MS MetabRef.py +213 -0
  118. examples/archive/scripts/GC-MS NetCDF.py +217 -0
  119. examples/archive/scripts/HR-MS Thermo Raw 21T.py +136 -0
  120. examples/archive/scripts/LC-ICPMS_metal_peaks.py +297 -0
  121. examples/archive/scripts/LCMS-Thermo.py +460 -0
  122. examples/archive/scripts/LCMS_isotopes.py +283 -0
  123. examples/archive/scripts/MSParams_example.py +21 -0
  124. examples/archive/scripts/Molecular Formula Data Aggreation.py +84 -0
  125. examples/archive/scripts/Single Mz Search.py +69 -0
  126. examples/test_notebooks.py +145 -0
  127. ext_lib/ChemstationMSFileReader.dll +0 -0
  128. ext_lib/ChemstationMSFileReader.xml +126 -0
  129. ext_lib/RawFileReaderLicense.doc +0 -0
  130. ext_lib/ThermoFisher.CommonCore.BackgroundSubtraction.dll +0 -0
  131. ext_lib/ThermoFisher.CommonCore.BackgroundSubtraction.xml +2307 -0
  132. ext_lib/ThermoFisher.CommonCore.Data.dll +0 -0
  133. ext_lib/ThermoFisher.CommonCore.Data.xml +28974 -0
  134. ext_lib/ThermoFisher.CommonCore.MassPrecisionEstimator.dll +0 -0
  135. ext_lib/ThermoFisher.CommonCore.MassPrecisionEstimator.xml +241 -0
  136. ext_lib/ThermoFisher.CommonCore.RawFileReader.dll +0 -0
  137. ext_lib/ThermoFisher.CommonCore.RawFileReader.xml +31174 -0
  138. ext_lib/__init__.py +0 -0
  139. ext_lib/dotnet/OpenMcdf.Extensions.dll +0 -0
  140. ext_lib/dotnet/OpenMcdf.dll +0 -0
  141. ext_lib/dotnet/OpenMcdf.xml +1154 -0
  142. ext_lib/dotnet/System.IO.FileSystem.AccessControl.dll +0 -0
  143. ext_lib/dotnet/System.IO.FileSystem.AccessControl.xml +506 -0
  144. ext_lib/dotnet/System.Security.AccessControl.dll +0 -0
  145. ext_lib/dotnet/System.Security.AccessControl.xml +2043 -0
  146. ext_lib/dotnet/System.Security.Principal.Windows.dll +0 -0
  147. ext_lib/dotnet/System.Security.Principal.Windows.xml +1011 -0
  148. ext_lib/dotnet/ThermoFisher.CommonCore.BackgroundSubtraction.dll +0 -0
  149. ext_lib/dotnet/ThermoFisher.CommonCore.BackgroundSubtraction.xml +2307 -0
  150. ext_lib/dotnet/ThermoFisher.CommonCore.Data.dll +0 -0
  151. ext_lib/dotnet/ThermoFisher.CommonCore.Data.xml +29148 -0
  152. ext_lib/dotnet/ThermoFisher.CommonCore.MassPrecisionEstimator.dll +0 -0
  153. ext_lib/dotnet/ThermoFisher.CommonCore.MassPrecisionEstimator.xml +241 -0
  154. ext_lib/dotnet/ThermoFisher.CommonCore.RawFileReader.dll +0 -0
  155. ext_lib/dotnet/ThermoFisher.CommonCore.RawFileReader.xml +31492 -0
  156. ext_lib/version +18 -0
  157. support_code/atom_parsers/AtomsDescription.py +359 -0
  158. support_code/atom_parsers/CreateAtomsDescription.py +56 -0
  159. support_code/nmdc/filefinder.py +90 -0
  160. support_code/nmdc/lipidomics/lipidomics_workflow.py +748 -0
  161. support_code/nmdc/lipidomics/manifest_examples.py +49 -0
  162. support_code/nmdc/metabolomics/gcms_workflow.py +158 -0
  163. support_code/nmdc/metabolomics/lcms_metabolomics_targeted_search.py +59 -0
  164. support_code/nmdc/metabolomics/lcms_metabolomics_workflow.py +248 -0
  165. support_code/nmdc/metabolomics/metabolomics_collection.py +628 -0
  166. support_code/nmdc/metadata/dms_api.py +42 -0
  167. support_code/nmdc/nom/archived_scripts/nmdc_metadata_gen.py +288 -0
  168. support_code/nmdc/nom/archived_scripts/nom_grow_workflow.py +209 -0
  169. support_code/nmdc/nom/nom_workflow.py +312 -0
  170. support_code/windows_only_importers/BrukerCompassXtract.py +180 -0
  171. support_code/windows_only_importers/ThermoMSFileReader.py +405 -0
@@ -0,0 +1,142 @@
1
+ from corems.encapsulation.factory.parameters import (
2
+ MSParameters,
3
+ GCMSParameters,
4
+ LCMSParameters
5
+ )
6
+
7
+
8
+ def get_dict_all_default_data():
9
+ """Return a dictionary with all default parameters for MS and GCMS"""
10
+ ms_params = MSParameters(use_defaults=True)
11
+ gcms_params = GCMSParameters(use_defaults=True)
12
+
13
+ return {
14
+ "MolecularFormulaSearch": ms_params.molecular_search.__dict__,
15
+ "Transient": ms_params.transient.__dict__,
16
+ "MassSpectrum": ms_params.mass_spectrum.__dict__,
17
+ "MassSpecPeak": ms_params.ms_peak.__dict__,
18
+ "DataInput": ms_params.data_input.__dict__,
19
+ "MolecularSearch": gcms_params.molecular_search.__dict__,
20
+ "GasChromatograph": gcms_params.gc_ms.__dict__,
21
+ }
22
+
23
+
24
+ def get_dict_data_lcms(lcms_obj):
25
+ """Return a dictionary with all parameters for LCMSBase object
26
+
27
+ Parameters
28
+ ----------
29
+ lcms_obj: LCMSBase
30
+ LCMSBase object
31
+
32
+ Returns
33
+ -------
34
+ dict
35
+ dictionary with all parameters for LCMSBase object
36
+ """
37
+ output_dict = {}
38
+ output_dict["LiquidChromatograph"] = lcms_obj.parameters.lc_ms.__dict__
39
+ output_dict["mass_spectrum"] = {}
40
+ for key, value in lcms_obj.parameters.mass_spectrum.items():
41
+ output_dict["mass_spectrum"][key] = {}
42
+ for k, v in value.__dict__.items():
43
+ output_dict["mass_spectrum"][key][k] = v.__dict__
44
+ return output_dict
45
+
46
+
47
+ def get_dict_lcms_default_data():
48
+ """Return a dictionary with all default parameters for LCMS"""
49
+ default_params = LCMSParameters(use_defaults=True)
50
+
51
+ output_dict = {}
52
+ output_dict["LiquidChromatograph"] = default_params.lc_ms.__dict__
53
+ output_dict["mass_spectrum"] = {}
54
+ for key, value in default_params.mass_spectrum.items():
55
+ output_dict["mass_spectrum"][key] = {}
56
+ for k, v in value.__dict__.items():
57
+ output_dict["mass_spectrum"][key][k] = v.__dict__
58
+ return output_dict
59
+
60
+
61
+ def get_dict_data_ms(mass_spec):
62
+ """Return a dictionary with all parameters for MassSpectrum object
63
+
64
+ Parameters
65
+ ----------
66
+ mass_spec: MassSpectrum
67
+ MassSpectrum object
68
+
69
+ Returns
70
+ -------
71
+ dict
72
+ dictionary with all parameters for MassSpectrum object
73
+ """
74
+ ms_params = mass_spec.parameters
75
+ return {
76
+ "MolecularFormulaSearch": ms_params.molecular_search.__dict__,
77
+ "Transient": ms_params.transient.__dict__,
78
+ "MassSpectrum": ms_params.mass_spectrum.__dict__,
79
+ "MassSpecPeak": ms_params.ms_peak.__dict__,
80
+ "DataInput": ms_params.data_input.__dict__,
81
+ }
82
+
83
+
84
+ def get_dict_ms_default_data():
85
+ """Return a dictionary with all default parameters for MS including data input"""
86
+ ms_params = MSParameters(use_defaults=True)
87
+
88
+ return {
89
+ "MolecularFormulaSearch": ms_params.molecular_search.__dict__,
90
+ "Transient": ms_params.transient.__dict__,
91
+ "MassSpectrum": ms_params.mass_spectrum.__dict__,
92
+ "MassSpecPeak": ms_params.ms_peak.__dict__,
93
+ "DataInput": ms_params.data_input.__dict__,
94
+ }
95
+
96
+
97
+ def get_dict_gcms_default_data():
98
+ """Return a dictionary with all default parameters for GCMS"""
99
+ default_gcms_params = GCMSParameters(use_defaults=True)
100
+
101
+ return {
102
+ "MolecularSearch": default_gcms_params.molecular_search.__dict__,
103
+ "GasChromatograph": default_gcms_params.gc_ms.__dict__,
104
+ }
105
+
106
+
107
+ def get_dict_data_gcms(gcms):
108
+ """Return a dictionary with all parameters for GCMS"""
109
+
110
+ return {
111
+ "MolecularSearch": gcms.molecular_search_settings.__dict__,
112
+ "GasChromatograph": gcms.chromatogram_settings.__dict__,
113
+ }
114
+
115
+
116
+ def get_dict_data_lcms_collection(lcms_collection):
117
+ """Return a dictionary with all parameters for LCMSCollection object
118
+
119
+ Parameters
120
+ ----------
121
+ lcms_collection: LCMSCollection
122
+ LCMSCollection object
123
+
124
+ Returns
125
+ -------
126
+ dict
127
+ dictionary with all parameters for LCMSCollection object
128
+ """
129
+ output_dict = {}
130
+ output_dict["LCMSCollection"] = lcms_collection.parameters.lcms_collection.__dict__
131
+ return output_dict
132
+
133
+
134
+ def get_dict_lcms_collection_default_data():
135
+ """Return a dictionary with all default parameters for LCMS Collection"""
136
+ from corems.encapsulation.factory.processingSetting import LCMSCollectionSettings
137
+
138
+ default_params = LCMSCollectionSettings()
139
+
140
+ output_dict = {}
141
+ output_dict["LCMSCollection"] = default_params.__dict__
142
+ return output_dict
@@ -0,0 +1,332 @@
1
+ import json
2
+
3
+ import toml
4
+ from pathlib import Path
5
+
6
+ from corems.encapsulation.output import parameter_to_dict
7
+ from corems.encapsulation.output.parameter_to_dict import get_dict_data_lcms
8
+
9
+
10
+ def dump_all_settings_json(filename="SettingsCoreMS.json", file_path=None):
11
+ """
12
+ Write JSON file into current directory with all the default settings for the CoreMS package.
13
+
14
+ Parameters:
15
+ ----------
16
+ filename : str, optional
17
+ The name of the JSON file to be created. Default is 'SettingsCoreMS.json'.
18
+ file_path : str or Path, optional
19
+ The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory.
20
+ """
21
+
22
+ data_dict_all = parameter_to_dict.get_dict_all_default_data()
23
+
24
+ if not file_path:
25
+ file_path = Path.cwd() / filename
26
+
27
+ with open(
28
+ file_path,
29
+ "w",
30
+ encoding="utf8",
31
+ ) as outfile:
32
+ import re
33
+
34
+ # pretty print
35
+ output = json.dumps(
36
+ data_dict_all, sort_keys=False, indent=4, separators=(",", ": ")
37
+ )
38
+ output = re.sub(r'",\s+', '", ', output)
39
+
40
+ outfile.write(output)
41
+
42
+
43
+ def dump_ms_settings_json(filename="SettingsCoreMS.json", file_path=None):
44
+ """
45
+ Write JSON file into current directory with all the mass spectrum default settings for the CoreMS package.
46
+
47
+ Parameters
48
+ ----------
49
+ filename : str, optional
50
+ The name of the JSON file to be created. Default is 'SettingsCoreMS.json'.
51
+ file_path : str or Path, optional
52
+ The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory.
53
+
54
+ """
55
+ data_dict = parameter_to_dict.get_dict_ms_default_data()
56
+ if not file_path:
57
+ file_path = Path.cwd() / filename
58
+
59
+ with open(
60
+ file_path,
61
+ "w",
62
+ encoding="utf8",
63
+ ) as outfile:
64
+ import re
65
+
66
+ # pretty print
67
+ output = json.dumps(
68
+ data_dict, sort_keys=False, indent=4, separators=(",", ": ")
69
+ )
70
+ output = re.sub(r'",\s+', '", ', output)
71
+
72
+ outfile.write(output)
73
+
74
+
75
+ def dump_gcms_settings_json(filename="SettingsCoreMS.json", file_path=None):
76
+ """
77
+ Write JSON file into current directory containing the default GCMS settings data.
78
+
79
+ Parameters
80
+ ----------
81
+ filename : str, optional
82
+ The name of the JSON file to be created. Default is 'SettingsCoreMS.json'.
83
+ file_path : str or Path-like object, optional
84
+ The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory.
85
+ """
86
+
87
+ from pathlib import Path
88
+ import json
89
+
90
+ data_dict = parameter_to_dict.get_dict_gcms_default_data()
91
+
92
+ if not file_path:
93
+ file_path = Path.cwd() / filename
94
+
95
+ with open(
96
+ file_path,
97
+ "w",
98
+ encoding="utf8",
99
+ ) as outfile:
100
+ import re
101
+
102
+ # pretty print
103
+ output = json.dumps(
104
+ data_dict, sort_keys=False, indent=4, separators=(",", ": ")
105
+ )
106
+ output = re.sub(r'",\s+', '", ', output)
107
+
108
+ outfile.write(output)
109
+
110
+
111
+ def dump_all_settings_toml(filename="SettingsCoreMS.toml", file_path=None):
112
+ """
113
+ Write TOML file into the specified file path or the current directory with all the default settings for the CoreMS package.
114
+
115
+ Parameters
116
+ ----------
117
+ filename : str, optional
118
+ The name of the TOML file. Defaults to 'SettingsCoreMS.toml'.
119
+ file_path : str or Path, optional
120
+ The path where the TOML file will be saved. If not provided, the file will be saved in the current directory.
121
+
122
+ """
123
+ from pathlib import Path
124
+
125
+ data_dict_all = parameter_to_dict.get_dict_all_default_data()
126
+
127
+ if not file_path:
128
+ file_path = Path.cwd() / filename
129
+
130
+ with open(
131
+ file_path,
132
+ "w",
133
+ encoding="utf8",
134
+ ) as outfile:
135
+ import re
136
+
137
+ output = toml.dumps(data_dict_all)
138
+ outfile.write(output)
139
+
140
+
141
+ def dump_ms_settings_toml(filename="SettingsCoreMS.toml", file_path=None):
142
+ """
143
+ Write TOML file into the current directory with all the mass spectrum default settings for the CoreMS package.
144
+
145
+ Parameters
146
+ ----------
147
+ filename : str, optional
148
+ The name of the TOML file to be created. Default is 'SettingsCoreMS.toml'.
149
+ file_path : str or Path, optional
150
+ The path where the TOML file should be saved. If not provided, the file will be saved in the current working directory.
151
+
152
+ """
153
+ data_dict = parameter_to_dict.get_dict_ms_default_data()
154
+
155
+ if not file_path:
156
+ file_path = Path.cwd() / filename
157
+
158
+ with open(
159
+ file_path,
160
+ "w",
161
+ encoding="utf8",
162
+ ) as outfile:
163
+ import re
164
+
165
+ # pretty print
166
+ output = toml.dumps(data_dict)
167
+ outfile.write(output)
168
+
169
+
170
+ def dump_gcms_settings_toml(filename="SettingsCoreMS.toml", file_path=None):
171
+ """
172
+ Write TOML file into current directory containing the default GCMS settings data.
173
+
174
+ Parameters
175
+ ----------
176
+ filename : str, optional
177
+ The name of the TOML file. Defaults to 'SettingsCoreMS.toml'.
178
+ file_path : str or Path, optional
179
+ The path where the TOML file will be saved. If not provided, the file will be saved in the current working directory.
180
+
181
+ """
182
+
183
+ data_dict = parameter_to_dict.get_dict_gcms_default_data()
184
+
185
+ if not file_path:
186
+ file_path = Path.cwd() / filename
187
+
188
+ with open(
189
+ file_path,
190
+ "w",
191
+ encoding="utf8",
192
+ ) as outfile:
193
+ output = toml.dumps(data_dict)
194
+ outfile.write(output)
195
+
196
+
197
+ def dump_lcms_settings_json(
198
+ filename="SettingsCoreMS.json", file_path=None, lcms_obj=None
199
+ ):
200
+ """
201
+ Write JSON file into current directory with all the LCMS settings data for the CoreMS package.
202
+
203
+ Parameters
204
+ ----------
205
+ filename : str, optional
206
+ The name of the JSON file. Defaults to 'SettingsCoreMS.json'.
207
+ file_path : str or Path, optional
208
+ The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory.
209
+ lcms_obj : object, optional
210
+ The LCMS object containing the settings data. If not provided, the settings data will be retrieved from the default settings.
211
+
212
+ """
213
+
214
+ if lcms_obj is None:
215
+ data_dict = parameter_to_dict.get_dict_lcms_default_data()
216
+ else:
217
+ data_dict = get_dict_data_lcms(lcms_obj)
218
+
219
+ if not file_path:
220
+ file_path = Path.cwd() / filename
221
+
222
+ with open(
223
+ file_path,
224
+ "w",
225
+ encoding="utf8",
226
+ ) as outfile:
227
+ outfile.write(json.dumps(data_dict, indent=4))
228
+
229
+
230
+ def dump_lcms_settings_toml(
231
+ filename="SettingsCoreMS.toml", file_path=None, lcms_obj=None
232
+ ):
233
+ """
234
+ Write TOML file into current directory with all the LCMS settings data for the CoreMS package.
235
+
236
+ Parameters
237
+ ----------
238
+ filename : str, optional
239
+ The name of the TOML file. Defaults to 'SettingsCoreMS.toml'.
240
+ file_path : str or Path, optional
241
+ The path where the TOML file will be saved. If not provided, the file will be saved in the current working directory.
242
+ lcms_obj : object, optional
243
+ The LCMS object containing the settings data. If not provided, the settings data will be retrieved from the default settings.
244
+
245
+ """
246
+
247
+ if lcms_obj is None:
248
+ data_dict = parameter_to_dict.get_dict_lcms_default_data()
249
+ else:
250
+ data_dict = get_dict_data_lcms(lcms_obj)
251
+
252
+ if not file_path:
253
+ file_path = Path.cwd() / filename
254
+
255
+ with open(
256
+ file_path,
257
+ "w",
258
+ encoding="utf8",
259
+ ) as outfile:
260
+ output = toml.dumps(data_dict)
261
+ outfile.write(output)
262
+
263
+
264
+ def dump_lcms_collection_settings_json(
265
+ filename="SettingsCoreMS.json", file_path=None, lcms_collection=None
266
+ ):
267
+ """Write JSON file with LCMS collection settings data.
268
+
269
+ Parameters
270
+ ----------
271
+ filename : str, optional
272
+ The name of the JSON file. Defaults to 'SettingsCoreMS.json'.
273
+ file_path : str or Path, optional
274
+ The path where the JSON file will be saved. If not provided, the file will be saved in the current working directory.
275
+ lcms_collection : LCMSCollection, optional
276
+ The LCMS collection object containing the settings data. If not provided, the settings data will be retrieved from the default settings.
277
+ """
278
+ from corems.encapsulation.output.parameter_to_dict import (
279
+ get_dict_data_lcms_collection,
280
+ get_dict_lcms_collection_default_data,
281
+ )
282
+
283
+ if lcms_collection is None:
284
+ data_dict = get_dict_lcms_collection_default_data()
285
+ else:
286
+ data_dict = get_dict_data_lcms_collection(lcms_collection)
287
+
288
+ if not file_path:
289
+ file_path = Path.cwd() / filename
290
+
291
+ with open(
292
+ file_path,
293
+ "w",
294
+ encoding="utf8",
295
+ ) as outfile:
296
+ outfile.write(json.dumps(data_dict, indent=4))
297
+
298
+
299
+ def dump_lcms_collection_settings_toml(
300
+ filename="SettingsCoreMS.toml", file_path=None, lcms_collection=None
301
+ ):
302
+ """Write TOML file with LCMS collection settings data.
303
+
304
+ Parameters
305
+ ----------
306
+ filename : str, optional
307
+ The name of the TOML file. Defaults to 'SettingsCoreMS.toml'.
308
+ file_path : str or Path, optional
309
+ The path where the TOML file will be saved. If not provided, the file will be saved in the current working directory.
310
+ lcms_collection : LCMSCollection, optional
311
+ The LCMS collection object containing the settings data. If not provided, the settings data will be retrieved from the default settings.
312
+ """
313
+ from corems.encapsulation.output.parameter_to_dict import (
314
+ get_dict_data_lcms_collection,
315
+ get_dict_lcms_collection_default_data,
316
+ )
317
+
318
+ if lcms_collection is None:
319
+ data_dict = get_dict_lcms_collection_default_data()
320
+ else:
321
+ data_dict = get_dict_data_lcms_collection(lcms_collection)
322
+
323
+ if not file_path:
324
+ file_path = Path.cwd() / filename
325
+
326
+ with open(
327
+ file_path,
328
+ "w",
329
+ encoding="utf8",
330
+ ) as outfile:
331
+ output = toml.dumps(data_dict)
332
+ outfile.write(output)
File without changes
@@ -0,0 +1,84 @@
1
+ __author__ = "Yuri E. Corilo"
2
+ __date__ = "Feb 13, 2020"
3
+
4
+ from pathlib import Path
5
+ import numpy as np
6
+ from pandas import Series
7
+
8
+ from corems.mass_spectra.calc import SignalProcessing as sp
9
+
10
+
11
+ class GC_Calculations:
12
+ def calibrate_ri(self, ref_dict, cal_file_path):
13
+ if not self:
14
+ self.process_chromatogram()
15
+
16
+ for gcms_peak in self:
17
+ gcms_peak.calc_ri(ref_dict)
18
+
19
+ self.ri_pairs_ref = ref_dict
20
+ if isinstance(cal_file_path, str):
21
+ # if obj is a string it defaults to create a Path obj, pass the S3Path if needed
22
+ self.cal_file_path = Path(cal_file_path)
23
+ else:
24
+ self.cal_file_path = cal_file_path
25
+
26
+ def smooth_tic(self, tic):
27
+ implemented_smooth_method = self.chromatogram_settings.implemented_smooth_method
28
+
29
+ pol_order = self.chromatogram_settings.savgol_pol_order
30
+
31
+ window_len = self.chromatogram_settings.smooth_window
32
+
33
+ window = self.chromatogram_settings.smooth_method
34
+
35
+ return sp.smooth_signal(
36
+ tic, window_len, window, pol_order, implemented_smooth_method
37
+ )
38
+
39
+ def centroid_detector(self, tic, rt):
40
+ noise_std = self.chromatogram_settings.std_noise_threshold
41
+
42
+ method = self.chromatogram_settings.noise_threshold_method
43
+
44
+ # peak picking
45
+ min_height = self.chromatogram_settings.peak_height_min_percent
46
+ min_datapoints = self.chromatogram_settings.min_peak_datapoints
47
+
48
+ # baseline detection
49
+ max_prominence = self.chromatogram_settings.peak_max_prominence_percent
50
+ max_height = self.chromatogram_settings.peak_height_max_percent
51
+
52
+ peak_indexes_generator = sp.peak_detector_generator(
53
+ tic,
54
+ noise_std,
55
+ method,
56
+ rt,
57
+ max_height,
58
+ min_height,
59
+ max_prominence,
60
+ min_datapoints,
61
+ )
62
+
63
+ return peak_indexes_generator
64
+
65
+ def remove_outliers(self, data):
66
+ from numpy import percentile
67
+
68
+ q25, q75 = percentile(data, 25), percentile(data, 75)
69
+ iqr = q75 - q25
70
+ if self.parameters.verbose_processing:
71
+ print("Percentiles: 25th=%.3f, 75th=%.3f, IQR=%.3f" % (q25, q75, iqr))
72
+ # calculate the outlier cutoff
73
+ cut_off = iqr * 1.5
74
+ lower, upper = q25 - cut_off, q75 + cut_off
75
+ # identify outliers
76
+ outliers = [x for x in data if x < lower or x > upper]
77
+ if self.parameters.verbose_processing:
78
+ print("Identified outliers: %d" % len(outliers))
79
+ # remove outliers
80
+ nanfilled_outliers = Series(
81
+ [x if lower <= x <= upper else np.nan for x in data]
82
+ )
83
+
84
+ return nanfilled_outliers