corems.encapsulation.input.parameter_from_json

  1from pathlib import Path
  2import json
  3import toml
  4
  5from corems.encapsulation.factory.parameters import MSParameters, LCMSParameters
  6from corems.encapsulation.factory.processingSetting import (
  7    MolecularFormulaSearchSettings,
  8    TransientSetting,
  9)
 10from corems.encapsulation.factory.processingSetting import (
 11    MassSpectrumSetting,
 12    DataInputSetting,
 13)
 14from corems.encapsulation.factory.processingSetting import MassSpecPeakSetting, GasChromatographSetting, CompoundSearchSettings, LCMSCollectionSettings
 15
 16
 17def 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
 53def 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
 88def 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
123def 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
158def 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
189def 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
220def _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
256def _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
325def _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
367def 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
414def 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
461def _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
500def 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
525def 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
550def _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]
def load_and_set_toml_parameters_ms(mass_spec_obj, parameters_path=False):
18def load_and_set_toml_parameters_ms(mass_spec_obj, parameters_path=False):
19    """Load parameters from a toml file and set the parameters in the mass_spec_obj
20
21    Parameters
22    ----------
23    mass_spec_obj : MassSpectrum
24        corems MassSpectrum object
25
26    parameters_path : str, optional
27        path to the parameters file, by default False
28
29    Raises
30    ------
31    FileNotFoundError
32        if the file is not found
33    """
34
35    if parameters_path:
36        file_path = Path(parameters_path)
37
38    else:
39        filename = "SettingsCoreMS.toml"
40        file_path = Path.cwd() / filename
41
42    if file_path.exists():
43        with open(
44            file_path,
45            "r",
46            encoding="utf8",
47        ) as stream:
48            data_loaded = toml.load(stream)
49            _set_dict_data_ms(data_loaded, mass_spec_obj)
50    else:
51        raise FileNotFoundError("Could not locate %s", file_path)

Load parameters from a toml file and set the parameters in the mass_spec_obj

Parameters
  • mass_spec_obj (MassSpectrum): corems MassSpectrum object
  • parameters_path (str, optional): path to the parameters file, by default False
Raises
  • FileNotFoundError: if the file is not found
def load_and_set_parameters_ms(mass_spec_obj, parameters_path=False):
54def load_and_set_parameters_ms(mass_spec_obj, parameters_path=False):
55    """Load parameters from a json file and set the parameters in the mass_spec_obj
56
57    Parameters
58    ----------
59    mass_spec_obj : MassSpectrum
60        corems MassSpectrum object
61    parameters_path : str, optional
62        path to the parameters file, by default False
63
64    Raises
65    ------
66    FileNotFoundError
67        if the file is not found
68    """
69
70    if parameters_path:
71        file_path = Path(parameters_path)
72
73    else:
74        filename = "SettingsCoreMS.json"
75        file_path = Path.cwd() / filename
76
77    if file_path.exists():
78        with open(
79            file_path,
80            "r",
81            encoding="utf8",
82        ) as stream:
83            data_loaded = json.load(stream)
84            _set_dict_data_ms(data_loaded, mass_spec_obj)
85    else:
86        raise FileNotFoundError("Could not locate %s", file_path)

Load parameters from a json file and set the parameters in the mass_spec_obj

Parameters
  • mass_spec_obj (MassSpectrum): corems MassSpectrum object
  • parameters_path (str, optional): path to the parameters file, by default False
Raises
  • FileNotFoundError: if the file is not found
def load_and_set_toml_parameters_gcms(gcms_obj, parameters_path=False):
 89def load_and_set_toml_parameters_gcms(gcms_obj, parameters_path=False):
 90    """Load parameters from a toml file and set the parameters in the GCMS object
 91
 92    Parameters
 93    ----------
 94    gcms_obj : GCMSBase
 95        corems GCMSBase object
 96    parameters_path : str, optional
 97        path to the parameters file, by default False
 98
 99    Raises
100    ------
101    FileNotFoundError
102        if the file is not found
103    """
104
105    if parameters_path:
106        file_path = Path(parameters_path)
107
108    else:
109        filename = "SettingsCoreMS.toml"
110        file_path = Path.cwd() / filename
111
112    if file_path.exists():
113        with open(
114            file_path,
115            "r",
116            encoding="utf8",
117        ) as stream:
118            data_loaded = toml.load(stream)
119            _set_dict_data_gcms(data_loaded, gcms_obj)
120    else:
121        raise FileNotFoundError("Could not locate %s", file_path)

Load parameters from a toml file and set the parameters in the GCMS object

