corems.mass_spectrum.input.numpyArray

  1__author__ = "Yuri E. Corilo"
  2__date__ = "Oct 23, 2019"
  3
  4from corems.encapsulation.constant import Labels
  5from corems.encapsulation.factory.parameters import default_parameters
  6from corems.mass_spectrum.factory.MassSpectrumClasses import (
  7    MassSpecCentroid,
  8    MassSpecProfile,
  9)
 10
 11
 12def ms_from_array_profile(
 13    mz,
 14    abundance,
 15    dataname: str,
 16    polarity: int = -1,
 17    auto_process: bool = True,
 18    data_type: str = Labels.simulated_profile,
 19):
 20    """Create a MassSpecProfile object from an array of m/z values and abundance values.
 21
 22    Parameters
 23    ----------
 24    mz : numpy.ndarray
 25        Array of m/z values.
 26    abundance : numpy.ndarray
 27        Array of abundance values.
 28    dataname : str
 29        Name of the data.
 30    polarity : int, optional
 31        Polarity of the data. The default is -1.
 32    auto_process : bool, optional
 33        Flag to automatically process the data. The default is True.
 34    data_type : str, optional
 35        Type of the data. The default is Labels.simulated_profile.
 36
 37    Returns
 38    -------
 39    MassSpecProfile
 40        The created MassSpecProfile object.
 41    """
 42    data_dict = {Labels.mz: mz, Labels.abundance: abundance}
 43
 44    output_parameters = get_output_parameters(polarity, dataname)
 45
 46    output_parameters[Labels.label] = data_type
 47
 48    ms = MassSpecProfile(data_dict, output_parameters, auto_process=auto_process)
 49
 50    return ms
 51
 52
 53def ms_from_array_centroid(
 54    mz,
 55    abundance,
 56    rp: list[float],
 57    s2n: list[float],
 58    dataname: str,
 59    polarity: int = -1,
 60    auto_process: bool = True,
 61):
 62    """Create a MassSpecCentroid object from an array of m/z values, abundance values, resolution power, and signal-to-noise ratio.
 63
 64    Parameters
 65    ----------
 66    mz : numpy.ndarray
 67        Array of m/z values.
 68    abundance : numpy.ndarray
 69        Array of abundance values.
 70    rp : list(float)
 71        List of resolving power values.
 72    s2n : list(float)
 73        List of signal-to-noise ratio values.
 74    dataname : str
 75        Name of the data.
 76    polarity : int, optional
 77        Polarity of the data. The default is -1.
 78    auto_process : bool, optional
 79
 80    Returns
 81    -------
 82    MassSpecCentroid
 83        The created MassSpecCentroid object.
 84    """
 85    data_dict = {
 86        Labels.mz: mz,
 87        Labels.abundance: abundance,
 88        Labels.s2n: s2n,
 89        Labels.rp: rp,
 90    }
 91
 92    output_parameters = get_output_parameters(polarity, dataname)
 93    output_parameters[Labels.label] = Labels.corems_centroid
 94
 95    return MassSpecCentroid(data_dict, output_parameters, auto_process)
 96
 97
 98def get_output_parameters(polarity: int, file_location: str):
 99    """Generate the output parameters for creating a MassSpecProfile or MassSpecCentroid object.
100
101    Parameters
102    ----------
103    polarity : int
104        Polarity of the data.
105    file_location : str
106        File location.
107
108    Returns
109    -------
110    dict
111        Output parameters.
112    """
113    d_params = default_parameters(file_location)
114
115    d_params["analyzer"] = "Generic Simulated"
116
117    d_params["instrument_label"] = "Generic Simulated"
118
119    d_params["polarity"] = polarity
120
121    d_params["filename_path"] = file_location
122
123    d_params["mobility_scan"] = 0
124
125    d_params["mobility_rt"] = 0
126
127    d_params["scan_number"] = 0
128
129    d_params["rt"] = 0
130
131    d_params[Labels.label] = Labels.simulated_profile
132
133    return d_params
def ms_from_array_profile( mz, abundance, dataname: str, polarity: int = -1, auto_process: bool = True, data_type: str = 'Simulated Profile'):
13def ms_from_array_profile(
14    mz,
15    abundance,
16    dataname: str,
17    polarity: int = -1,
18    auto_process: bool = True,
19    data_type: str = Labels.simulated_profile,
20):
21    """Create a MassSpecProfile object from an array of m/z values and abundance values.
22
23    Parameters
24    ----------
25    mz : numpy.ndarray
26        Array of m/z values.
27    abundance : numpy.ndarray
28        Array of abundance values.
29    dataname : str
30        Name of the data.
31    polarity : int, optional
32        Polarity of the data. The default is -1.
33    auto_process : bool, optional
34        Flag to automatically process the data. The default is True.
35    data_type : str, optional
36        Type of the data. The default is Labels.simulated_profile.
37
38    Returns
39    -------
40    MassSpecProfile
41        The created MassSpecProfile object.
42    """
43    data_dict = {Labels.mz: mz, Labels.abundance: abundance}
44
45    output_parameters = get_output_parameters(polarity, dataname)
46
47    output_parameters[Labels.label] = data_type
48
49    ms = MassSpecProfile(data_dict, output_parameters, auto_process=auto_process)
50
51    return ms

