corems.encapsulation.factory.parameters

  1import dataclasses
  2
  3from corems.encapsulation.factory.processingSetting import (
  4    LiquidChromatographSetting,
  5    MolecularFormulaSearchSettings,
  6    TransientSetting,
  7    MassSpecPeakSetting,
  8    MassSpectrumSetting,
  9    LCMSCollectionSettings,
 10    SpectralSimilaritySearchSettings,
 11)
 12from corems.encapsulation.factory.processingSetting import (
 13    CompoundSearchSettings,
 14    GasChromatographSetting,
 15)
 16from corems.encapsulation.factory.processingSetting import DataInputSetting
 17
 18
 19def hush_output():
 20    """Toggle all the verbose_processing flags to False on the MSParameters, GCMSParameters and LCMSParameters classes"""
 21    MSParameters.molecular_search.verbose_processing = False
 22    MSParameters.mass_spectrum.verbose_processing = False
 23    GCMSParameters.gc_ms.verbose_processing = False
 24    LCMSParameters.lc_ms.verbose_processing = False
 25
 26
 27def reset_ms_parameters():
 28    """Reset the MSParameter class to the default values"""
 29    MSParameters.molecular_search = MolecularFormulaSearchSettings()
 30    MSParameters.transient = TransientSetting()
 31    MSParameters.mass_spectrum = MassSpectrumSetting()
 32    MSParameters.ms_peak = MassSpecPeakSetting()
 33    MSParameters.data_input = DataInputSetting()
 34    MSParameters.spectral_similarity_search = SpectralSimilaritySearchSettings()
 35
 36
 37def reset_gcms_parameters():
 38    """Reset the GCMSParameters class to the default values"""
 39    GCMSParameters.molecular_search = CompoundSearchSettings()
 40    GCMSParameters.gc_ms = GasChromatographSetting()
 41
 42
 43def reset_lcms_parameters():
 44    """Reset the LCMSParameters class to the default values"""
 45    reset_ms_parameters()
 46    LCMSParameters.lc_ms = LiquidChromatographSetting()
 47    LCMSParameters.mass_spectrum = {
 48        "ms1": MSParameters(use_defaults=True),
 49        "ms2": MSParameters(use_defaults=True),
 50    }
 51
 52
 53def settings_from_lcms(
 54    lcms_obj, profile: str = "ms2"
 55) -> SpectralSimilaritySearchSettings:
 56    """Return spectral similarity search settings for an LCMS object profile key.
 57
 58    Parameters
 59    ----------
 60    lcms_obj
 61        Object with ``parameters.mass_spectrum`` (e.g. LCMSBase).
 62    profile : str, optional
 63        Key in ``parameters.mass_spectrum`` (default ``"ms2"``).
 64
 65    Returns
 66    -------
 67    SpectralSimilaritySearchSettings
 68        Live reference on that LCMS object (mutations affect only this sample).
 69    """
 70    return lcms_obj.parameters.mass_spectrum[profile].spectral_similarity_search
 71
 72
 73def settings_from_lcms_collection(
 74    lcms_collection, profile: str = "ms2"
 75) -> SpectralSimilaritySearchSettings:
 76    """Return spectral similarity settings from the **first** sample in a collection.
 77
 78    This is a read convenience for library build when all samples already share
 79    the same settings.  Mutating the returned object updates **only the first
 80    sample**.  To change settings for every sample (and keep them equal for a
 81    later re-instantiation of the collection), configure a settings instance
 82    then call :func:`apply_spectral_similarity_search_to_collection`.
 83
 84    Parameters
 85    ----------
 86    lcms_collection
 87        Sequence of LCMS objects (e.g. LCMSCollection).
 88    profile : str, optional
 89        Key in ``parameters.mass_spectrum`` (default ``"ms2"``).
 90
 91    Returns
 92    -------
 93    SpectralSimilaritySearchSettings
 94    """
 95    first = lcms_collection[0]
 96    return settings_from_lcms(first, profile=profile)
 97
 98
 99def apply_spectral_similarity_search_to_collection(
100    lcms_collection,
101    settings: SpectralSimilaritySearchSettings,
102    profile: str = "ms2",
103) -> None:
104    """Copy *settings* onto every LCMS sample's ``mass_spectrum[profile]`` bag.
105
106    Use this after configuring spectral similarity / networking knobs so all
107    members of a collection stay aligned (collection workflows assume shared
108    processing parameters).
109
110    Parameters
111    ----------
112    lcms_collection
113        Sequence of LCMS objects (e.g. LCMSCollection).
114    settings : SpectralSimilaritySearchSettings
115        Settings to broadcast.  Each sample receives ``settings.copy()`` so
116        later per-sample mutations do not cross-link.
117    profile : str, optional
118        Key in ``parameters.mass_spectrum`` (default ``"ms2"``).
119    """
120    for sample in lcms_collection:
121        if profile not in sample.parameters.mass_spectrum:
122            raise KeyError(
123                f"profile={profile!r} not in sample parameters.mass_spectrum "
124                f"(keys={list(sample.parameters.mass_spectrum)})"
125            )
126        sample.parameters.mass_spectrum[
127            profile
128        ].spectral_similarity_search = settings.copy()
129
130
131class MSParameters:
132    """MSParameters class is used to store the parameters used for the processing of the mass spectrum
133
134    Each attibute is a class that contains the parameters for the processing of the mass spectrum, see the corems.encapsulation.factory.processingSetting module for more details.
135
136    Parameters
137    ----------
138    use_defaults: bool, optional
139        if True, the class will be instantiated with the default values, otherwise the current values will be used. Default is False.
140
141    Attributes
142    -----------
143    molecular_search: MolecularFormulaSearchSettings
144        MolecularFormulaSearchSettings object
145    transient: TransientSetting
146        TransientSetting object
147    mass_spectrum: MassSpectrumSetting
148        MassSpectrumSetting object
149    ms_peak: MassSpecPeakSetting
150        MassSpecPeakSetting object
151    data_input: DataInputSetting
152        DataInputSetting object
153    spectral_similarity_search: SpectralSimilaritySearchSettings
154        Spectral similarity library search and molecular networking settings
155        (not molecular formula search). Used for LCMS MS2 profiles; present
156        but typically unused on MS1 mass spectrum parameters.
157
158    Notes
159    -----
160    One can use the use_defaults parameter to reset the parameters to the default values.
161    Alternatively, to use the current values - modify the class's contents before instantiating the class.
162    """
163
164    molecular_search = MolecularFormulaSearchSettings()
165    transient = TransientSetting()
166    mass_spectrum = MassSpectrumSetting()
167    ms_peak = MassSpecPeakSetting()
168    data_input = DataInputSetting()
169    spectral_similarity_search = SpectralSimilaritySearchSettings()
170
171    def __init__(self, use_defaults=False) -> None:
172        if not use_defaults:
173            self.molecular_search = dataclasses.replace(MSParameters.molecular_search)
174            self.transient = dataclasses.replace(MSParameters.transient)
175            self.mass_spectrum = dataclasses.replace(MSParameters.mass_spectrum)
176            self.ms_peak = dataclasses.replace(MSParameters.ms_peak)
177            self.data_input = dataclasses.replace(MSParameters.data_input)
178            self.spectral_similarity_search = (
179                MSParameters.spectral_similarity_search.copy()
180            )
181        else:
182            self.molecular_search = MolecularFormulaSearchSettings()
183            self.transient = TransientSetting()
184            self.mass_spectrum = MassSpectrumSetting()
185            self.ms_peak = MassSpecPeakSetting()
186            self.data_input = DataInputSetting()
187            self.spectral_similarity_search = SpectralSimilaritySearchSettings()
188
189    def copy(self):
190        """Create a copy of the MSParameters object"""
191        new_ms_parameters = MSParameters()
192        new_ms_parameters.molecular_search = dataclasses.replace(self.molecular_search)
193        new_ms_parameters.transient = dataclasses.replace(self.transient)
194        new_ms_parameters.mass_spectrum = dataclasses.replace(self.mass_spectrum)
195        new_ms_parameters.ms_peak = dataclasses.replace(self.ms_peak)
196        new_ms_parameters.data_input = dataclasses.replace(self.data_input)
197        new_ms_parameters.spectral_similarity_search = (
198            self.spectral_similarity_search.copy()
199        )
200
201        return new_ms_parameters
202
203    def print(self):
204        """Print the MSParameters object"""
205        for k, v in self.__dict__.items():
206            print(k, type(v).__name__)
207
208            for k2, v2 in v.__dict__.items():
209                print("    {}: {}".format(k2, v2))
210
211    def __eq__(self, value: object) -> bool:
212        # Check that the object is of the same type
213        if not isinstance(value, MSParameters):
214            return False
215        equality_check = []
216        equality_check.append(self.molecular_search == value.molecular_search)
217        equality_check.append(self.transient == value.transient)
218        equality_check.append(self.mass_spectrum == value.mass_spectrum)
219        equality_check.append(self.ms_peak == value.ms_peak)
220        equality_check.append(self.data_input == value.data_input)
221        equality_check.append(
222            self.spectral_similarity_search == value.spectral_similarity_search
223        )
224
225        return all(equality_check)
226
227
228class GCMSParameters:
229    """GCMSParameters class is used to store the parameters used for the processing of the gas chromatograph mass spectrum
230
231    Each attibute is a class that contains the parameters for the processing of the data, see the corems.encapsulation.factory.processingSetting module for more details.
232
233    Parameters
234    ----------
235    use_defaults: bool, optional
236        if True, the class will be instantiated with the default values, otherwise the current values will be used. Default is False.
237
238    Attributes
239    -----------
240    molecular_search: MolecularFormulaSearchSettings
241        MolecularFormulaSearchSettings object
242    gc_ms: GasChromatographSetting
243        GasChromatographSetting object
244
245    Notes
246    -----
247    One can use the use_defaults parameter to reset the parameters to the default values.
248    Alternatively, to use the current values - modify the class's contents before instantiating the class.
249    """
250
251    molecular_search = CompoundSearchSettings()
252    gc_ms = GasChromatographSetting()
253
254    def __init__(self, use_defaults=False) -> None:
255        if not use_defaults:
256            self.molecular_search = dataclasses.replace(GCMSParameters.molecular_search)
257            self.gc_ms = dataclasses.replace(GCMSParameters.gc_ms)
258        else:
259            self.molecular_search = CompoundSearchSettings()
260            self.gc_ms = GasChromatographSetting()
261
262    def copy(self):
263        """Create a copy of the GCMSParameters object"""
264        new_gcms_parameters = GCMSParameters()
265        new_gcms_parameters.molecular_search = dataclasses.replace(
266            self.molecular_search
267        )
268        new_gcms_parameters.gc_ms = dataclasses.replace(self.gc_ms)
269
270        return new_gcms_parameters
271
272    def __eq__(self, value: object) -> bool:
273        # Check that the object is of the same type
274        if not isinstance(value, GCMSParameters):
275            return False
276        equality_check = []
277        equality_check.append(self.molecular_search == value.molecular_search)
278        equality_check.append(self.gc_ms == value.gc_ms)
279
280        return all(equality_check)
281
282    def print(self):
283        """Print the GCMSParameters object"""
284        for k, v in self.__dict__.items():
285            print(k, type(v).__name__)
286
287            for k2, v2 in v.__dict__.items():
288                print("    {}: {}".format(k2, v2))
289
290
291class LCMSParameters:
292    """LCMSParameters class is used to store the parameters used for the processing of the liquid chromatograph mass spectrum
293
294    Each attibute is a class that contains the parameters for the processing of the data, see the corems.encapsulation.factory.processingSetting module for more details.
295
296    Parameters
297    ----------
298    use_defaults: bool, optional
299        if True, the class will be instantiated with the default values, otherwise the current values will be used. Default is False.
300
301    Attributes
302    -----------
303    lc_ms: LiquidChromatographSetting
304        LiquidChromatographSetting object
305    mass_spectrum: dict
306        dictionary with the mass spectrum parameters for ms1 and ms2, each value is a MSParameters object
307        (includes ``spectral_similarity_search`` on each bag; use ``mass_spectrum["ms2"].spectral_similarity_search`` by default)
308
309    Notes
310    -----
311    One can use the use_defaults parameter to reset the parameters to the default values.
312    Alternatively, to use the current values - modify the class's contents before instantiating the class.
313
314    Annotation fields on ``lc_ms`` (``ms2_min_fe_score``, etc.) are legacy aliases;
315    prefer ``mass_spectrum["ms2"].spectral_similarity_search``. Use
316    :meth:`sync_ms2_annotation_from_lc_ms` / :meth:`sync_ms2_annotation_to_lc_ms`.
317    """
318
319    lc_ms = LiquidChromatographSetting()
320    mass_spectrum = {"ms1": MSParameters(), "ms2": MSParameters()}
321
322    def __init__(self, use_defaults=False) -> None:
323        if not use_defaults:
324            self.lc_ms = dataclasses.replace(LCMSParameters.lc_ms)
325            self.mass_spectrum = {
326                "ms1": MSParameters(use_defaults=False),
327                "ms2": MSParameters(use_defaults=False),
328            }
329        else:
330            self.lc_ms = LiquidChromatographSetting()
331            self.mass_spectrum = {
332                "ms1": MSParameters(use_defaults=True),
333                "ms2": MSParameters(use_defaults=True),
334            }
335        self.sync_ms2_annotation_from_lc_ms()
336
337    def sync_ms2_annotation_from_lc_ms(self, profile: str = "ms2") -> None:
338        """Copy legacy ``lc_ms`` annotation fields into ``mass_spectrum[profile].spectral_similarity_search``."""
339        if profile not in self.mass_spectrum:
340            return
341        dest = self.mass_spectrum[profile].spectral_similarity_search
342        dest.ms2_min_fe_score = self.lc_ms.ms2_min_fe_score
343        dest.search_as_lipids = self.lc_ms.search_as_lipids
344        dest.include_fragment_types = self.lc_ms.include_fragment_types
345
346    def sync_ms2_annotation_to_lc_ms(self, profile: str = "ms2") -> None:
347        """Copy ``mass_spectrum[profile].spectral_similarity_search`` annotation fields into legacy ``lc_ms``."""
348        if profile not in self.mass_spectrum:
349            return
350        src = self.mass_spectrum[profile].spectral_similarity_search
351        self.lc_ms.ms2_min_fe_score = src.ms2_min_fe_score
352        self.lc_ms.search_as_lipids = src.search_as_lipids
353        self.lc_ms.include_fragment_types = src.include_fragment_types
354
355    def copy(self):
356        """Create a copy of the LCMSParameters object"""
357        new_lcms_parameters = LCMSParameters()
358        new_lcms_parameters.lc_ms = dataclasses.replace(self.lc_ms)
359        for key in self.mass_spectrum:
360            new_lcms_parameters.mass_spectrum[key] = self.mass_spectrum[key].copy()
361
362        return new_lcms_parameters
363
364    def __eq__(self, value: object) -> bool:
365        # Check that the object is of the same type
366        if not isinstance(value, LCMSParameters):
367            return False
368        equality_check = []
369        equality_check.append(self.lc_ms == value.lc_ms)
370
371        # Check that the mass_spectrum dictionary has the same keys
372        equality_check.append(self.mass_spectrum.keys() == value.mass_spectrum.keys())
373
374        # Check that the values of the mass_spectrum dictionary are equal
375        for key in self.mass_spectrum.keys():
376            equality_check.append(
377                self.mass_spectrum[key].mass_spectrum
378                == value.mass_spectrum[key].mass_spectrum
379            )
380            equality_check.append(
381                self.mass_spectrum[key].ms_peak == value.mass_spectrum[key].ms_peak
382            )
383            equality_check.append(
384                self.mass_spectrum[key].molecular_search
385                == value.mass_spectrum[key].molecular_search
386            )
387            equality_check.append(
388                self.mass_spectrum[key].transient == value.mass_spectrum[key].transient
389            )
390            equality_check.append(
391                self.mass_spectrum[key].data_input
392                == value.mass_spectrum[key].data_input
393            )
394            equality_check.append(
395                self.mass_spectrum[key].spectral_similarity_search
396                == value.mass_spectrum[key].spectral_similarity_search
397            )
398
399        return all(equality_check)
400
401    def print(self):
402        """Print the LCMSParameters object"""
403        # Print the lcms paramters
404        for k, v in self.__dict__.items():
405            if k == "lc_ms":
406                print(k, type(v).__name__)
407
408        for k2, v2 in self.mass_spectrum.items():
409            """Print the MSParameters object"""
410            for k3, v3 in v2.__dict__.items():
411                print("{} - {}: {}".format(k2, k3, type(v3).__name__))
412
413                for k4, v4 in v3.__dict__.items():
414                    print("    {}: {}".format(k4, v4))
415
416
417class LCMSCollectionParameters:
418    """LCMSCollectionParameters class is used to store the parameters used for the processing of the LCMS collection
419
420    Each attribute is a class that contains the parameters for the processing of the LCMS collection,
421    see the corems.encapsulation.factory.processingSetting module for more details.
422
423    Parameters
424    ----------
425    use_defaults: bool, optional
426        if True, the class will be instantiated with the default values, otherwise the current values will be used.
427        Default is False.
428
429    Attributes
430    -----------
431    lcms_collection: LCMSCollectionSettings
432        LCMSCollectionSettings object
433
434    Notes
435    -----
436    One can use the use_defaults parameter to reset the parameters to the default values.
437    Alternatively, to use the current values - modify the class's contents before instantiating the class.
438    """
439
440    lcms_collection = LCMSCollectionSettings()
441
442    def __init__(self, use_defaults=False) -> None:
443        if not use_defaults:
444            self.lcms_collection = dataclasses.replace(
445                LCMSCollectionParameters.lcms_collection
446            )
447        else:
448            self.lcms_collection = LCMSCollectionSettings()
449
450    def copy(self):
451        """Create a copy of the LCMSCollectionParameters object"""
452        new_lcms_collection_parameters = LCMSCollectionParameters()
453        new_lcms_collection_parameters.lcms_collection = dataclasses.replace(
454            self.lcms_collection
455        )
456        return new_lcms_collection_parameters
457
458    def __eq__(self, value: object) -> bool:
459        # Check that the object is of the same type
460        if not isinstance(value, LCMSCollectionParameters):
461            return False
462        return self.lcms_collection == value.lcms_collection
463
464
465def default_parameters(file_location):  # pragma: no cover
466    """Generate parameters dictionary with the default parameters for data processing
467       To gather parameters from instrument data during the data parsing step, a parameters dictionary with the default parameters needs to be generated.
468       This dictionary acts as a placeholder and is later used as an argument for all the class constructor methods during instantiation.
469       The data gathered from the instrument is added to the class properties.
470
471    Parameters
472    ----------
473    file_location: str
474        path to the file
475
476    Returns
477    -------
478    parameters: dict
479        dictionary with the default parameters for data processing
480    """
481
482    parameters = dict()
483
484    parameters["Aterm"] = 0
485
486    parameters["Bterm"] = 0
487
488    parameters["Cterm"] = 0
489
490    parameters["exc_high_freq"] = 0
491
492    parameters["exc_low_freq"] = 0
493
494    parameters["mw_low"] = 0
495
496    parameters["mw_high"] = 0
497
498    parameters["qpd_enabled"] = 0
499
500    parameters["bandwidth"] = 0
501
502    parameters["analyzer"] = "Unknown"
503
504    parameters["acquisition_time"] = None
505
506    parameters["instrument_label"] = "Unknown"
507
508    parameters["sample_name"] = "Unknown"
509
510    parameters["number_data_points"] = 0
511
512    parameters["polarity"] = "Unknown"
513
514    parameters["filename_path"] = str(file_location)
515
516    """scan_number and rt will be need to lc ms"""
517
518    parameters["mobility_scan"] = 0
519
520    parameters["mobility_rt"] = 0
521
522    parameters["scan_number"] = 0
523
524    parameters["rt"] = 0
525
526    return parameters
def hush_output():
20def hush_output():
21    """Toggle all the verbose_processing flags to False on the MSParameters, GCMSParameters and LCMSParameters classes"""
22    MSParameters.molecular_search.verbose_processing = False
23    MSParameters.mass_spectrum.verbose_processing = False
24    GCMSParameters.gc_ms.verbose_processing = False
25    LCMSParameters.lc_ms.verbose_processing = False

