MSSpectrum#

class pyopenms.MSSpectrum#

Bases: object

Cython implementation of _MSSpectrum

Original C++ documentation is available here

– Inherits from [‘SpectrumSettings’, ‘RangeManagerMzInt’]

The representation of a 1D spectrum. Raw data access is proved by get_peaks and set_peaks, which yields numpy arrays Iterations yields access to underlying peak objects but is slower Extra data arrays can be accessed through getFloatDataArrays / getIntegerDataArrays / getStringDataArrays See help(SpectrumSettings) for information about meta-information

Usage:

ms_level = spectrum.getMSLevel()
rt = spectrum.getRT()
mz, intensities = spectrum.get_peaks()

Usage:

from pyopenms import *

spectrum = MSSpectrum()
spectrum.setDriftTime(25) # 25 ms
spectrum.setRT(205.2) # 205.2 s
spectrum.setMSLevel(3) # MS3
p = Precursor()
p.setIsolationWindowLowerOffset(1.5)
p.setIsolationWindowUpperOffset(1.5)
p.setMZ(600) # isolation at 600 +/- 1.5 Th
p.setActivationEnergy(40) # 40 eV
p.setCharge(4) # 4+ ion
spectrum.setPrecursors( [p] )

# Add raw data to spectrum
spectrum.set_peaks( ([401.5], [900]) )

# Additional data arrays / peak annotations
fda = FloatDataArray()
fda.setName("Signal to Noise Array")
fda.push_back(15)
sda = StringDataArray()
sda.setName("Peak annotation")
sda.push_back("y15++")
spectrum.setFloatDataArrays( [fda] )
spectrum.setStringDataArrays( [sda] )

# Add spectrum to MSExperiment
exp = MSExperiment()
exp.addSpectrum(spectrum)

# Add second spectrum and store as mzML file
spectrum2 = MSSpectrum()
spectrum2.set_peaks( ([1, 2], [1, 2]) )
exp.addSpectrum(spectrum2)

MzMLFile().store("testfile.mzML", exp)
__init__()#

Overload:

__init__(self) None

Overload:

__init__(self, in_0: MSSpectrum) None

Methods

__init__

Overload:

calculateTIC(self)

Returns the total ion current (=sum) of peak intensities in the spectrum

clear(self, clear_meta_data)

Clears all data (and meta data if clear_meta_data is true)

clearMetaInfo(self)

Removes all meta values

clearRanges(self)

Resets all range dimensions as empty

containsIMData(self)

findHighestInWindow(self, mz, ...)

Returns the index of the highest peak in the provided abs.

findNearest

Overload:

getAcquisitionInfo(self)

Returns a const reference to the acquisition info

getComment(self)

Returns the free-text comment

getDataProcessing(self)

getDriftTime(self)

Returns the drift time (-1 if not set)

getDriftTimeUnit(self)

getDriftTimeUnitAsString(self)

getFloatDataArrays(self)

Returns the additional float data arrays to store e.g.

getIMData

getInstrumentSettings(self)

Returns a const reference to the instrument settings of the current spectrum

getIntegerDataArrays(self)

Returns the additional int data arrays to store e.g.

getKeys(self, keys)

Fills the given vector with a list of all keys for which a value is set

getMSLevel(self)

Returns the MS level

getMaxIntensity(self)

Returns the maximum intensity

getMaxMZ(self)

Returns the maximum m/z

getMetaValue(self, in_0)

Returns the value corresponding to a string, or

getMinIntensity(self)

Returns the minimum intensity

getMinMZ(self)

Returns the minimum m/z

getName(self)

getNativeID(self)

Returns the native identifier for the spectrum, used by the acquisition software

getPeptideIdentifications(self)

Returns a const reference to the PeptideIdentification vector

getPrecursors(self)

Returns a const reference to the precursors

getProducts(self)

Returns a const reference to the products

getRT(self)

Returns the absolute retention time (in seconds)

getSourceFile(self)

Returns a const reference to the source file

getStringDataArrays(self)

Returns the additional string data arrays to store e.g.

getType(self)

Returns the spectrum type (centroided (PEAKS) or profile data (RAW))

get_peaks