Create a MassSpecProfile object from an array of m/z values and abundance values.

Parameters
  • mz (numpy.ndarray): Array of m/z values.
  • abundance (numpy.ndarray): Array of abundance values.
  • dataname (str): Name of the data.
  • polarity (int, optional): Polarity of the data. The default is -1.
  • auto_process (bool, optional): Flag to automatically process the data. The default is True.
  • data_type (str, optional): Type of the data. The default is Labels.simulated_profile.
Returns
  • MassSpecProfile: The created MassSpecProfile object.
def ms_from_array_centroid( mz, abundance, rp: list[float], s2n: list[float], dataname: str, polarity: int = -1, auto_process: bool = True):
54def ms_from_array_centroid(
55    mz,
56    abundance,
57    rp: list[float],
58    s2n: list[float],
59    dataname: str,
60    polarity: int = -1,
61    auto_process: bool = True,
62):
63    """Create a MassSpecCentroid object from an array of m/z values, abundance values, resolution power, and signal-to-noise ratio.
64
65    Parameters
66    ----------
67    mz : numpy.ndarray
68        Array of m/z values.
69    abundance : numpy.ndarray
70        Array of abundance values.
71    rp : list(float)
72        List of resolving power values.
73    s2n : list(float)
74        List of signal-to-noise ratio values.
75    dataname : str
76        Name of the data.
77    polarity : int, optional
78        Polarity of the data. The default is -1.
79    auto_process : bool, optional
80
81    Returns
82    -------
83    MassSpecCentroid
84        The created MassSpecCentroid object.
85    """
86    data_dict = {
87        Labels.mz: mz,
88        Labels.abundance: abundance,
89        Labels.s2n: s2n,
90        Labels.rp: rp,
91    }
92
93    output_parameters = get_output_parameters(polarity, dataname)
94    output_parameters[Labels.label] = Labels.corems_centroid
95
96    return MassSpecCentroid(data_dict, output_parameters, auto_process)

Create a MassSpecCentroid object from an array of m/z values, abundance values, resolution power, and signal-to-noise ratio.

Parameters
  • mz (numpy.ndarray): Array of m/z values.
  • abundance (numpy.ndarray): Array of abundance values.
  • rp (list(float)): List of resolving power values.
  • s2n (list(float)): List of signal-to-noise ratio values.
  • dataname (str): Name of the data.
  • polarity (int, optional): Polarity of the data. The default is -1.
  • auto_process (bool, optional):
Returns
  • MassSpecCentroid: The created MassSpecCentroid object.
def get_output_parameters(polarity: int, file_location: str):
 99def get_output_parameters(polarity: int, file_location: str):
100    """Generate the output parameters for creating a MassSpecProfile or MassSpecCentroid object.
101
102    Parameters
103    ----------
104    polarity : int
105        Polarity of the data.
106    file_location : str
107        File location.
108
109    Returns
110    -------
111    dict
112        Output parameters.
113    """
114    d_params = default_parameters(file_location)
115
116    d_params["analyzer"] = "Generic Simulated"
117
118    d_params["instrument_label"] = "Generic Simulated"
119
120    d_params["polarity"] = polarity
121
122    d_params["filename_path"] = file_location
123
124    d_params["mobility_scan"] = 0
125
126    d_params["mobility_rt"] = 0
127
128    d_params["scan_number"] = 0
129
130    d_params["rt"] = 0
131
132    d_params[Labels.label] = Labels.simulated_profile
133
134    return d_params

Generate the output parameters for creating a MassSpecProfile or MassSpecCentroid object.

Parameters
  • polarity (int): Polarity of the data.
  • file_location (str): File location.
Returns
  • dict: Output parameters.