Toggle all the verbose_processing flags to False on the MSParameters, GCMSParameters and LCMSParameters classes

def reset_ms_parameters():
28def reset_ms_parameters():
29    """Reset the MSParameter class to the default values"""
30    MSParameters.molecular_search = MolecularFormulaSearchSettings()
31    MSParameters.transient = TransientSetting()
32    MSParameters.mass_spectrum = MassSpectrumSetting()
33    MSParameters.ms_peak = MassSpecPeakSetting()
34    MSParameters.data_input = DataInputSetting()
35    MSParameters.spectral_similarity_search = SpectralSimilaritySearchSettings()

Reset the MSParameter class to the default values

def reset_gcms_parameters():
38def reset_gcms_parameters():
39    """Reset the GCMSParameters class to the default values"""
40    GCMSParameters.molecular_search = CompoundSearchSettings()
41    GCMSParameters.gc_ms = GasChromatographSetting()

Reset the GCMSParameters class to the default values

def reset_lcms_parameters():
44def reset_lcms_parameters():
45    """Reset the LCMSParameters class to the default values"""
46    reset_ms_parameters()
47    LCMSParameters.lc_ms = LiquidChromatographSetting()
48    LCMSParameters.mass_spectrum = {
49        "ms1": MSParameters(use_defaults=True),
50        "ms2": MSParameters(use_defaults=True),
51    }