Cython signature: numpy_vector, numpy_vector get_peaks()

intensityInRange

isMetaEmpty(self)

Returns if the MetaInfo is empty

isSorted(self)

Returns true if the spectrum is sorte by m/z

metaRegistry(self)

Returns a reference to the MetaInfoRegistry

metaValueExists(self, in_0)

Returns whether an entry with the given name exists

push_back(self, in_0)

Append a peak

removeMetaValue(self, in_0)

Removes the DataValue corresponding to name if it exists

reserve(self, n)

resize(self, n)

Resize the peak array

select(self, indices)

Subset the spectrum by indices.

setAcquisitionInfo(self, in_0)

Sets the acquisition info

setComment(self, in_0)

Sets the free-text comment

setDataProcessing(self, in_0)

setDriftTime(self, in_0)

Sets the drift time (-1 if not set)

setDriftTimeUnit(self, dt)

setFloatDataArrays(self, fda)

Sets the additional float data arrays to store e.g.

setInstrumentSettings(self, in_0)

Sets the instrument settings of the current spectrum

setIntegerDataArrays(self, ida)

Sets the additional int data arrays to store e.g.

setMSLevel(self, in_0)

Sets the MS level

setMetaValue(self, in_0, in_1)

Sets the DataValue corresponding to a name

setName(self, in_0)

setNativeID(self, in_0)

Sets the native identifier for the spectrum, used by the acquisition software

setPeptideIdentifications(self, in_0)

Sets the PeptideIdentification vector

setPrecursors(self, in_0)

Sets the precursors

setProducts(self, in_0)

Sets the products

setRT(self, in_0)

Sets the absolute retention time (in seconds)

setSourceFile(self, in_0)

Sets the source file

setStringDataArrays(self, sda)

Sets the additional string data arrays to store e.g.

setType(self, in_0)

Sets the spectrum type

set_peaks

Cython signature: set_peaks((numpy_vector, numpy_vector))

size(self)

Returns the number of peaks in the spectrum

sortByIntensity(self, reverse)

sortByPosition(self)

unify(self, in_0)

updateRanges(self)

calculateTIC(self) float#

Returns the total ion current (=sum) of peak intensities in the spectrum

clear(self, clear_meta_data: bool) None#

Clears all data (and meta data if clear_meta_data is true)

clearMetaInfo(self) None#

Removes all meta values

clearRanges(self) None#

Resets all range dimensions as empty

containsIMData(self) bool#
findHighestInWindow(self, mz: float, tolerance_left: float, tolerance_right: float) int#

Returns the index of the highest peak in the provided abs. m/z tolerance window to the left and right (-1 if none match)

findNearest()#

Overload:

findNearest(self, mz: float) int

Returns the index of the closest peak in m/z

Overload:

findNearest(self, mz: float, tolerance: float) int

Returns the index of the closest peak in the provided +/- m/z tolerance window (-1 if none match)

Overload:

findNearest(self, mz: float, tolerance_left: float, tolerance_right: float) int

Returns the index of the closest peak in the provided abs. m/z tolerance window to the left and right (-1 if none match)

getAcquisitionInfo(self) AcquisitionInfo#

Returns a const reference to the acquisition info

getComment(self) bytes | str | String#

Returns the free-text comment

getDataProcessing(self) List[DataProcessing]#
getDriftTime(self) float#

Returns the drift time (-1 if not set)

getDriftTimeUnit(self) int#
getDriftTimeUnitAsString(self) bytes | str | String#
getFloatDataArrays(self) List[FloatDataArray]#

Returns the additional float data arrays to store e.g. meta data

getIMData()#
getInstrumentSettings(self) InstrumentSettings#

Returns a const reference to the instrument settings of the current spectrum

getIntegerDataArrays(self) List[IntegerDataArray]#

Returns the additional int data arrays to store e.g. meta data

getKeys(self, keys: List[bytes]) None#

Fills the given vector with a list of all keys for which a value is set

getMSLevel(self) int#

Returns the MS level

getMaxIntensity(self) float#

Returns the maximum intensity

getMaxMZ(self) float#

Returns the maximum m/z