Parameters
  • gcms_obj (GCMSBase): corems GCMSBase object
  • parameters_path (str, optional): path to the parameters file, by default False
Raises
  • FileNotFoundError: if the file is not found
def load_and_set_parameters_gcms(gcms_obj, parameters_path=False):
124def load_and_set_parameters_gcms(gcms_obj, parameters_path=False):
125    """Load parameters from a json file and set the parameters in the GCMS object
126
127    Parameters
128    ----------
129    gcms_obj : GCMSBase
130        corems GCMSBase object
131    parameters_path : str, optional
132        path to the parameters file, by default False
133
134    Raises
135    ------
136    FileNotFoundError
137        if the file is not found
138    """
139
140    if parameters_path:
141        file_path = Path(parameters_path)
142
143    else:
144        filename = "SettingsCoreMS.json"
145        file_path = Path.cwd() / filename
146
147    if file_path.exists():
148        with open(
149            file_path,
150            "r",
151            encoding="utf8",
152        ) as stream:
153            data_loaded = json.load(stream)
154            _set_dict_data_gcms(data_loaded, gcms_obj)
155    else:
156        raise FileNotFoundError("Could not locate %s", file_path)

Load parameters from a json file and set the parameters in the GCMS object

Parameters
  • gcms_obj (GCMSBase): corems GCMSBase object
  • parameters_path (str, optional): path to the parameters file, by default False
Raises
  • FileNotFoundError: if the file is not found
def load_and_set_json_parameters_lcms(lcms_obj, parameters_path=False):
159def load_and_set_json_parameters_lcms(lcms_obj, parameters_path=False):
160    """Load parameters from a json file and set the parameters in the LCMS object
161
162    Parameters
163    ----------
164    lcms_obj : LCMSBase
165        corems LCMSBase object
166    parameters_path : str
167        path to the parameters file saved as a .json, by default False
168
169    Raises
170    ------
171    FileNotFoundError
172        if the file is not found
173    """
174
175    if parameters_path:
176        file_path = Path(parameters_path)
177
178    if file_path.exists():
179        with open(
180            file_path,
181            "r",
182            encoding="utf8",
183        ) as stream:
184            data_loaded = json.load(stream)
185            _set_dict_data_lcms(data_loaded, lcms_obj)
186    else:
187        raise FileNotFoundError("Could not locate %s", file_path)

Load parameters from a json file and set the parameters in the LCMS object

Parameters
  • lcms_obj (LCMSBase): corems LCMSBase object
  • parameters_path (str): path to the parameters file saved as a .json, by default False
Raises
  • FileNotFoundError: if the file is not found
def load_and_set_toml_parameters_lcms(lcms_obj, parameters_path=False):
190def load_and_set_toml_parameters_lcms(lcms_obj, parameters_path=False):
191    """Load parameters from a toml file and set the parameters in the LCMS object
192
193    Parameters
194    ----------
195    lcms_obj : LCMSBase
196        corems LCMSBase object
197    parameters_path : str
198        path to the parameters file saved as a .toml, by default False
199
200    Raises
201    ------
202    FileNotFoundError
203        if the file is not found
204    """
205
206    if parameters_path:
207        file_path = Path(parameters_path)
208
209    if file_path.exists():
210        with open(
211            file_path,
212            "r",
213            encoding="utf8",
214        ) as stream:
215            data_loaded = toml.load(stream)
216            _set_dict_data_lcms(data_loaded, lcms_obj)
217    else:
218        raise FileNotFoundError("Could not locate %s", file_path)

Load parameters from a toml file and set the parameters in the LCMS object

Parameters
  • lcms_obj (LCMSBase): corems LCMSBase object
  • parameters_path (str): path to the parameters file saved as a .toml, by default False
Raises
  • FileNotFoundError: if the file is not found
def load_and_set_toml_parameters_class(parameter_label, instance_parameters_class, parameters_path=False):
368def load_and_set_toml_parameters_class(
369    parameter_label, instance_parameters_class, parameters_path=False
370):
371    """Load parameters from a toml file and set the parameters in the instance_parameters_class
372
373    Parameters
374    ----------
375    parameter_label : str
376        label of the parameters in the toml file
377    instance_parameters_class : object
378        instance of the parameters class
379    parameters_path : str, optional
380        path to the parameters file, by default False
381
382    Raises
383    ------
384    FileNotFoundError
385        if the file is not found
386
387    Returns
388    -------
389    object
390        instance of the parameters class
391    """
392
393    if parameters_path:
394        file_path = Path(parameters_path)
395
396    else:
397        file_path = Path.cwd() / "SettingsCoreMS.toml"
398
399    if file_path.exists():
400        with open(
401            file_path,
402            "r",
403            encoding="utf8",
404        ) as stream:
405            data_loaded = toml.load(stream)
406            parameter_class = _set_dict_data(
407                data_loaded, parameter_label, instance_parameters_class
408            )
409
410            return parameter_class
411    else:
412        raise FileNotFoundError("Could not locate %s", file_path)