Reset the LCMSParameters class to the default values

def settings_from_lcms( lcms_obj, profile: str = 'ms2') -> corems.encapsulation.factory.processingSetting.SpectralSimilaritySearchSettings:
54def settings_from_lcms(
55    lcms_obj, profile: str = "ms2"
56) -> SpectralSimilaritySearchSettings:
57    """Return spectral similarity search settings for an LCMS object profile key.
58
59    Parameters
60    ----------
61    lcms_obj
62        Object with ``parameters.mass_spectrum`` (e.g. LCMSBase).
63    profile : str, optional
64        Key in ``parameters.mass_spectrum`` (default ``"ms2"``).
65
66    Returns
67    -------
68    SpectralSimilaritySearchSettings
69        Live reference on that LCMS object (mutations affect only this sample).
70    """
71    return lcms_obj.parameters.mass_spectrum[profile].spectral_similarity_search

Return spectral similarity search settings for an LCMS object profile key.

Parameters
  • lcms_obj: Object with parameters.mass_spectrum (e.g. LCMSBase).
  • profile (str, optional): Key in parameters.mass_spectrum (default "ms2").
Returns
  • SpectralSimilaritySearchSettings: Live reference on that LCMS object (mutations affect only this sample).
def settings_from_lcms_collection( lcms_collection, profile: str = 'ms2') -> corems.encapsulation.factory.processingSetting.SpectralSimilaritySearchSettings:
74def settings_from_lcms_collection(
75    lcms_collection, profile: str = "ms2"
76) -> SpectralSimilaritySearchSettings:
77    """Return spectral similarity settings from the **first** sample in a collection.
78
79    This is a read convenience for library build when all samples already share
80    the same settings.  Mutating the returned object updates **only the first
81    sample**.  To change settings for every sample (and keep them equal for a
82    later re-instantiation of the collection), configure a settings instance
83    then call :func:`apply_spectral_similarity_search_to_collection`.
84
85    Parameters
86    ----------
87    lcms_collection
88        Sequence of LCMS objects (e.g. LCMSCollection).
89    profile : str, optional
90        Key in ``parameters.mass_spectrum`` (default ``"ms2"``).
91
92    Returns
93    -------
94    SpectralSimilaritySearchSettings
95    """
96    first = lcms_collection[0]
97    return settings_from_lcms(first, profile=profile)

