MSExperiment#

class pyopenms.MSExperiment(*args, **kwargs)#

Bases: MSExperiment

__init__(*args, **kwargs)#

Overload:

__init__(self) None

Overload:

__init__(self, in_0: MSExperiment) None

Methods

__init__(*args, **kwargs)

addChromatogram(self, chromatogram)

addSpectrum(self, spec)

aggregateFromMatrix(self, ranges, ms_level, ...)

Aggregates intensity values for multiple m/z and RT ranges specified in a matrix

calculateTIC(self)

Returns the total ion chromatogram

chromatogramRanges(self)

Returns a reference to the chromatogram range manager

clear(self, clear_meta_data)

Clear all spectra data and meta data (if called with True)

clearMetaDataArrays(self)

clearMetaInfo(self)

Removes all meta values

clearRanges(self)

Clear all ranges in all range managers

empty(self)

extractXICsFromMatrix(self, ranges, ...)

Extracts XIC chromatograms for multiple m/z and RT ranges specified in a matrix

get2DPeakData

Cython signature: tuple[np.array[float] rt, np.array[float] mz, np.array[float] inty] get2DPeakData(float min_rt, float max_rt, float min_mz, float max_mz, unsigned int ms_level)

get2DPeakDataIM

Cython signature: tuple[np.array[float] rt, np.array[float] mz, np.array[float] inty, np.array[float] ion_mobility] get2DPeakDataIM(float min_rt, float max_rt, float min_mz, float max_mz, unsigned int ms_level)

get2DPeakDataIMLong

Cython signature: tuple[np.array[float] rt, np.array[float] mz, np.array[float] inty, np.array[float] ion_mobility] get2DPeakDataIMLong(float min_rt, float max_rt, float min_mz, float max_mz, unsigned int ms_level)

get2DPeakDataLong

Cython signature: tuple[np.array[float] rt, np.array[float] mz, np.array[float] inty] get2DPeakDataLong(float min_rt, float max_rt, float min_mz, float max_mz, unsigned int ms_level)

getChromatogram

Cython signature: MSChromatogram getChromatogram(size_t id_)

getChromatograms(self)

getComment(self)

Returns the free-text comment

getContacts(self)

Returns a reference to the list of contact persons

getDateTime(self)

Returns the date the experiment was performed

getExperimentalSettings(self)

getFractionIdentifier(self)

Returns fraction identifier

getHPLC(self)

Returns a reference to the description of the HPLC run

getIdentifier(self)

Retrieve document identifier (e.g. an LSID).

getInstrument(self)

Returns a reference to the MS instrument description

getKeys(self, keys)

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

getLoadedFilePath(self)

Returns the file_name which is the absolute path to the file loaded

getLoadedFileType(self)

Returns the file_type (e.g. featureXML, consensusXML, mzData, mzXML, mzML, ...) of the file loaded.

getMSLevels

Cython signature: list[int] getMSLevels()

getMaxIntensity(self)

Get the maximum intensity value from the combined ranges

getMaxMZ(self)

Get the maximum m/z value from the combined ranges

getMaxMobility(self)

Get the maximum mobility value from the combined ranges

getMaxRT(self)

Get the maximum RT value from the combined ranges

getMetaValue(self, in_0)

Returns the value corresponding to a string, or

getMinIntensity(self)

Get the minimum intensity value from the combined ranges

getMinMZ(self)

Get the minimum m/z value from the combined ranges

getMinMobility(self)

Get the minimum mobility value from the combined ranges

getMinRT(self)

Get the minimum RT value from the combined ranges

getNrChromatograms(self)

Returns the number of chromatograms

getNrSpectra(self)

Returns the number of MS spectra

getPrecursorSpectrum(self, zero_based_index)

Returns the index of the precursor spectrum for spectrum at index @p zero_based_index

getPrimaryMSRunPath(self, toFill)

References to the first MS file(s) after conversions.

getSample(self)

Returns a reference to the sample description

