matchms.Spectrum module¶
- class matchms.Spectrum.Spectrum(mz: array, intensities: array, metadata: Optional[dict] = None, metadata_harmonization: bool = True)[source]¶
Bases:
object
Container for a collection of peaks, losses and metadata.
Spectrum peaks are stored as
Fragments
object which can be addressed calling spectrum.peaks and contains m/z values and the respective peak intensities.Spectrum metadata is stored as
Metadata
object which can be addressed by spectrum.metadata.Code example
import numpy as np from matchms import Scores, Spectrum from matchms.similarity import CosineGreedy spectrum = Spectrum(mz=np.array([100, 150, 200.]), intensities=np.array([0.7, 0.2, 0.1]), metadata={'id': 'spectrum1', "peak_comments": {200.: "the peak at 200 m/z"}}) print(spectrum.peaks.mz[0]) print(spectrum.peaks.intensities[0]) print(spectrum.get('id')) print(spectrum.peak_comments.get(200))
Should output
100.0 0.7 spectrum1 the peak at 200 m/z
- losses¶
Losses of spectrum, the difference between the precursor and all peaks.
Can be filled with
from matchms import Fragments spectrum.losess = Fragments(mz=np.array([50.]), intensities=np.array([0.1]))
- Type
Fragments or None
- __init__(mz: array, intensities: array, metadata: Optional[dict] = None, metadata_harmonization: bool = True)[source]¶
- Parameters
mz – Array of m/z for the peaks
intensities – Array of intensities for the peaks
metadata – Dictionary with for example the scan number of precursor m/z.
metadata_harmonization (bool, optional) – Set to False if default metadata filters should not be applied. The default is True.
- get(key: str, default=None)[source]¶
Retrieve value from
metadata
dict. Shorthand forval = self.metadata[key]
- metadata_hash()[source]¶
Return a (truncated) sha256-based hash which is generated based on the spectrum metadata. Spectra with same metadata results in same metadata_hash.
- plot(figsize=(8, 6), dpi=200, **kwargs)[source]¶
Plot to visually inspect a spectrum run
spectrum.plot()
Example of a spectrum plotted using
spectrum.plot()
..¶