Return spectral similarity settings from the first sample in a collection.

This is a read convenience for library build when all samples already share the same settings. Mutating the returned object updates only the first sample. To change settings for every sample (and keep them equal for a later re-instantiation of the collection), configure a settings instance then call apply_spectral_similarity_search_to_collection().

Parameters
  • lcms_collection: Sequence of LCMS objects (e.g. LCMSCollection).
  • profile (str, optional): Key in parameters.mass_spectrum (default "ms2").
Returns
  • SpectralSimilaritySearchSettings
def apply_spectral_similarity_search_to_collection( lcms_collection, settings: corems.encapsulation.factory.processingSetting.SpectralSimilaritySearchSettings, profile: str = 'ms2') -> None:
100def apply_spectral_similarity_search_to_collection(
101    lcms_collection,
102    settings: SpectralSimilaritySearchSettings,
103    profile: str = "ms2",
104) -> None:
105    """Copy *settings* onto every LCMS sample's ``mass_spectrum[profile]`` bag.
106
107    Use this after configuring spectral similarity / networking knobs so all
108    members of a collection stay aligned (collection workflows assume shared
109    processing parameters).
110
111    Parameters
112    ----------
113    lcms_collection
114        Sequence of LCMS objects (e.g. LCMSCollection).
115    settings : SpectralSimilaritySearchSettings
116        Settings to broadcast.  Each sample receives ``settings.copy()`` so
117        later per-sample mutations do not cross-link.
118    profile : str, optional
119        Key in ``parameters.mass_spectrum`` (default ``"ms2"``).
120    """
121    for sample in lcms_collection:
122        if profile not in sample.parameters.mass_spectrum:
123            raise KeyError(
124                f"profile={profile!r} not in sample parameters.mass_spectrum "
125                f"(keys={list(sample.parameters.mass_spectrum)})"
126            )
127        sample.parameters.mass_spectrum[
128            profile
129        ].spectral_similarity_search = settings.copy()

Copy settings onto every LCMS sample's mass_spectrum[profile] bag.

Use this after configuring spectral similarity / networking knobs so all members of a collection stay aligned (collection workflows assume shared processing parameters).

Parameters
  • lcms_collection: Sequence of LCMS objects (e.g. LCMSCollection).
  • settings (SpectralSimilaritySearchSettings): Settings to broadcast. Each sample receives settings.copy() so later per-sample mutations do not cross-link.
  • profile (str, optional): Key in parameters.mass_spectrum (default "ms2").
class MSParameters:
132class MSParameters:
133    """MSParameters class is used to store the parameters used for the processing of the mass spectrum
134
135    Each attibute is a class that contains the parameters for the processing of the mass spectrum, see the corems.encapsulation.factory.processingSetting module for more details.
136
137    Parameters
138    ----------
139    use_defaults: bool, optional
140        if True, the class will be instantiated with the default values, otherwise the current values will be used. Default is False.
141
142    Attributes
143    -----------
144    molecular_search: MolecularFormulaSearchSettings
145        MolecularFormulaSearchSettings object
146    transient: TransientSetting
147        TransientSetting object
148    mass_spectrum: MassSpectrumSetting
149        MassSpectrumSetting object
150    ms_peak: MassSpecPeakSetting
151        MassSpecPeakSetting object
152    data_input: DataInputSetting
153        DataInputSetting object
154    spectral_similarity_search: SpectralSimilaritySearchSettings
155        Spectral similarity library search and molecular networking settings
156        (not molecular formula search). Used for LCMS MS2 profiles; present
157        but typically unused on MS1 mass spectrum parameters.
158
159    Notes
160    -----
161    One can use the use_defaults parameter to reset the parameters to the default values.
162    Alternatively, to use the current values - modify the class's contents before instantiating the class.
163    """
164
165    molecular_search = MolecularFormulaSearchSettings()
166    transient = TransientSetting()
167    mass_spectrum = MassSpectrumSetting()
168    ms_peak = MassSpecPeakSetting()
169    data_input = DataInputSetting()
170    spectral_similarity_search = SpectralSimilaritySearchSettings()
171
172    def __init__(self, use_defaults=False) -> None:
173        if not use_defaults:
174            self.molecular_search = dataclasses.replace(MSParameters.molecular_search)
175            self.transient = dataclasses.replace(MSParameters.transient)
176            self.mass_spectrum = dataclasses.replace(MSParameters.mass_spectrum)
177            self.ms_peak = dataclasses.replace(MSParameters.ms_peak)
178            self.data_input = dataclasses.replace(MSParameters.data_input)
179            self.spectral_similarity_search = (
180                MSParameters.spectral_similarity_search.copy()
181            )
182        else:
183            self.molecular_search = MolecularFormulaSearchSettings()
184            self.transient = TransientSetting()
185            self.mass_spectrum = MassSpectrumSetting()
186            self.ms_peak = MassSpecPeakSetting()
187            self.data_input = DataInputSetting()
188            self.spectral_similarity_search = SpectralSimilaritySearchSettings()
189
190    def copy(self):
191        """Create a copy of the MSParameters object"""
192        new_ms_parameters = MSParameters()
193        new_ms_parameters.molecular_search = dataclasses.replace(self.molecular_search)
194        new_ms_parameters.transient = dataclasses.replace(self.transient)
195        new_ms_parameters.mass_spectrum = dataclasses.replace(self.mass_spectrum)
196        new_ms_parameters.ms_peak = dataclasses.replace(self.ms_peak)
197        new_ms_parameters.data_input = dataclasses.replace(self.data_input)
198        new_ms_parameters.spectral_similarity_search = (
199            self.spectral_similarity_search.copy()
200        )
201
202        return new_ms_parameters
203
204    def print(self):
205        """Print the MSParameters object"""
206        for k, v in self.__dict__.items():
207            print(k, type(v).__name__)
208
209            for k2, v2 in v.__dict__.items():
210                print("    {}: {}".format(k2, v2))
211
212    def __eq__(self, value: object) -> bool:
213        # Check that the object is of the same type
214        if not isinstance(value, MSParameters):
215            return False
216        equality_check = []
217        equality_check.append(self.molecular_search == value.molecular_search)
218        equality_check.append(self.transient == value.transient)
219        equality_check.append(self.mass_spectrum == value.mass_spectrum)
220        equality_check.append(self.ms_peak == value.ms_peak)
221        equality_check.append(self.data_input == value.data_input)
222        equality_check.append(
223            self.spectral_similarity_search == value.spectral_similarity_search
224        )
225
226        return all(equality_check)