getSize(self)

Returns the total number of peaks

getSourceFiles(self)

Returns a reference to the source data file

getSpectra(self)

getSpectrum

Cython signature: MSSpectrum getSpectrum(size_t id_)

get_df([columns, ms_levels, long])

Generates a pandas DataFrame with all peaks in the MSExperiment

get_df_columns([long])

Returns a list of column names that get_df() would produce.

get_ion_df()

Generates a pandas DataFrame with all peaks and the ion mobility in the MSExperiment

get_massql_df([ion_mobility])

Exports data from MSExperiment to pandas DataFrames to be used with MassQL.

isMetaEmpty(self)

Returns if the MetaInfo is empty

isSorted

metaRegistry(self)

Returns a reference to the MetaInfoRegistry

metaValueExists(self, in_0)

Returns whether an entry with the given name exists

removeMetaValue(self, in_0)

Removes the DataValue corresponding to name if it exists

reserve(self, s)

reserveSpaceChromatograms(self, s)

reserveSpaceSpectra(self, s)

reset(self)

resize(self, s)

setChromatograms(self, chromatograms)

setComment(self, comment)

Sets the free-text comment

setContacts(self, contacts)

Sets the list of contact persons

setDateTime(self, date_time)

Sets the date the experiment was performed

setFractionIdentifier(self, fraction_identifier)

Sets the fraction identifier

setHPLC(self, hplc)

Sets the description of the HPLC run

setIdentifier(self, id)

Sets document identifier (e.g. an LSID).

setInstrument(self, instrument)

Sets the MS instrument description

setLoadedFilePath(self, file_name)

Sets the file_name according to absolute path of the file loaded, preferably done whilst loading

setLoadedFileType(self, file_name)

Sets the file_type according to the type of the file loaded from, preferably done whilst loading

setMetaValue(self, in_0, in_1)

Sets the DataValue corresponding to a name

setSample(self, sample)

Sets the sample description

setSourceFiles(self, source_files)

Sets the source data file

setSpectra(self, spectra)

size(self)

sortChromatograms

sortSpectra

spectrumRanges(self)

Returns a reference to the spectrum range manager

swap(self, in_0)

updateRanges(self)

Recalculate global ranges for both spectra and chromatrograms after changes to the data has been made.

addChromatogram(self, chromatogram: MSChromatogram) None#
addSpectrum(self, spec: MSSpectrum) None#
aggregateFromMatrix(self, ranges: MatrixDouble, ms_level: int, mz_agg: bytes) List[List[float]]#

Aggregates intensity values for multiple m/z and RT ranges specified in a matrix

calculateTIC(self) MSChromatogram#

Returns the total ion chromatogram

chromatogramRanges(self) ChromatogramRangeManager#

Returns a reference to the chromatogram range manager

clear(self, clear_meta_data: bool) None#

Clear all spectra data and meta data (if called with True)

clearMetaDataArrays(self) bool#
clearMetaInfo(self) None#

Removes all meta values

clearRanges(self) None#

Clear all ranges in all range managers

empty(self) bool#
extractXICsFromMatrix(self, ranges: MatrixDouble, ms_level: int, mz_agg: bytes) List[MSChromatogram]#

Extracts XIC chromatograms for multiple m/z and RT ranges specified in a matrix

get2DPeakData()#

Cython signature: tuple[np.array[float] rt, np.array[float] mz, np.array[float] inty] get2DPeakData(float min_rt, float max_rt, float min_mz, float max_mz, unsigned int ms_level)

get2DPeakDataIM()#

Cython signature: tuple[np.array[float] rt, np.array[float] mz, np.array[float] inty, np.array[float] ion_mobility] get2DPeakDataIM(float min_rt, float max_rt, float min_mz, float max_mz, unsigned int ms_level)

get2DPeakDataIMLong()#

Cython signature: tuple[np.array[float] rt, np.array[float] mz, np.array[float] inty, np.array[float] ion_mobility] get2DPeakDataIMLong(float min_rt, float max_rt, float min_mz, float max_mz, unsigned int ms_level)

