Data Models
nplinker.metabolomics
¶
MolecularFamily
¶
MolecularFamily(id: str)
Class to model molecular family.
Attributes:
-
id(str) –Unique id for the molecular family.
-
spectra_ids(set[str]) –Set of spectrum ids in the molecular family.
-
spectra(set[Spectrum]) –Set of Spectrum objects in the molecular family.
-
strains(StrainCollection) –StrainCollection object that contains strains in the molecular family.
Parameters:
-
id(str) –Unique id for the molecular family.
Source code in src/nplinker/metabolomics/molecular_family.py
add_spectrum
¶
add_spectrum(spectrum: Spectrum) -> None
Add a Spectrum object to the molecular family.
Parameters:
-
spectrum(Spectrum) –Spectrumobject to add to the molecular family.
Source code in src/nplinker/metabolomics/molecular_family.py
detach_spectrum
¶
detach_spectrum(spectrum: Spectrum) -> None
Remove a Spectrum object from the molecular family.
Parameters:
-
spectrum(Spectrum) –Spectrumobject to remove from the molecular family.
Source code in src/nplinker/metabolomics/molecular_family.py
has_strain
¶
Spectrum
¶
Spectrum(
id: str,
mz: list[float],
intensity: list[float],
precursor_mz: float,
precursor_charge: int,
rt: float = 0,
metadata: dict | None = None,
)
Class to model MS/MS Spectrum.
Attributes:
-
id–the spectrum ID.
-
mz–the list of m/z values.
-
intensity–the list of intensity values.
-
precursor_mz–the m/z value of the precursor ion.
-
precursor_charge–the charge of the precursor ion.
-
rt–the retention time in seconds.
-
metadata–the metadata of the spectrum, i.e. the header information in the MGF file.
-
gnps_annotations(dict) –the GNPS annotations of the spectrum.
-
gnps_id(str | None) –the GNPS ID of the spectrum.
-
strains(StrainCollection) –the strains that this spectrum belongs to.
-
family(MolecularFamily | None) –the molecular family that this spectrum belongs to.
-
peaks(ndarray) –2D array of peaks, each row is a peak of (m/z, intensity) values.
Parameters:
-
id(str) –the spectrum ID.
-
mz(list[float]) –the list of m/z values.
-
intensity(list[float]) –the list of intensity values.
-
precursor_mz(float) –the precursor m/z.
-
precursor_charge(int) –the charge of the precursor ion.
-
rt(float, default:0) –the retention time in seconds. Defaults to 0.
-
metadata(dict | None, default:None) –the metadata of the spectrum, i.e. the header information in the MGF file.
Source code in src/nplinker/metabolomics/spectrum.py
peaks
cached
property
¶
peaks: ndarray
Get the peaks, a 2D array with each row containing the values of (m/z, intensity).
__reduce__
¶
__reduce__() -> tuple
Reduce function for pickling.
Source code in src/nplinker/metabolomics/spectrum.py
has_strain
¶
to_dict
¶
Convert the Spectrum object to a dictionary for exporting purpose.
Returns:
-
dict[str, Any]–A dictionary containing containing the following key-value pairs:
- "spectrum_id" (str): The unique identifier of the spectrum.
- "num_strains_with_spectrum" (int): The number of strains associated with the spectrum.
- "precursor_mz" (float): The precursor m/z value, rounded to four decimal places.
- "rt" (float): The retention time, rounded to three decimal places.
- "molecular_family" (str | None ): The identifier of the molecular family.
- "gnps_id" (str | None ): The GNPS identifier.
- "gnps_annotations" (dict[str, str]): A dictionary of GNPS annotations.
Source code in src/nplinker/metabolomics/spectrum.py
to_tabular
¶
Convert the Spectrum object to a tabular format.
Returns:
-
dict(dict[str, str]) –A dictionary representing the Spectrum object in tabular format. The keys can be treated as headers and values are strings in which tabs are removed. This dict can be exported as a TSV file.