MSParameters class is used to store the parameters used for the processing of the mass spectrum

Each attibute is a class that contains the parameters for the processing of the mass spectrum, see the corems.encapsulation.factory.processingSetting module for more details.

Parameters
  • use_defaults (bool, optional): if True, the class will be instantiated with the default values, otherwise the current values will be used. Default is False.
Attributes
  • molecular_search (MolecularFormulaSearchSettings): MolecularFormulaSearchSettings object
  • transient (TransientSetting): TransientSetting object
  • mass_spectrum (MassSpectrumSetting): MassSpectrumSetting object
  • ms_peak (MassSpecPeakSetting): MassSpecPeakSetting object
  • data_input (DataInputSetting): DataInputSetting object
  • spectral_similarity_search (SpectralSimilaritySearchSettings): Spectral similarity library search and molecular networking settings (not molecular formula search). Used for LCMS MS2 profiles; present but typically unused on MS1 mass spectrum parameters.
Notes

One can use the use_defaults parameter to reset the parameters to the default values. Alternatively, to use the current values - modify the class's contents before instantiating the class.

MSParameters(use_defaults=False)
172    def __init__(self, use_defaults=False) -> None:
173        if not use_defaults:
174            self.molecular_search = dataclasses.replace(MSParameters.molecular_search)
175            self.transient = dataclasses.replace(MSParameters.transient)
176            self.mass_spectrum = dataclasses.replace(MSParameters.mass_spectrum)
177            self.ms_peak = dataclasses.replace(MSParameters.ms_peak)
178            self.data_input = dataclasses.replace(MSParameters.data_input)
179            self.spectral_similarity_search = (
180                MSParameters.spectral_similarity_search.copy()
181            )
182        else:
183            self.molecular_search = MolecularFormulaSearchSettings()
184            self.transient = TransientSetting()
185            self.mass_spectrum = MassSpectrumSetting()
186            self.ms_peak = MassSpecPeakSetting()
187            self.data_input = DataInputSetting()
188            self.spectral_similarity_search = SpectralSimilaritySearchSettings()
transient = TransientSetting(implemented_apodization_function=('Hamming', 'Hanning', 'Blackman', 'Full-Sine', 'Half-Sine', 'Kaiser', 'Half-Kaiser', 'Rectangle'), apodization_method='Hanning', number_of_truncations=0, number_of_zero_fills=1, next_power_of_two=False, kaiser_beta=8.6)
mass_spectrum = MassSpectrumSetting(noise_threshold_method='by_format', noise_threshold_methods_implemented=('by_format', 'minima', 'signal_noise', 'relative_abundance', 'absolute_abundance', 'log'), noise_threshold_min_std=6, noise_threshold_min_s2n=4.0, noise_threshold_min_relative_abundance=6.0, noise_threshold_absolute_abundance=1000000.0, noise_threshold_log_nsigma=6, noise_threshold_log_nsigma_corr_factor=0.463, noise_threshold_log_nsigma_bins=500, noise_min_mz=50.0, noise_max_mz=1200.0, min_picking_mz=50.0, max_picking_mz=1200.0, picking_point_extrapolate=3, calib_minimize_method='Powell', calib_pol_order=2, max_calib_ppm_error=1.0, min_calib_ppm_error=-1.0, calib_sn_threshold=2.0, calibration_ref_match_method='merged', calibration_ref_match_method_implemented=('legacy', 'merged'), calibration_ref_match_tolerance=0.003, calibration_ref_match_std_raw_error_limit=1.5, do_calibration=True, verbose_processing=True)
ms_peak = MassSpecPeakSetting(kendrick_base={'C': 1, 'H': 2}, kendrick_rounding_method='floor', implemented_kendrick_rounding_methods=('floor', 'ceil', 'round'), peak_derivative_threshold=0.0, peak_min_prominence_percent=0.1, min_peak_datapoints=5.0, peak_max_prominence_percent=0.1, peak_height_max_percent=10.0, legacy_resolving_power=True, legacy_centroid_polyfit=False)
data_input = DataInputSetting(header_translate={'m/z': 'm/z', 'mOz': 'm/z', 'Mass': 'm/z', 'Resolving Power': 'Resolving Power', 'Res.': 'Resolving Power', 'resolution': 'Resolving Power', 'Intensity': 'Peak Height', 'Peak Height': 'Peak Height', 'I': 'Peak Height', 'Abundance': 'Peak Height', 'abs_abu': 'Peak Height', 'Signal/Noise': 'S/N', 'S/N': 'S/N', 'sn': 'S/N'})
def copy(self):
190    def copy(self):
191        """Create a copy of the MSParameters object"""
192        new_ms_parameters = MSParameters()
193        new_ms_parameters.molecular_search = dataclasses.replace(self.molecular_search)
194        new_ms_parameters.transient = dataclasses.replace(self.transient)
195        new_ms_parameters.mass_spectrum = dataclasses.replace(self.mass_spectrum)
196        new_ms_parameters.ms_peak = dataclasses.replace(self.ms_peak)
197        new_ms_parameters.data_input = dataclasses.replace(self.data_input)
198        new_ms_parameters.spectral_similarity_search = (
199            self.spectral_similarity_search.copy()
200        )
201
202        return new_ms_parameters

Create a copy of the MSParameters object

def print(self):
204    def print(self):
205        """Print the MSParameters object"""
206        for k, v in self.__dict__.items():
207            print(k, type(v).__name__)
208
209            for k2, v2 in v.__dict__.items():
210                print("    {}: {}".format(k2, v2))

Print the MSParameters object