get2DPeakDataLong()#

Cython signature: tuple[np.array[float] rt, np.array[float] mz, np.array[float] inty] get2DPeakDataLong(float min_rt, float max_rt, float min_mz, float max_mz, unsigned int ms_level)

getChromatogram()#

Cython signature: MSChromatogram getChromatogram(size_t id_)

getChromatograms(self) List[MSChromatogram]#
getComment(self) bytes | str | String#

Returns the free-text comment

getContacts(self) List[ContactPerson]#

Returns a reference to the list of contact persons

getDateTime(self) DateTime#

Returns the date the experiment was performed

getExperimentalSettings(self) ExperimentalSettings#
getFractionIdentifier(self) bytes | str | String#

Returns fraction identifier

getHPLC(self) HPLC#

Returns a reference to the description of the HPLC run

getIdentifier(self) bytes | str | String#

Retrieve document identifier (e.g. an LSID)

getInstrument(self) Instrument#

Returns a reference to the MS instrument description

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

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

getLoadedFilePath(self) bytes | str | String#

Returns the file_name which is the absolute path to the file loaded

getLoadedFileType(self) int#

Returns the file_type (e.g. featureXML, consensusXML, mzData, mzXML, mzML, …) of the file loaded

getMSLevels()#

Cython signature: list[int] getMSLevels()

getMaxIntensity(self) float#

Get the maximum intensity value from the combined ranges

getMaxMZ(self) float#

Get the maximum m/z value from the combined ranges

getMaxMobility(self) float#

Get the maximum mobility value from the combined ranges

getMaxRT(self) float#

Get the maximum RT value from the combined ranges

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#

Get the minimum intensity value from the combined ranges

getMinMZ(self) float#

Get the minimum m/z value from the combined ranges

getMinMobility(self) float#

Get the minimum mobility value from the combined ranges

getMinRT(self) float#

Get the minimum RT value from the combined ranges

getNrChromatograms(self) int#

Returns the number of chromatograms

getNrSpectra(self) int#

Returns the number of MS spectra

getPrecursorSpectrum(self, zero_based_index: int) int#

Returns the index of the precursor spectrum for spectrum at index @p zero_based_index

getPrimaryMSRunPath(self, toFill: List[bytes]) None#

References to the first MS file(s) after conversions. Used to trace results back to original data.

getSample(self) Sample#

Returns a reference to the sample description

getSize(self) int#

Returns the total number of peaks

getSourceFiles(self) List[SourceFile]#

Returns a reference to the source data file

getSpectra(self) List[MSSpectrum]#
getSpectrum()#

Cython signature: MSSpectrum getSpectrum(size_t id_)

get_df(columns: None | List[str] = None, ms_levels: List[int] = [], long: bool = False)#

Generates a pandas DataFrame with all peaks in the MSExperiment

Parameters: columns (list or None): List of column names to include. If None,

includes all columns. Use get_df_columns() to discover available columns.

ms_levels (List[int]): Get only spectra with the given MS levels. Default is an empty list, which means all MS levels will be included. long (bool): set to True if you want to have a long/expanded/melted dataframe with one row per peak. Faster but

replicated RT information. If False, returns rows in the style: rt, _np.array(mz), _np.array(int)

Returns: pandas.DataFrame: feature information stored in a DataFrame

Example:
>>> # Get all columns
>>> df = exp.get_df()
>>> # Discover available columns
>>> print(exp.get_df_columns())
>>> # Get only specific columns
>>> df = exp.get_df(columns=['rt', 'mz', 'intensity'], long=True)
get_df_columns(long: bool = False) List[str]#

Returns a list of column names that get_df() would produce.

Useful for discovering available columns before export.

Args:
long (bool): If True, returns columns for long format.

If False, returns columns for compact format.

Returns:

list: List of column name strings.