getMetaValue(self, in_0: bytes | str | String) int | float | bytes | str | List[int] | List[float] | List[bytes]#

Returns the value corresponding to a string, or

getMinIntensity(self) float#

Returns the minimum intensity

getMinMZ(self) float#

Returns the minimum m/z

getName(self) bytes | str | String#
getNativeID(self) bytes | str | String#

Returns the native identifier for the spectrum, used by the acquisition software

getPeptideIdentifications(self) List[PeptideIdentification]#

Returns a const reference to the PeptideIdentification vector

getPrecursors(self) List[Precursor]#

Returns a const reference to the precursors

getProducts(self) List[Product]#

Returns a const reference to the products

getRT(self) float#

Returns the absolute retention time (in seconds)

getSourceFile(self) SourceFile#

Returns a const reference to the source file

getStringDataArrays(self) List[StringDataArray]#

Returns the additional string data arrays to store e.g. meta data

getType(self) int#

Returns the spectrum type (centroided (PEAKS) or profile data (RAW))

get_peaks()#

Cython signature: numpy_vector, numpy_vector get_peaks()

Will return a tuple of two numpy arrays (m/z, intensity) corresponding to the peaks in the MSSpectrum. Provides fast access to peaks.

intensityInRange()#
isMetaEmpty(self) bool#

Returns if the MetaInfo is empty

isSorted(self) bool#

Returns true if the spectrum is sorte by m/z

metaRegistry(self) MetaInfoRegistry#

Returns a reference to the MetaInfoRegistry

metaValueExists(self, in_0: bytes | str | String) bool#

Returns whether an entry with the given name exists

push_back(self, in_0: Peak1D) None#

Append a peak

removeMetaValue(self, in_0: bytes | str | String) None#

Removes the DataValue corresponding to name if it exists

reserve(self, n: int) None#
resize(self, n: int) None#

Resize the peak array

select(self, indices: List[int]) MSSpectrum#

Subset the spectrum by indices. Also applies to associated data arrays if present.

setAcquisitionInfo(self, in_0: AcquisitionInfo) None#

Sets the acquisition info

setComment(self, in_0: bytes | str | String) None#

Sets the free-text comment

setDataProcessing(self, in_0: List[DataProcessing]) None#
setDriftTime(self, in_0: float) None#

Sets the drift time (-1 if not set)

setDriftTimeUnit(self, dt: int) None#
setFloatDataArrays(self, fda: List[FloatDataArray]) None#

Sets the additional float data arrays to store e.g. meta data

setInstrumentSettings(self, in_0: InstrumentSettings) None#

Sets the instrument settings of the current spectrum

setIntegerDataArrays(self, ida: List[IntegerDataArray]) None#

Sets the additional int data arrays to store e.g. meta data

setMSLevel(self, in_0: int) None#

Sets the MS level

setMetaValue(self, in_0: bytes | str | String, in_1: int | float | bytes | str | List[int] | List[float] | List[bytes]) None#

Sets the DataValue corresponding to a name

setName(self, in_0: bytes | str | String) None#
setNativeID(self, in_0: bytes | str | String) None#

Sets the native identifier for the spectrum, used by the acquisition software

setPeptideIdentifications(self, in_0: List[PeptideIdentification]) None#

Sets the PeptideIdentification vector

setPrecursors(self, in_0: List[Precursor]) None#

Sets the precursors

setProducts(self, in_0: List[Product]) None#

Sets the products

setRT(self, in_0: float) None#

Sets the absolute retention time (in seconds)

setSourceFile(self, in_0: SourceFile) None#

Sets the source file

setStringDataArrays(self, sda: List[StringDataArray]) None#

Sets the additional string data arrays to store e.g. meta data

setType(self, in_0: int) None#

Sets the spectrum type

set_peaks()#

Cython signature: set_peaks((numpy_vector, numpy_vector))

Takes a tuple or list of two arrays (m/z, intensity) and populates the MSSpectrum. The arrays can be numpy arrays (faster).

size(self) int#

Returns the number of peaks in the spectrum

sortByIntensity(self, reverse: bool) None#
sortByPosition(self) None#
unify(self, in_0: SpectrumSettings) None#
updateRanges(self) None#