class GCMSParameters:
229class GCMSParameters:
230    """GCMSParameters class is used to store the parameters used for the processing of the gas chromatograph mass spectrum
231
232    Each attibute is a class that contains the parameters for the processing of the data, see the corems.encapsulation.factory.processingSetting module for more details.
233
234    Parameters
235    ----------
236    use_defaults: bool, optional
237        if True, the class will be instantiated with the default values, otherwise the current values will be used. Default is False.
238
239    Attributes
240    -----------
241    molecular_search: MolecularFormulaSearchSettings
242        MolecularFormulaSearchSettings object
243    gc_ms: GasChromatographSetting
244        GasChromatographSetting object
245
246    Notes
247    -----
248    One can use the use_defaults parameter to reset the parameters to the default values.
249    Alternatively, to use the current values - modify the class's contents before instantiating the class.
250    """
251
252    molecular_search = CompoundSearchSettings()
253    gc_ms = GasChromatographSetting()
254
255    def __init__(self, use_defaults=False) -> None:
256        if not use_defaults:
257            self.molecular_search = dataclasses.replace(GCMSParameters.molecular_search)
258            self.gc_ms = dataclasses.replace(GCMSParameters.gc_ms)
259        else:
260            self.molecular_search = CompoundSearchSettings()
261            self.gc_ms = GasChromatographSetting()
262
263    def copy(self):
264        """Create a copy of the GCMSParameters object"""
265        new_gcms_parameters = GCMSParameters()
266        new_gcms_parameters.molecular_search = dataclasses.replace(
267            self.molecular_search
268        )
269        new_gcms_parameters.gc_ms = dataclasses.replace(self.gc_ms)
270
271        return new_gcms_parameters
272
273    def __eq__(self, value: object) -> bool:
274        # Check that the object is of the same type
275        if not isinstance(value, GCMSParameters):
276            return False
277        equality_check = []
278        equality_check.append(self.molecular_search == value.molecular_search)
279        equality_check.append(self.gc_ms == value.gc_ms)
280
281        return all(equality_check)
282
283    def print(self):
284        """Print the GCMSParameters object"""
285        for k, v in self.__dict__.items():
286            print(k, type(v).__name__)
287
288            for k2, v2 in v.__dict__.items():
289                print("    {}: {}".format(k2, v2))

GCMSParameters class is used to store the parameters used for the processing of the gas chromatograph mass spectrum

Each attibute is a class that contains the parameters for the processing of the data, see the corems.encapsulation.factory.processingSetting module for more details.

Parameters
  • use_defaults (bool, optional): if True, the class will be instantiated with the default values, otherwise the current values will be used. Default is False.
Attributes
  • molecular_search (MolecularFormulaSearchSettings): MolecularFormulaSearchSettings object
  • gc_ms (GasChromatographSetting): GasChromatographSetting object
Notes

One can use the use_defaults parameter to reset the parameters to the default values. Alternatively, to use the current values - modify the class's contents before instantiating the class.

GCMSParameters(use_defaults=False)
255    def __init__(self, use_defaults=False) -> None:
256        if not use_defaults:
257            self.molecular_search = dataclasses.replace(GCMSParameters.molecular_search)
258            self.gc_ms = dataclasses.replace(GCMSParameters.gc_ms)
259        else:
260            self.molecular_search = CompoundSearchSettings()
261            self.gc_ms = GasChromatographSetting()
gc_ms = GasChromatographSetting(use_deconvolution=False, implemented_smooth_method=('savgol', 'hanning', 'blackman', 'bartlett', 'flat', 'boxcar'), smooth_window=5, smooth_method='savgol', savgol_pol_order=2, peak_derivative_threshold=0.0005, peak_height_max_percent=10.0, peak_max_prominence_percent=1.0, min_peak_datapoints=5.0, max_peak_width=0.1, noise_threshold_method='manual_relative_abundance', noise_threshold_methods_implemented=('auto_relative_abundance', 'manual_relative_abundance', 'second_derivative'), std_noise_threshold=3, peak_height_min_percent=0.1, peak_min_prominence_percent=0.1, eic_signal_threshold=0.01, max_rt_distance=0.025, verbose_processing=True)
def copy(self):
263    def copy(self):
264        """Create a copy of the GCMSParameters object"""
265        new_gcms_parameters = GCMSParameters()
266        new_gcms_parameters.molecular_search = dataclasses.replace(
267            self.molecular_search
268        )
269        new_gcms_parameters.gc_ms = dataclasses.replace(self.gc_ms)
270
271        return new_gcms_parameters

Create a copy of the GCMSParameters object

def print(self):
283    def print(self):
284        """Print the GCMSParameters object"""
285        for k, v in self.__dict__.items():
286            print(k, type(v).__name__)
287
288            for k2, v2 in v.__dict__.items():
289                print("    {}: {}".format(k2, v2))

Print the GCMSParameters object

class LCMSParameters:
292class LCMSParameters:
293    """LCMSParameters class is used to store the parameters used for the processing of the liquid chromatograph mass spectrum
294
295    Each attibute is a class that contains the parameters for the processing of the data, see the corems.encapsulation.factory.processingSetting module for more details.
296
297    Parameters
298    ----------
299    use_defaults: bool, optional
300        if True, the class will be instantiated with the default values, otherwise the current values will be used. Default is False.
301
302    Attributes
303    -----------
304    lc_ms: LiquidChromatographSetting
305        LiquidChromatographSetting object
306    mass_spectrum: dict
307        dictionary with the mass spectrum parameters for ms1 and ms2, each value is a MSParameters object
308        (includes ``spectral_similarity_search`` on each bag; use ``mass_spectrum["ms2"].spectral_similarity_search`` by default)
309
310    Notes
311    -----
312    One can use the use_defaults parameter to reset the parameters to the default values.
313    Alternatively, to use the current values - modify the class's contents before instantiating the class.
314
315    Annotation fields on ``lc_ms`` (``ms2_min_fe_score``, etc.) are legacy aliases;
316    prefer ``mass_spectrum["ms2"].spectral_similarity_search``. Use
317    :meth:`sync_ms2_annotation_from_lc_ms` / :meth:`sync_ms2_annotation_to_lc_ms`.
318    """
319
320    lc_ms = LiquidChromatographSetting()
321    mass_spectrum = {"ms1": MSParameters(), "ms2": MSParameters()}
322
323    def __init__(self, use_defaults=False) -> None:
324        if not use_defaults:
325            self.lc_ms = dataclasses.replace(LCMSParameters.lc_ms)
326            self.mass_spectrum = {
327                "ms1": MSParameters(use_defaults=False),
328                "ms2": MSParameters(use_defaults=False),
329            }
330        else:
331            self.lc_ms = LiquidChromatographSetting()
332            self.mass_spectrum = {
333                "ms1": MSParameters(use_defaults=True),
334                "ms2": MSParameters(use_defaults=True),
335            }
336        self.sync_ms2_annotation_from_lc_ms()
337
338    def sync_ms2_annotation_from_lc_ms(self, profile: str = "ms2") -> None:
339        """Copy legacy ``lc_ms`` annotation fields into ``mass_spectrum[profile].spectral_similarity_search``."""
340        if profile not in self.mass_spectrum:
341            return
342        dest = self.mass_spectrum[profile].spectral_similarity_search
343        dest.ms2_min_fe_score = self.lc_ms.ms2_min_fe_score
344        dest.search_as_lipids = self.lc_ms.search_as_lipids
345        dest.include_fragment_types = self.lc_ms.include_fragment_types
346
347    def sync_ms2_annotation_to_lc_ms(self, profile: str = "ms2") -> None:
348        """Copy ``mass_spectrum[profile].spectral_similarity_search`` annotation fields into legacy ``lc_ms``."""
349        if profile not in self.mass_spectrum:
350            return
351        src = self.mass_spectrum[profile].spectral_similarity_search
352        self.lc_ms.ms2_min_fe_score = src.ms2_min_fe_score
353        self.lc_ms.search_as_lipids = src.search_as_lipids
354        self.lc_ms.include_fragment_types = src.include_fragment_types
355
356    def copy(self):
357        """Create a copy of the LCMSParameters object"""
358        new_lcms_parameters = LCMSParameters()
359        new_lcms_parameters.lc_ms = dataclasses.replace(self.lc_ms)
360        for key in self.mass_spectrum:
361            new_lcms_parameters.mass_spectrum[key] = self.mass_spectrum[key].copy()
362
363        return new_lcms_parameters
364
365    def __eq__(self, value: object) -> bool:
366        # Check that the object is of the same type
367        if not isinstance(value, LCMSParameters):
368            return False
369        equality_check = []
370        equality_check.append(self.lc_ms == value.lc_ms)
371
372        # Check that the mass_spectrum dictionary has the same keys
373        equality_check.append(self.mass_spectrum.keys() == value.mass_spectrum.keys())
374
375        # Check that the values of the mass_spectrum dictionary are equal
376        for key in self.mass_spectrum.keys():
377            equality_check.append(
378                self.mass_spectrum[key].mass_spectrum
379                == value.mass_spectrum[key].mass_spectrum
380            )
381            equality_check.append(
382                self.mass_spectrum[key].ms_peak == value.mass_spectrum[key].ms_peak
383            )
384            equality_check.append(
385                self.mass_spectrum[key].molecular_search
386                == value.mass_spectrum[key].molecular_search
387            )
388            equality_check.append(
389                self.mass_spectrum[key].transient == value.mass_spectrum[key].transient
390            )
391            equality_check.append(
392                self.mass_spectrum[key].data_input
393                == value.mass_spectrum[key].data_input
394            )
395            equality_check.append(
396                self.mass_spectrum[key].spectral_similarity_search
397                == value.mass_spectrum[key].spectral_similarity_search
398            )
399
400        return all(equality_check)
401
402    def print(self):
403        """Print the LCMSParameters object"""
404        # Print the lcms paramters
405        for k, v in self.__dict__.items():
406            if k == "lc_ms":
407                print(k, type(v).__name__)
408
409        for k2, v2 in self.mass_spectrum.items():
410            """Print the MSParameters object"""
411            for k3, v3 in v2.__dict__.items():
412                print("{} - {}: {}".format(k2, k3, type(v3).__name__))
413
414                for k4, v4 in v3.__dict__.items():
415                    print("    {}: {}".format(k4, v4))

