MSChromatogram#

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

Bases: MSChromatogram

MSChromatogram with DataFrame export capabilities.

This class extends MSChromatogram with a get_df() method that converts chromatogram data to a pandas DataFrame.

__init__(*args, **kwargs)#

Overload:

__init__(self) None

Overload:

__init__(self, in_0: MSChromatogram) None

Methods

__init__(*args, **kwargs)

clear(self, in_0)

Clears all data and meta data

clearMetaInfo(self)

Removes all meta values

clearRanges(self)

Resets all range dimensions as empty

findNearest(self, in_0)

Binary search for the peak nearest to a specific RT :note: Make sure the chromatogram is sorted with respect to RT! Otherwise the result is undefined

getAcquisitionInfo(self)

Returns the acquisition info

getChromatogramType(self)

Get the chromatogram type

getComment(self)

Returns the free-text comment

getDataProcessing(self)

Returns the description of the applied processing

getFloatDataArrays(self)

Returns a reference to the float meta data arrays

getInstrumentSettings(self)

Returns the instrument settings of the current spectrum

getIntegerDataArrays(self)

Returns a reference to the integer meta data arrays

getKeys(self, keys)

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

getMZ(self)

Returns the mz of the product entry, makes sense especially for MRM scans

getMaxIntensity(self)

Returns the maximum intensity

getMaxRT(self)

Returns the maximum RT

getMetaValue(self, in_0)

Returns the value corresponding to a string, or

getMinIntensity(self)

Returns the minimum intensity

getMinRT(self)

Returns the minimum RT

getName(self)

Returns the name

getNativeID(self)

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

getPrecursor(self)

Returns the precursors

getProduct(self)

Returns the product ion

getSourceFile(self)

Returns the source file

getStringDataArrays(self)

Returns a reference to the string meta data arrays

get_data_dict

Returns a dictionary of NumPy arrays with RT, intensities, and metadata.

get_df([columns, export_meta_values])

Returns a pandas DataFrame representation of the MSChromatogram.

get_df_columns

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

get_peaks

isMetaEmpty(self)

Returns if the MetaInfo is empty

isSorted(self)

Checks if all peaks are sorted with respect to ascending RT

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

setAcquisitionInfo(self, acquisition_info)

Sets the acquisition info

setChromatogramType(self, type)

Sets the chromatogram type

setComment(self, comment)

Sets the free-text comment

setDataProcessing(self, in_0)

Sets the description of the applied processing

setFloatDataArrays(self, fda)

Sets the float meta data arrays

setInstrumentSettings(self, instrument_settings)

Sets the instrument settings of the current spectrum

setIntegerDataArrays(self, ida)

Sets the integer meta data arrays

setMetaValue(self, in_0, in_1)

Sets the DataValue corresponding to a name

setName(self, in_0)

Sets the name

setNativeID(self, native_id)

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

setPrecursor(self, precursor)

Sets the precursors

setProduct(self, p)

Sets the product ion

setSourceFile(self, source_file)

Sets the source file

setStringDataArrays(self, sda)

Sets the string meta data arrays

set_peaks

size(self)

sortByIntensity(self, reverse)

Lexicographically sorts the peaks by their intensity

sortByPosition(self)

Lexicographically sorts the peaks by their position

updateRanges(self)

clear(self, in_0: int) None#

Clears all data and meta data

Parameters:

clear_meta_data – If true, all meta data is cleared in addition to the data

clearMetaInfo(self) None#

Removes all meta values

clearRanges(self) None#

Resets all range dimensions as empty

findNearest(self, in_0: float) int#

Binary search for the peak nearest to a specific RT :note: Make sure the chromatogram is sorted with respect to RT! Otherwise the result is undefined

Parameters:

rt – The searched for mass-to-charge ratio searched

Returns:

Returns the index of the peak.

Raises:

Exception: Precondition is thrown if the chromatogram is empty (not only in debug mode)

getAcquisitionInfo(self) AcquisitionInfo#

Returns the acquisition info

getChromatogramType(self) int#

Get the chromatogram type

getComment(self) bytes | str | String#

Returns the free-text comment

getDataProcessing(self) List[DataProcessing]#

Returns the description of the applied processing

getFloatDataArrays(self) List[FloatDataArray]#

Returns a reference to the float meta data arrays

getInstrumentSettings(self) InstrumentSettings#

Returns the instrument settings of the current spectrum

getIntegerDataArrays(self) List[IntegerDataArray]#

Returns a reference to the integer meta data arrays

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

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

getMZ(self) float#

Returns the mz of the product entry, makes sense especially for MRM scans

getMaxIntensity(self) float#

Returns the maximum intensity

getMaxRT(self) float#

Returns the maximum RT

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

getMinRT(self) float#

Returns the minimum RT

getName(self) bytes | str | String#

Returns the name

getNativeID(self) bytes | str | String#

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

getPrecursor(self) Precursor#

Returns the precursors

