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
File without changes
@@ -0,0 +1,579 @@
1
+ from pathlib import Path
2
+ import json
3
+ import toml
4
+
5
+ from corems.encapsulation.factory.parameters import MSParameters, LCMSParameters
6
+ from corems.encapsulation.factory.processingSetting import (
7
+ MolecularFormulaSearchSettings,
8
+ TransientSetting,
9
+ )
10
+ from corems.encapsulation.factory.processingSetting import (
11
+ MassSpectrumSetting,
12
+ DataInputSetting,
13
+ )
14
+ from corems.encapsulation.factory.processingSetting import MassSpecPeakSetting, GasChromatographSetting, CompoundSearchSettings, LCMSCollectionSettings
15
+
16
+
17
+ def load_and_set_toml_parameters_ms(mass_spec_obj, parameters_path=False):
18
+ """Load parameters from a toml file and set the parameters in the mass_spec_obj
19
+
20
+ Parameters
21
+ ----------
22
+ mass_spec_obj : MassSpectrum
23
+ corems MassSpectrum object
24
+
25
+ parameters_path : str, optional
26
+ path to the parameters file, by default False
27
+
28
+ Raises
29
+ ------
30
+ FileNotFoundError
31
+ if the file is not found
32
+ """
33
+
34
+ if parameters_path:
35
+ file_path = Path(parameters_path)
36
+
37
+ else:
38
+ filename = "SettingsCoreMS.toml"
39
+ file_path = Path.cwd() / filename
40
+
41
+ if file_path.exists():
42
+ with open(
43
+ file_path,
44
+ "r",
45
+ encoding="utf8",
46
+ ) as stream:
47
+ data_loaded = toml.load(stream)
48
+ _set_dict_data_ms(data_loaded, mass_spec_obj)
49
+ else:
50
+ raise FileNotFoundError("Could not locate %s", file_path)
51
+
52
+
53
+ def load_and_set_parameters_ms(mass_spec_obj, parameters_path=False):
54
+ """Load parameters from a json file and set the parameters in the mass_spec_obj
55
+
56
+ Parameters
57
+ ----------
58
+ mass_spec_obj : MassSpectrum
59
+ corems MassSpectrum object
60
+ parameters_path : str, optional
61
+ path to the parameters file, by default False
62
+
63
+ Raises
64
+ ------
65
+ FileNotFoundError
66
+ if the file is not found
67
+ """
68
+
69
+ if parameters_path:
70
+ file_path = Path(parameters_path)
71
+
72
+ else:
73
+ filename = "SettingsCoreMS.json"
74
+ file_path = Path.cwd() / filename
75
+
76
+ if file_path.exists():
77
+ with open(
78
+ file_path,
79
+ "r",
80
+ encoding="utf8",
81
+ ) as stream:
82
+ data_loaded = json.load(stream)
83
+ _set_dict_data_ms(data_loaded, mass_spec_obj)
84
+ else:
85
+ raise FileNotFoundError("Could not locate %s", file_path)
86
+
87
+
88
+ def load_and_set_toml_parameters_gcms(gcms_obj, parameters_path=False):
89
+ """Load parameters from a toml file and set the parameters in the GCMS object
90
+
91
+ Parameters
92
+ ----------
93
+ gcms_obj : GCMSBase
94
+ corems GCMSBase object
95
+ parameters_path : str, optional
96
+ path to the parameters file, by default False
97
+
98
+ Raises
99
+ ------
100
+ FileNotFoundError
101
+ if the file is not found
102
+ """
103
+
104
+ if parameters_path:
105
+ file_path = Path(parameters_path)
106
+
107
+ else:
108
+ filename = "SettingsCoreMS.toml"
109
+ file_path = Path.cwd() / filename
110
+
111
+ if file_path.exists():
112
+ with open(
113
+ file_path,
114
+ "r",
115
+ encoding="utf8",
116
+ ) as stream:
117
+ data_loaded = toml.load(stream)
118
+ _set_dict_data_gcms(data_loaded, gcms_obj)
119
+ else:
120
+ raise FileNotFoundError("Could not locate %s", file_path)
121
+
122
+
123
+ def load_and_set_parameters_gcms(gcms_obj, parameters_path=False):
124
+ """Load parameters from a json file and set the parameters in the GCMS object
125
+
126
+ Parameters
127
+ ----------
128
+ gcms_obj : GCMSBase
129
+ corems GCMSBase object
130
+ parameters_path : str, optional
131
+ path to the parameters file, by default False
132
+
133
+ Raises
134
+ ------
135
+ FileNotFoundError
136
+ if the file is not found
137
+ """
138
+
139
+ if parameters_path:
140
+ file_path = Path(parameters_path)
141
+
142
+ else:
143
+ filename = "SettingsCoreMS.json"
144
+ file_path = Path.cwd() / filename
145
+
146
+ if file_path.exists():
147
+ with open(
148
+ file_path,
149
+ "r",
150
+ encoding="utf8",
151
+ ) as stream:
152
+ data_loaded = json.load(stream)
153
+ _set_dict_data_gcms(data_loaded, gcms_obj)
154
+ else:
155
+ raise FileNotFoundError("Could not locate %s", file_path)
156
+
157
+
158
+ def load_and_set_json_parameters_lcms(lcms_obj, parameters_path=False):
159
+ """Load parameters from a json file and set the parameters in the LCMS object
160
+
161
+ Parameters
162
+ ----------
163
+ lcms_obj : LCMSBase
164
+ corems LCMSBase object
165
+ parameters_path : str
166
+ path to the parameters file saved as a .json, by default False
167
+
168
+ Raises
169
+ ------
170
+ FileNotFoundError
171
+ if the file is not found
172
+ """
173
+
174
+ if parameters_path:
175
+ file_path = Path(parameters_path)
176
+
177
+ if file_path.exists():
178
+ with open(
179
+ file_path,
180
+ "r",
181
+ encoding="utf8",
182
+ ) as stream:
183
+ data_loaded = json.load(stream)
184
+ _set_dict_data_lcms(data_loaded, lcms_obj)
185
+ else:
186
+ raise FileNotFoundError("Could not locate %s", file_path)
187
+
188
+
189
+ def load_and_set_toml_parameters_lcms(lcms_obj, parameters_path=False):
190
+ """Load parameters from a toml file and set the parameters in the LCMS object
191
+
192
+ Parameters
193
+ ----------
194
+ lcms_obj : LCMSBase
195
+ corems LCMSBase object
196
+ parameters_path : str
197
+ path to the parameters file saved as a .toml, by default False
198
+
199
+ Raises
200
+ ------
201
+ FileNotFoundError
202
+ if the file is not found
203
+ """
204
+
205
+ if parameters_path:
206
+ file_path = Path(parameters_path)
207
+
208
+ if file_path.exists():
209
+ with open(
210
+ file_path,
211
+ "r",
212
+ encoding="utf8",
213
+ ) as stream:
214
+ data_loaded = toml.load(stream)
215
+ _set_dict_data_lcms(data_loaded, lcms_obj)
216
+ else:
217
+ raise FileNotFoundError("Could not locate %s", file_path)
218
+
219
+
220
+ def _set_dict_data_gcms(data_loaded, gcms_obj):
221
+ """Set the parameters in the GCMS object from a dict
222
+
223
+ This function is called by load_and_set_parameters_gcms and load_and_set_toml_parameters_gcms and should not be called directly.
224
+
225
+ Parameters
226
+ ----------
227
+ data_loaded : dict
228
+ dict with the parameters
229
+ gcms_obj : GCMSBase
230
+ corems GCMSBase object
231
+ """
232
+
233
+ classes = [
234
+ GasChromatographSetting(),
235
+ CompoundSearchSettings(),
236
+ ]
237
+
238
+ labels = ["GasChromatograph", "MolecularSearch"]
239
+
240
+ label_class = zip(labels, classes)
241
+
242
+ if data_loaded:
243
+ for label, classe in label_class:
244
+ class_data = data_loaded.get(label)
245
+ # not always we will not all the settings
246
+ # this allow a class data to be none and continue
247
+ # to import the other classes
248
+ if class_data:
249
+ for item, value in class_data.items():
250
+ setattr(classe, item, value)
251
+
252
+ gcms_obj.chromatogram_settings = classes[0]
253
+ gcms_obj.molecular_search_settings = classes[1]
254
+
255
+
256
+ def _set_dict_data_lcms(data_loaded, lcms_obj):
257
+ """Set the parameters on a LCMS object from a dict
258
+
259
+ This function is called by load_and_set_parameters_lcms and load_and_set_toml_parameters_lcms and should not be called directly.
260
+
261
+ Parameters
262
+ ----------
263
+ data_loaded : dict
264
+ dict with the parameters
265
+ lcms_obj : LCMSBase
266
+ corems LCMSBase object
267
+ """
268
+
269
+ # Load the lcms parameters
270
+ default_params = LCMSParameters(use_defaults=True)
271
+ lcms_params = data_loaded.get("LiquidChromatograph")
272
+ for item, value in lcms_params.items():
273
+ # If the original value is a tuple but the new one is a list we need to convert the list to a tuple
274
+ if isinstance(value, list) and isinstance(
275
+ getattr(default_params.lc_ms, item), tuple
276
+ ):
277
+ setattr(lcms_obj.parameters.lc_ms, item, tuple(value))
278
+ else:
279
+ setattr(lcms_obj.parameters.lc_ms, item, value)
280
+
281
+ def set_ms_params_by_key(ms_key):
282
+ classes = [
283
+ MassSpectrumSetting,
284
+ MassSpecPeakSetting,
285
+ MolecularFormulaSearchSettings,
286
+ DataInputSetting,
287
+ TransientSetting,
288
+ ]
289
+
290
+ labels = [
291
+ "mass_spectrum",
292
+ "ms_peak",
293
+ "molecular_search",
294
+ "data_input",
295
+ "transient",
296
+ ]
297
+
298
+ label_class = zip(labels, classes)
299
+
300
+ for label, classe in label_class:
301
+ class_data = data_loaded.get("mass_spectrum").get(ms_key).get(label)
302
+ param_instance = classe()
303
+ if class_data is not None:
304
+ # Set the attributes of the nested class
305
+ for item, value in class_data.items():
306
+ if item == "usedAtoms":
307
+ # Convert the lists to tuples
308
+ for atom, atom_value in value.items():
309
+ value[atom] = tuple(atom_value)
310
+ if isinstance(value, list) and isinstance(
311
+ getattr(param_instance, item), tuple
312
+ ):
313
+ setattr(param_instance, item, tuple(value))
314
+ else:
315
+ setattr(param_instance, item, value)
316
+ setattr(lcms_obj.parameters.mass_spectrum[ms_key], label, param_instance)
317
+
318
+ # Load the mass spectrum parameters
319
+ ms_keys = data_loaded["mass_spectrum"].keys()
320
+ for ms_key in ms_keys:
321
+ lcms_obj.parameters.mass_spectrum[ms_key] = MSParameters()
322
+ set_ms_params_by_key(ms_key)
323
+
324
+
325
+ def _set_dict_data_ms(data_loaded, mass_spec_obj):
326
+ """Set the parameters in the MassSpectrum object from a dict
327
+
328
+ This function is called by load_and_set_parameters_ms and load_and_set_toml_parameters_ms and should not be called directly.
329
+
330
+ Parameters
331
+ ----------
332
+ data_loaded : dict
333
+ dict with the parameters
334
+ mass_spec_obj : MassSpectrum
335
+ corems MassSpectrum object
336
+ """
337
+
338
+ from copy import deepcopy
339
+
340
+ classes = [
341
+ MolecularFormulaSearchSettings(),
342
+ TransientSetting(),
343
+ MassSpectrumSetting(),
344
+ MassSpecPeakSetting(),
345
+ ]
346
+
347
+ labels = ["MolecularFormulaSearch", "Transient", "MassSpectrum", "MassSpecPeak"]
348
+
349
+ label_class = zip(labels, classes)
350
+
351
+ if data_loaded:
352
+ for label, classe in label_class:
353
+ class_data = data_loaded.get(label)
354
+ # not always we will have all the settings classes
355
+ # this allow a class data to be none and continue
356
+ # to import the other classes
357
+ if class_data:
358
+ for item, value in class_data.items():
359
+ setattr(classe, item, value)
360
+
361
+ mass_spec_obj.molecular_search_settings = classes[0]
362
+ mass_spec_obj.transient_settings = classes[1]
363
+ mass_spec_obj.settings = classes[2]
364
+ mass_spec_obj.mspeaks_settings = classes[3]
365
+
366
+
367
+ def load_and_set_toml_parameters_class(
368
+ parameter_label, instance_parameters_class, parameters_path=False
369
+ ):
370
+ """Load parameters from a toml file and set the parameters in the instance_parameters_class
371
+
372
+ Parameters
373
+ ----------
374
+ parameter_label : str
375
+ label of the parameters in the toml file
376
+ instance_parameters_class : object
377
+ instance of the parameters class
378
+ parameters_path : str, optional
379
+ path to the parameters file, by default False
380
+
381
+ Raises
382
+ ------
383
+ FileNotFoundError
384
+ if the file is not found
385
+
386
+ Returns
387
+ -------
388
+ object
389
+ instance of the parameters class
390
+ """
391
+
392
+ if parameters_path:
393
+ file_path = Path(parameters_path)
394
+
395
+ else:
396
+ file_path = Path.cwd() / "SettingsCoreMS.toml"
397
+
398
+ if file_path.exists():
399
+ with open(
400
+ file_path,
401
+ "r",
402
+ encoding="utf8",
403
+ ) as stream:
404
+ data_loaded = toml.load(stream)
405
+ parameter_class = _set_dict_data(
406
+ data_loaded, parameter_label, instance_parameters_class
407
+ )
408
+
409
+ return parameter_class
410
+ else:
411
+ raise FileNotFoundError("Could not locate %s", file_path)
412
+
413
+
414
+ def load_and_set_parameters_class(
415
+ parameter_label, instance_parameters_class, parameters_path=False
416
+ ):
417
+ """Load parameters from a json file and set the parameters in the instance_parameters_class
418
+
419
+ Parameters
420
+ ----------
421
+ parameter_label : str
422
+ label of the parameters in the json file
423
+ instance_parameters_class : object
424
+ instance of the parameters class
425
+ parameters_path : str, optional
426
+ path to the parameters file, by default False
427
+
428
+ Raises
429
+ ------
430
+ FileNotFoundError
431
+ if the file is not found
432
+
433
+ Returns
434
+ -------
435
+ object
436
+ instance of the parameters class
437
+ """
438
+
439
+ if parameters_path:
440
+ file_path = Path(parameters_path)
441
+
442
+ else:
443
+ file_path = Path.cwd() / "SettingsCoreMS.json"
444
+
445
+ if file_path.exists():
446
+ with open(
447
+ file_path,
448
+ "r",
449
+ encoding="utf8",
450
+ ) as stream:
451
+ data_loaded = json.load(stream)
452
+ parameter_class = _set_dict_data(
453
+ data_loaded, parameter_label, instance_parameters_class
454
+ )
455
+
456
+ return parameter_class
457
+ else:
458
+ raise FileNotFoundError("Could not locate %s", file_path)
459
+
460
+
461
+ def _set_dict_data(data_loaded, parameter_label, instance_ParameterClass):
462
+ """Set the parameters in an instance of a parameter class from a dict
463
+
464
+ This function is called by load_and_set_parameters_class and load_and_set_toml_parameters_class and should not be called directly.
465
+
466
+ Parameters
467
+ ----------
468
+ data_loaded : dict
469
+ dict with the parameters
470
+ parameter_label : str
471
+ label of the parameters in the json file
472
+ instance_ParameterClass : object
473
+ instance of the parameters class
474
+
475
+ Returns
476
+ -------
477
+ object
478
+ instance of the parameters class
479
+ """
480
+
481
+ classes = [instance_ParameterClass]
482
+
483
+ labels = [parameter_label]
484
+
485
+ label_class = zip(labels, classes)
486
+
487
+ if data_loaded:
488
+ for label, classe in label_class:
489
+ class_data = data_loaded.get(label)
490
+ # not always we will have all the settings classes
491
+ # this allow a class data to be none and continue
492
+ # to import the other classes
493
+ if class_data:
494
+ for item, value in class_data.items():
495
+ setattr(classe, item, value)
496
+
497
+ return classes[0]
498
+
499
+
500
+ def load_and_set_json_parameters_lcms_collection(lcms_collection, parameters_path):
501
+ """Load parameters from a json file and set the parameters in the LCMS collection object
502
+
503
+ Parameters
504
+ ----------
505
+ lcms_collection : LCMSCollection
506
+ corems LCMSCollection object
507
+ parameters_path : str or Path
508
+ path to the parameters file saved as a .json
509
+
510
+ Raises
511
+ ------
512
+ FileNotFoundError
513
+ if the file is not found
514
+ """
515
+ file_path = Path(parameters_path)
516
+
517
+ if file_path.exists():
518
+ with open(file_path, "r", encoding="utf8") as stream:
519
+ data_loaded = json.load(stream)
520
+ _set_dict_data_lcms_collection(data_loaded, lcms_collection)
521
+ else:
522
+ raise FileNotFoundError(f"Could not locate {file_path}")
523
+
524
+
525
+ def load_and_set_toml_parameters_lcms_collection(lcms_collection, parameters_path):
526
+ """Load parameters from a toml file and set the parameters in the LCMS collection object
527
+
528
+ Parameters
529
+ ----------
530
+ lcms_collection : LCMSCollection
531
+ corems LCMSCollection object
532
+ parameters_path : str or Path
533
+ path to the parameters file saved as a .toml
534
+
535
+ Raises
536
+ ------
537
+ FileNotFoundError
538
+ if the file is not found
539
+ """
540
+ file_path = Path(parameters_path)
541
+
542
+ if file_path.exists():
543
+ with open(file_path, "r", encoding="utf8") as stream:
544
+ data_loaded = toml.load(stream)
545
+ _set_dict_data_lcms_collection(data_loaded, lcms_collection)
546
+ else:
547
+ raise FileNotFoundError(f"Could not locate {file_path}")
548
+
549
+
550
+ def _set_dict_data_lcms_collection(data_loaded, lcms_collection):
551
+ """Set the parameters in the LCMS collection object from a dict
552
+
553
+ This function is called by load_and_set_json_parameters_lcms_collection and
554
+ load_and_set_toml_parameters_lcms_collection and should not be called directly.
555
+
556
+ Parameters
557
+ ----------
558
+ data_loaded : dict
559
+ dict with the parameters
560
+ lcms_collection : LCMSCollection
561
+ corems LCMSCollection object
562
+ """
563
+ classes = [LCMSCollectionSettings()]
564
+ labels = ["LCMSCollection"]
565
+
566
+ label_class = zip(labels, classes)
567
+
568
+ if data_loaded:
569
+ for label, classe in label_class:
570
+ class_data = data_loaded.get(label)
571
+ # not always we will have all the settings
572
+ # this allows a class data to be none and continue
573
+ # to import the other classes
574
+ if class_data:
575
+ for attr, value in class_data.items():
576
+ if hasattr(classe, attr):
577
+ setattr(classe, attr, value)
578
+
579
+ lcms_collection.parameters.lcms_collection = classes[0]
File without changes