LCMSParameters class is used to store the parameters used for the processing of the liquid chromatograph mass spectrum

Each attibute is a class that contains the parameters for the processing of the data, see the corems.encapsulation.factory.processingSetting module for more details.

Parameters
  • use_defaults (bool, optional): if True, the class will be instantiated with the default values, otherwise the current values will be used. Default is False.
Attributes
  • lc_ms (LiquidChromatographSetting): LiquidChromatographSetting object
  • mass_spectrum (dict): dictionary with the mass spectrum parameters for ms1 and ms2, each value is a MSParameters object (includes spectral_similarity_search on each bag; use mass_spectrum["ms2"].spectral_similarity_search by default)
Notes

One can use the use_defaults parameter to reset the parameters to the default values. Alternatively, to use the current values - modify the class's contents before instantiating the class.

Annotation fields on lc_ms (ms2_min_fe_score, etc.) are legacy aliases; prefer mass_spectrum["ms2"].spectral_similarity_search. Use sync_ms2_annotation_from_lc_ms() / sync_ms2_annotation_to_lc_ms().

LCMSParameters(use_defaults=False)
323    def __init__(self, use_defaults=False) -> None:
324        if not use_defaults:
325            self.lc_ms = dataclasses.replace(LCMSParameters.lc_ms)
326            self.mass_spectrum = {
327                "ms1": MSParameters(use_defaults=False),
328                "ms2": MSParameters(use_defaults=False),
329            }
330        else:
331            self.lc_ms = LiquidChromatographSetting()
332            self.mass_spectrum = {
333                "ms1": MSParameters(use_defaults=True),
334                "ms2": MSParameters(use_defaults=True),
335            }
336        self.sync_ms2_annotation_from_lc_ms()
lc_ms = LiquidChromatographSetting(scans=(-1, -1), eic_tolerance_ppm=5.0, smooth_window=5, smooth_method='savgol', implemented_smooth_method=('savgol', 'hanning', 'blackman', 'bartlett', 'flat', 'boxcar'), savgol_pol_order=2, consecutive_scan_min=0, peak_height_max_percent=10.0, peak_max_prominence_percent=1.0, peak_derivative_threshold=0.0005, min_peak_datapoints=5.0, noise_threshold_method='manual_relative_abundance', noise_threshold_methods_implemented=('auto_relative_abundance', 'manual_relative_abundance', 'second_derivative'), peak_height_min_percent=0.1, eic_signal_threshold=0.01, dispersity_index_window=3.0, noise_window_factor=2.0, remove_redundant_mass_features=False, redundant_scan_frequency_min=0.1, redundant_feature_retain_n=3, remove_mass_features_by_peak_metrics=False, mass_feature_attribute_filter_dict={'noise_score_max': {'value': 0.8, 'operator': '>='}, 'noise_score_min': {'value': 0.5, 'operator': '>='}}, peak_picking_method='by_format', implemented_peak_picking_methods=('by_format', 'persistent homology', 'centroided_persistent_homology'), ph_inten_min_abs=0.0, mass_feature_cluster_mz_tolerance_rel=5e-06, mass_feature_cluster_rt_tolerance=0.3, ms1_scans_to_average=1, ms1_deconvolution_corr_min=0.8, ms2_dda_rt_tolerance=0.15, ms2_dda_mz_tolerance=0.05, ms2_min_fe_score=0.2, search_as_lipids=False, include_fragment_types=False, export_profile_spectra=False, export_eics=True, export_unprocessed_ms1=False, export_only_relevant_mass_spectra=False, verbose_processing=True)
mass_spectrum = {'ms1': <MSParameters object>, 'ms2': <MSParameters object>}
def sync_ms2_annotation_from_lc_ms(self, profile: str = 'ms2') -> None:
338    def sync_ms2_annotation_from_lc_ms(self, profile: str = "ms2") -> None:
339        """Copy legacy ``lc_ms`` annotation fields into ``mass_spectrum[profile].spectral_similarity_search``."""
340        if profile not in self.mass_spectrum:
341            return
342        dest = self.mass_spectrum[profile].spectral_similarity_search
343        dest.ms2_min_fe_score = self.lc_ms.ms2_min_fe_score
344        dest.search_as_lipids = self.lc_ms.search_as_lipids
345        dest.include_fragment_types = self.lc_ms.include_fragment_types

Copy legacy lc_ms annotation fields into mass_spectrum[profile].spectral_similarity_search.

def sync_ms2_annotation_to_lc_ms(self, profile: str = 'ms2') -> None:
347    def sync_ms2_annotation_to_lc_ms(self, profile: str = "ms2") -> None:
348        """Copy ``mass_spectrum[profile].spectral_similarity_search`` annotation fields into legacy ``lc_ms``."""
349        if profile not in self.mass_spectrum:
350            return
351        src = self.mass_spectrum[profile].spectral_similarity_search
352        self.lc_ms.ms2_min_fe_score = src.ms2_min_fe_score
353        self.lc_ms.search_as_lipids = src.search_as_lipids
354        self.lc_ms.include_fragment_types = src.include_fragment_types

Copy mass_spectrum[profile].spectral_similarity_search annotation fields into legacy lc_ms.

def copy(self):
356    def copy(self):
357        """Create a copy of the LCMSParameters object"""
358        new_lcms_parameters = LCMSParameters()
359        new_lcms_parameters.lc_ms = dataclasses.replace(self.lc_ms)
360        for key in self.mass_spectrum:
361            new_lcms_parameters.mass_spectrum[key] = self.mass_spectrum[key].copy()
362
363        return new_lcms_parameters