Example:
>>> exp.get_df_columns(long=True)
['rt', 'mz', 'intensity', 'ms_level']
>>> exp.get_df_columns(long=False)
['rt', 'ms_level', 'mz_array', 'intensity_array']
get_ion_df()#

Generates a pandas DataFrame with all peaks and the ion mobility in the MSExperiment

Returns: pandas.DataFrame: feature information stored in a DataFrame

get_massql_df(ion_mobility=False)#

Exports data from MSExperiment to pandas DataFrames to be used with MassQL.

The Python module massql allows queries in mass spectrometry data (MS1 and MS2 data frames) in a SQL like fashion (mwang87/MassQueryLanguage).

Both dataframes contain the columns: ‘i’: intensity of a peak ‘i_norm’: intensity normalized by the maximun intensity in the spectrum ‘i_tic_norm’: intensity normalized by the sum of intensities (TIC) in the spectrum ‘mz’: mass to charge of a peak ‘scan’: number of the spectrum ‘rt’: retention time of the spectrum ‘polarity’: ion mode of the spectrum as integer value (positive: 1, negative: 2) ‘ion’: the ionic mobility of a peak if ion parameter is True

The MS2 dataframe contains additional columns: ‘precmz’: mass to charge of the precursor ion ‘ms1scan’: number of the corresponding MS1 spectrum ‘charge’: charge of the precursor ion

Parameters:

ion (bool): if True, returns the ion mobility of the peaks.

Returns: ms1_df (pandas.DataFrame): peak data of MS1 spectra ms2_df (pandas.DataFrame): peak data of MS2 spectra with precursor information

isMetaEmpty(self) bool#

Returns if the MetaInfo is empty

isSorted()#

Overload:

isSorted(self, check_mz: bool) bool

Checks if all spectra are sorted with respect to ascending RT

Overload:

isSorted(self) bool
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

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

Removes the DataValue corresponding to name if it exists

reserve(self, s: int) None#
reserveSpaceChromatograms(self, s: int) None#
reserveSpaceSpectra(self, s: int) None#
reset(self) None#
resize(self, s: int) None#
setChromatograms(self, chromatograms: List[MSChromatogram]) None#
setComment(self, comment: bytes | str | String) None#

Sets the free-text comment

setContacts(self, contacts: List[ContactPerson]) None#

Sets the list of contact persons

setDateTime(self, date_time: DateTime) None#

Sets the date the experiment was performed

setFractionIdentifier(self, fraction_identifier: bytes | str | String) None#

Sets the fraction identifier

setHPLC(self, hplc: HPLC) None#

Sets the description of the HPLC run

setIdentifier(self, id: bytes | str | String) None#

Sets document identifier (e.g. an LSID)

setInstrument(self, instrument: Instrument) None#

Sets the MS instrument description

setLoadedFilePath(self, file_name: bytes | str | String) None#

Sets the file_name according to absolute path of the file loaded, preferably done whilst loading

setLoadedFileType(self, file_name: bytes | str | String) None#

Sets the file_type according to the type of the file loaded from, preferably done whilst loading

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

setSample(self, sample: Sample) None#

Sets the sample description

setSourceFiles(self, source_files: List[SourceFile]) None#

Sets the source data file

setSpectra(self, spectra: List[MSSpectrum]) None#
size(self) int#
sortChromatograms()#

Overload:

sortChromatograms(self, sort_rt: bool) None

Sorts chromatograms by m/z. If sort_rt=True also sort each chromatogram RT

Overload:

sortChromatograms(self) None
sortSpectra()#

Overload:

sortSpectra(self, sort_mz: bool) None

Sorts spectra by RT. If sort_mz=True also sort each peak in a spectrum by m/z

Overload:

sortSpectra(self) None
spectrumRanges(self) SpectrumRangeManager#

Returns a reference to the spectrum range manager

swap(self, in_0: MSExperiment) None#
updateRanges(self) None#

Recalculate global ranges for both spectra and chromatrograms after changes to the data has been made.