Load parameters from a toml file and set the parameters in the instance_parameters_class

Parameters
  • parameter_label (str): label of the parameters in the toml file
  • instance_parameters_class (object): instance of the parameters class
  • parameters_path (str, optional): path to the parameters file, by default False
Raises
  • FileNotFoundError: if the file is not found
Returns
  • object: instance of the parameters class
def load_and_set_parameters_class(parameter_label, instance_parameters_class, parameters_path=False):
415def load_and_set_parameters_class(
416    parameter_label, instance_parameters_class, parameters_path=False
417):
418    """Load parameters from a json file and set the parameters in the instance_parameters_class
419
420    Parameters
421    ----------
422    parameter_label : str
423        label of the parameters in the json file
424    instance_parameters_class : object
425        instance of the parameters class
426    parameters_path : str, optional
427        path to the parameters file, by default False
428
429    Raises
430    ------
431    FileNotFoundError
432        if the file is not found
433
434    Returns
435    -------
436    object
437        instance of the parameters class
438    """
439
440    if parameters_path:
441        file_path = Path(parameters_path)
442
443    else:
444        file_path = Path.cwd() / "SettingsCoreMS.json"
445
446    if file_path.exists():
447        with open(
448            file_path,
449            "r",
450            encoding="utf8",
451        ) as stream:
452            data_loaded = json.load(stream)
453            parameter_class = _set_dict_data(
454                data_loaded, parameter_label, instance_parameters_class
455            )
456
457            return parameter_class
458    else:
459        raise FileNotFoundError("Could not locate %s", file_path)

Load parameters from a json file and set the parameters in the instance_parameters_class

Parameters
  • parameter_label (str): label of the parameters in the json file
  • instance_parameters_class (object): instance of the parameters class
  • parameters_path (str, optional): path to the parameters file, by default False
Raises
  • FileNotFoundError: if the file is not found
Returns
  • object: instance of the parameters class
def load_and_set_json_parameters_lcms_collection(lcms_collection, parameters_path):
501def load_and_set_json_parameters_lcms_collection(lcms_collection, parameters_path):
502    """Load parameters from a json file and set the parameters in the LCMS collection object
503
504    Parameters
505    ----------
506    lcms_collection : LCMSCollection
507        corems LCMSCollection object
508    parameters_path : str or Path
509        path to the parameters file saved as a .json
510
511    Raises
512    ------
513    FileNotFoundError
514        if the file is not found
515    """
516    file_path = Path(parameters_path)
517
518    if file_path.exists():
519        with open(file_path, "r", encoding="utf8") as stream:
520            data_loaded = json.load(stream)
521            _set_dict_data_lcms_collection(data_loaded, lcms_collection)
522    else:
523        raise FileNotFoundError(f"Could not locate {file_path}")

Load parameters from a json file and set the parameters in the LCMS collection object

Parameters
  • lcms_collection (LCMSCollection): corems LCMSCollection object
  • parameters_path (str or Path): path to the parameters file saved as a .json
Raises
  • FileNotFoundError: if the file is not found
def load_and_set_toml_parameters_lcms_collection(lcms_collection, parameters_path):
526def load_and_set_toml_parameters_lcms_collection(lcms_collection, parameters_path):
527    """Load parameters from a toml file and set the parameters in the LCMS collection object
528
529    Parameters
530    ----------
531    lcms_collection : LCMSCollection
532        corems LCMSCollection object
533    parameters_path : str or Path
534        path to the parameters file saved as a .toml
535
536    Raises
537    ------
538    FileNotFoundError
539        if the file is not found
540    """
541    file_path = Path(parameters_path)
542
543    if file_path.exists():
544        with open(file_path, "r", encoding="utf8") as stream:
545            data_loaded = toml.load(stream)
546            _set_dict_data_lcms_collection(data_loaded, lcms_collection)
547    else:
548        raise FileNotFoundError(f"Could not locate {file_path}")

Load parameters from a toml file and set the parameters in the LCMS collection object

Parameters
  • lcms_collection (LCMSCollection): corems LCMSCollection object
  • parameters_path (str or Path): path to the parameters file saved as a .toml
Raises
  • FileNotFoundError: if the file is not found