Create a copy of the LCMSParameters object

def print(self):
402    def print(self):
403        """Print the LCMSParameters object"""
404        # Print the lcms paramters
405        for k, v in self.__dict__.items():
406            if k == "lc_ms":
407                print(k, type(v).__name__)
408
409        for k2, v2 in self.mass_spectrum.items():
410            """Print the MSParameters object"""
411            for k3, v3 in v2.__dict__.items():
412                print("{} - {}: {}".format(k2, k3, type(v3).__name__))
413
414                for k4, v4 in v3.__dict__.items():
415                    print("    {}: {}".format(k4, v4))

Print the LCMSParameters object

class LCMSCollectionParameters:
418class LCMSCollectionParameters:
419    """LCMSCollectionParameters class is used to store the parameters used for the processing of the LCMS collection
420
421    Each attribute is a class that contains the parameters for the processing of the LCMS collection,
422    see the corems.encapsulation.factory.processingSetting module for more details.
423
424    Parameters
425    ----------
426    use_defaults: bool, optional
427        if True, the class will be instantiated with the default values, otherwise the current values will be used.
428        Default is False.
429
430    Attributes
431    -----------
432    lcms_collection: LCMSCollectionSettings
433        LCMSCollectionSettings object
434
435    Notes
436    -----
437    One can use the use_defaults parameter to reset the parameters to the default values.
438    Alternatively, to use the current values - modify the class's contents before instantiating the class.
439    """
440
441    lcms_collection = LCMSCollectionSettings()
442
443    def __init__(self, use_defaults=False) -> None:
444        if not use_defaults:
445            self.lcms_collection = dataclasses.replace(
446                LCMSCollectionParameters.lcms_collection
447            )
448        else:
449            self.lcms_collection = LCMSCollectionSettings()
450
451    def copy(self):
452        """Create a copy of the LCMSCollectionParameters object"""
453        new_lcms_collection_parameters = LCMSCollectionParameters()
454        new_lcms_collection_parameters.lcms_collection = dataclasses.replace(
455            self.lcms_collection
456        )
457        return new_lcms_collection_parameters
458
459    def __eq__(self, value: object) -> bool:
460        # Check that the object is of the same type
461        if not isinstance(value, LCMSCollectionParameters):
462            return False
463        return self.lcms_collection == value.lcms_collection

LCMSCollectionParameters class is used to store the parameters used for the processing of the LCMS collection

Each attribute is a class that contains the parameters for the processing of the LCMS collection, see the corems.encapsulation.factory.processingSetting module for more details.

Parameters
  • use_defaults (bool, optional): if True, the class will be instantiated with the default values, otherwise the current values will be used. Default is False.
Attributes
  • lcms_collection (LCMSCollectionSettings): LCMSCollectionSettings object
Notes

One can use the use_defaults parameter to reset the parameters to the default values. Alternatively, to use the current values - modify the class's contents before instantiating the class.

LCMSCollectionParameters(use_defaults=False)
443    def __init__(self, use_defaults=False) -> None:
444        if not use_defaults:
445            self.lcms_collection = dataclasses.replace(
446                LCMSCollectionParameters.lcms_collection
447            )
448        else:
449            self.lcms_collection = LCMSCollectionSettings()
lcms_collection = LCMSCollectionSettings(cores=1, drop_isotopologues=False, _mass_feature_anchor_technique=['relative_intensity'], mass_feature_anchor_techniques_available=('deconvoluted_mass_spectra', 'absolute_intensity', 'relative_intensity'), mass_feature_anchor_absolute_intensity_threshold=10000, mass_feature_anchor_relative_intensity_threshold=0.6, alignment_minimum_matches=5, alignment_hold_out_fraction=0.3, _alignment_acceptance_technique=['fraction_improved', 'mean_squared_error_improved'], alignment_acceptance_techniques_available=('fraction_improved', 'mean_squared_error_improved'), alignment_acceptance_fraction_improved_threshold=0.5, alignment_mz_tol_ppm=5, alignment_rt_tol=0.4, consensus_mz_tol_ppm=5, consensus_rt_tol=0.3, consensus_partition_size=10000, filter_consensus_mass_features=True, consensus_min_sample_fraction=0.5, gap_fill_expand_on_miss=True, consensus_representative_metric='intensity_prefer_ms2', consensus_representative_metrics_available=('intensity', 'intensity_prefer_ms2'), feature_group_isotope_atoms=('C',), feature_group_min_isotope_abundance=0.01, feature_group_max_isotope_offset=4, feature_group_corr_threshold=0.8, feature_group_min_shared_sample_fraction=0.15, feature_group_ion_types=('[M+H]+', '[M+H-H2O]+', '[M-H]-', '[M+Na]+', '[M+H-NH3]+', '[M+NH4]+', '[M-H-H2O]-', '[M-H+2Na]+', '[M-H+H2O]-', '[M+NH4-H2O]+', '[M+H+H2O]+', '[M+K]+', '[M+H-2H2O]+', '[M]+'), feature_group_constrain_annotation=True, feature_group_partition_size=5000)
def copy(self):
451    def copy(self):
452        """Create a copy of the LCMSCollectionParameters object"""
453        new_lcms_collection_parameters = LCMSCollectionParameters()
454        new_lcms_collection_parameters.lcms_collection = dataclasses.replace(
455            self.lcms_collection
456        )
457        return new_lcms_collection_parameters

Create a copy of the LCMSCollectionParameters object

def default_parameters(file_location):
466def default_parameters(file_location):  # pragma: no cover
467    """Generate parameters dictionary with the default parameters for data processing
468       To gather parameters from instrument data during the data parsing step, a parameters dictionary with the default parameters needs to be generated.
469       This dictionary acts as a placeholder and is later used as an argument for all the class constructor methods during instantiation.
470       The data gathered from the instrument is added to the class properties.
471
472    Parameters
473    ----------
474    file_location: str
475        path to the file
476
477    Returns
478    -------
479    parameters: dict
480        dictionary with the default parameters for data processing
481    """
482
483    parameters = dict()
484
485    parameters["Aterm"] = 0
486
487    parameters["Bterm"] = 0
488
489    parameters["Cterm"] = 0
490
491    parameters["exc_high_freq"] = 0
492
493    parameters["exc_low_freq"] = 0
494
495    parameters["mw_low"] = 0
496
497    parameters["mw_high"] = 0
498
499    parameters["qpd_enabled"] = 0
500
501    parameters["bandwidth"] = 0
502
503    parameters["analyzer"] = "Unknown"
504
505    parameters["acquisition_time"] = None
506
507    parameters["instrument_label"] = "Unknown"
508
509    parameters["sample_name"] = "Unknown"
510
511    parameters["number_data_points"] = 0
512
513    parameters["polarity"] = "Unknown"
514
515    parameters["filename_path"] = str(file_location)
516
517    """scan_number and rt will be need to lc ms"""
518
519    parameters["mobility_scan"] = 0
520
521    parameters["mobility_rt"] = 0
522
523    parameters["scan_number"] = 0
524
525    parameters["rt"] = 0
526
527    return parameters

Generate parameters dictionary with the default parameters for data processing To gather parameters from instrument data during the data parsing step, a parameters dictionary with the default parameters needs to be generated. This dictionary acts as a placeholder and is later used as an argument for all the class constructor methods during instantiation. The data gathered from the instrument is added to the class properties.

Parameters
  • file_location (str): path to the file
Returns
  • parameters (dict): dictionary with the default parameters for data processing