getProduct(self) Product#

Returns the product ion

getSourceFile(self) SourceFile#

Returns the source file

getStringDataArrays(self) List[StringDataArray]#

Returns a reference to the string meta data arrays

get_data_dict()#

Returns a dictionary of NumPy arrays with RT, intensities, and metadata.

This method extracts chromatogram data including peaks, precursor/product info, and optional meta values into a dictionary format suitable for conversion to a pandas DataFrame.

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

all default columns. Use get_df_columns(‘all’) to see all available columns.

export_meta_values (bool): Whether to include meta values in the output.

Only applies when columns=None. Defaults to True.

Returns:
dict: Dictionary with requested columns as keys and numpy arrays as values.

Default columns include:

  • ‘rt’: numpy array of retention time values (float64)

  • ‘intensity’: numpy array of intensity values (float32)

  • ‘precursor_mz’: precursor m/z (float64)

  • ‘precursor_charge’: precursor charge (uint16)

  • ‘product_mz’: product m/z (float64)

  • ‘native_id’: chromatogram native identifier

  • Additional meta value columns (if export_meta_values=True)

Non-default columns (must be explicitly requested): - ‘chromatogram_type’: type of chromatogram - ‘comment’: chromatogram comment

Example:
>>> # Get all columns (default)
>>> data = chrom.get_data_dict()
>>> # Get only specific columns for performance
>>> data = chrom.get_data_dict(columns=['rt', 'intensity'])
>>> # Get all available columns including non-defaults
>>> all_cols = chrom.get_df_columns('all')
>>> data = chrom.get_data_dict(columns=all_cols)
get_df(columns: None | List[str] = None, export_meta_values: bool = True) DataFrame#

Returns a pandas DataFrame representation of the MSChromatogram.

This method converts the chromatogram data (peaks, metadata, precursor/product info) into a pandas DataFrame format.

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

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

export_meta_values (bool): Whether to include meta values. Only applies

when columns=None. Defaults to True.

Returns:
pd.DataFrame: DataFrame with requested columns. Default columns include:
  • rt: retention time (in seconds)

  • intensity: signal intensity at each time point

  • precursor_mz: precursor m/z

  • precursor_charge: precursor charge

  • product_mz: product m/z

  • native_id: chromatogram native identifier

  • Additional meta value columns (if export_meta_values=True)

Non-default columns (must be explicitly requested):
  • chromatogram_type: type of chromatogram

  • comment: chromatogram comment

Example:
>>> # Get all default columns
>>> df = chrom.get_df()
>>> # Discover available columns
>>> print(chrom.get_df_columns())
>>> # Get only specific columns (faster)
>>> df = chrom.get_df(columns=['rt', 'intensity'])
>>> # Get all columns including non-defaults
>>> cols = chrom.get_df_columns('all')
>>> df = chrom.get_df(columns=cols)
get_df_columns()#

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

Useful for discovering available columns before export, especially when selecting specific columns for performance optimization.

Args:
columns (str): ‘default’ for standard columns, ‘all’ for all available

columns including non-default ones (chromatogram_type, comment).

export_meta_values (bool): Whether to include meta value column names.

Defaults to True.

Returns:

list: List of column name strings.

Example:
>>> # See default columns
>>> cols = chrom.get_df_columns()
['rt', 'intensity', 'precursor_mz', ...]
>>> # See ALL available columns
>>> cols = chrom.get_df_columns('all')
['rt', 'intensity', ..., 'chromatogram_type', 'comment']
>>> # Export everything
>>> df = chrom.get_df(columns=chrom.get_df_columns('all'))
get_peaks()#
isMetaEmpty(self) bool#

Returns if the MetaInfo is empty

isSorted(self) bool#

Checks if all peaks are sorted with respect to ascending RT

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: ChromatogramPeak) 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

setAcquisitionInfo(self, acquisition_info: AcquisitionInfo) None#

Sets the acquisition info

setChromatogramType(self, type: int) None#

Sets the chromatogram type

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

Sets the free-text comment

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

Sets the description of the applied processing

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

Sets the float meta data arrays

setInstrumentSettings(self, instrument_settings: InstrumentSettings) None#

Sets the instrument settings of the current spectrum

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

Sets the integer meta data arrays

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#

Sets the name

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

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

setPrecursor(self, precursor: Precursor) None#

Sets the precursors

setProduct(self, p: Product) None#

Sets the product ion

setSourceFile(self, source_file: SourceFile) None#

Sets the source file

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

Sets the string meta data arrays

set_peaks()#
size(self) int#
sortByIntensity(self, reverse: bool) None#

Lexicographically sorts the peaks by their intensity

Sorts the peaks according to ascending intensity. Meta data arrays will be sorted accordingly

sortByPosition(self) None#

Lexicographically sorts the peaks by their position

The chromatogram is sorted with respect to position. Meta data arrays will be sorted accordingly

updateRanges(self) None#