MSExperiment#
- class pyopenms.MSExperiment#
Bases:
ExperimentalSettingsIn-Memory representation of a mass spectrometry experiment.
Contains the data and metadata of an experiment performed with an MS (or HPLC and MS). This representation of an MS experiment is organized as list of spectra and chromatograms and provides an in-memory representation of popular mass-spectrometric file formats such as mzXML or mzML. The meta-data associated with an experiment is contained in ExperimentalSettings (by inheritance) while the raw data (as well as spectra and chromatogram level meta data) is stored in objects of type MSSpectrum and MSChromatogram, which are accessible through the getSpectrum and getChromatogram functions.
Spectra can be accessed by direct iteration or by getSpectrum(), while chromatograms are accessed through getChromatogram(). See help(ExperimentalSettings) for information about meta-data.
Usage:
exp = MSExperiment() MzMLFile().load(path_to_file, exp) for spectrum in exp: print(spectrum.size()) # prints number of peaks mz, intensities = spectrum.get_peaks()
- __init__() None#
- __init__(arg: pyopenms.MSExperiment, /) None
Methods
__init__()addChromatogram(chromatogram)Adds a chromatogram to the experiment
addSpectrum(spectrum)Adds a spectrum to the experiment
aggregateFromMatrix(ranges, ms_level, mz_agg)Aggregates intensity values for multiple m/z and RT ranges specified in a matrix
arrow_columns([data, format, ...])Returns column names that to_arrow() would produce.
calculateTIC([rt_bin_size, ms_level])Returns the total ion chromatogram
Returns a copy of the chromatogram range manager
Returns a live view of the chromatogram at index i.
Returns a list of live views of the chromatograms (see chromatogram_view).
clear(clear_meta_data)Clear all spectra data and meta data (if called with True)
Clears the meta data arrays of all contained spectra
Removes all meta values
Clear all ranges in all range managers
df_columns([long_format])Returns a list of column names that to_df() would produce.
empty()Returns True if the experiment contains no spectra
extractXICsFromMatrix(ranges, ms_level, mz_agg)Extracts XIC chromatograms for multiple m/z and RT ranges specified in a matrix
get2DPeakData(min_rt, max_rt, min_mz, ...)Retrieves peak data in the given mz-rt range as (rt, mz, intensity) numpy arrays
get2DPeakDataIM(min_rt, max_rt, min_mz, ...)Retrieves peak data with ion mobility in the given mz-rt range as (rt, mz, intensity, ion_mobility) numpy arrays
get2DPeakDataLong(min_rt, max_rt, min_mz, ...)Retrieves peak data in the given mz-rt range as (rt, mz, intensity) numpy arrays with full precision
get2DPeakDataSemiWide(ms_levels)Retrieves peak data as flat arrays + offsets for efficient semi-wide DataFrame construction.
getChromatogram(id)Returns a copy of a single chromatogram by index
Returns a copy of the list of chromatograms
Returns the free-text comment
Returns a copy of the list of contact persons
Returns the date the experiment was performed
Returns the meta information of this experiment
Returns fraction identifier
getHPLC()Returns a copy of the description of the HPLC run
Retrieve document identifier (e.g. an LSID).
Returns a copy of the MS instrument description
getKeys(keys)Overloaded function.
Returns the file_name which is the absolute path to the file loaded
Returns the file_type (e.g. featureXML, consensusXML, mzData, mzXML, mzML, ...) of the file loaded.
Returns a sorted list of unique MS levels in the experiment
Get the maximum intensity value from the combined ranges
getMaxMZ()Get the maximum m/z value from the combined ranges
Get the maximum mobility value from the combined ranges
getMaxRT()Get the maximum RT value from the combined ranges
getMetaValue(name)Returns the value corresponding to a string, or DataValue::EMPTY if not found
Get the minimum intensity value from the combined ranges
getMinMZ()Get the minimum m/z value from the combined ranges
Get the minimum mobility value from the combined ranges
getMinRT()Get the minimum RT value from the combined ranges
Returns the number of chromatograms
Returns the number of MS spectra
getPrecursorSpectrum(zero_based_index)Returns the index of the precursor spectrum for spectrum at index @p zero_based_index
References to the first MS file(s) after conversions.
Returns a copy of the sample description
getSize()Returns the total number of peaks
Returns a copy of the source data file
Returns a copy of the list of spectra
getSpectrum(id)Returns a copy of a single spectrum by index
get_df(*args, **kwargs)Deprecated: use to_df() instead.
get_df_columns(*args, **kwargs)Deprecated: Use df_columns() instead.
Returns a DataFrame with RT, mz, intensity, and ion mobility columns for MS1 spectra.
get_massql_df([ion_mobility])Exports MS1 and MS2 data to pandas DataFrames for MassQL queries.
Returns if the MetaInfo is empty
isSorted([check_mz])Checks if all spectra are sorted with respect to ascending RT
Yields live views of the chromatograms, one at a time (see chromatogram_view).
Yields live views of the spectra, one at a time (see spectrum_view).
Returns a reference to the MetaInfoRegistry
metaValueExists(name)Returns whether an entry with the given name exists
rasterizeRTMZ(output[, shape, device])Rasterize peak data into a 2D intensity matrix.
removeMetaValue(name)Removes the DataValue corresponding to name if it exists
reserve(n)Reserves space for the specified number of spectra
Reserves space for the specified number of chromatograms
Reserves space for the specified number of spectra
reset()Clears all internal data (spectra, chromatograms, ranges and meta data)
resize(n)Resizes the spectrum container to the specified number of spectra
setChromatograms(chromatograms)Sets the chromatogram list
setComment(comment)Sets the free-text comment
setContacts(contacts)Sets the list of contact persons
setDateTime(date)Sets the date the experiment was performed
setFractionIdentifier(fraction_identifier)Sets the fraction identifier
setHPLC(hplc)Sets the description of the HPLC run
setIdentifier(id)Sets document identifier (e.g. an LSID).
setInstrument(instrument)Sets the MS instrument description
setInstrumentConfigurations(configurations)setLoadedFilePath(file_name)Sets the file_name according to absolute path of the file loaded, preferably done whilst loading
setLoadedFileType(file_name)Sets the file_type according to the type of the file loaded from, preferably done whilst loading
setMetaValue(name, value)Sets the DataValue corresponding to a name
setSample(sample)Sets the sample description
setSourceFiles(source_files)Sets the source data file
setSpectra(spectra)Sets the spectrum list
size()Returns the number of spectra
sortChromatograms([sort_rt])Sorts chromatograms by m/z.
sortSpectra([sort_mz])Sorts spectra by RT.
Returns a copy of the spectrum range manager
Returns a live view of the spectrum at index i.
Returns a list of live views of the spectra (see spectrum_view).
swap(from)Swaps the content of this experiment with another
to_arrow([data, format, columns, ms_levels, ...])Returns an Apache Arrow Table with spectra and/or chromatogram data.
to_df([columns, ms_levels, long_format])Returns a pandas DataFrame of all peaks in the MSExperiment.
Recalculate global ranges for both spectra and chromatrograms after changes to the data has been made.
- class MSExperimentRasterAggregation(*values)#
Bases:
Enum- MAX = 1#
- SUM = 0#
- getMapping()#
Returns a dict mapping int values to enum member name strings.
- addChromatogram(chromatogram: pyopenms.MSChromatogram) None#
- addChromatogram(chrom: pyopenms.MSChromatogram) None
Adds a chromatogram to the experiment
- addSpectrum(spectrum: pyopenms.MSSpectrum) None#
- addSpectrum(spectrum: pyopenms.MSSpectrum) None
Adds a spectrum to the experiment
- aggregateFromMatrix(ranges: pyopenms.MatrixDouble, ms_level: int, mz_agg: str) list[list[float]]#
Aggregates intensity values for multiple m/z and RT ranges specified in a matrix
- arrow_columns(data='spectra', format='long', include_precursor_info=True, include_ion_mobility=True)#
Returns column names that to_arrow() would produce.
- calculateTIC(rt_bin_size: float = 0, ms_level: int = 1) pyopenms.MSChromatogram#
Returns the total ion chromatogram
- chromatogramRanges() pyopenms.ChromatogramRangeManager#
Returns a copy of the chromatogram range manager
- chromatogram_view(i: int) pyopenms.MSChromatogram#
Returns a live view of the chromatogram at index i. The view aliases this object’s storage: edits through it are visible immediately, and it stays valid only until the chromatogram list is resized or reordered (add/set/sort operations invalidate it). The parent object is kept alive automatically. For an owned, hazard-free copy use getChromatogram(i).
- chromatogram_views()#
Returns a list of live views of the chromatograms (see chromatogram_view).
- clear(clear_meta_data: bool) None#
Clear all spectra data and meta data (if called with True)
- clearMetaDataArrays() bool#
Clears the meta data arrays of all contained spectra
- clearMetaInfo() None#
Removes all meta values
- clearRanges() None#
Clear all ranges in all range managers
- df_columns(long_format=False)#
Returns a list of column names that to_df() would produce.
- empty() bool#
Returns True if the experiment contains no spectra
- extractXICsFromMatrix(ranges: pyopenms.MatrixDouble, ms_level: int, mz_agg: str) list[pyopenms.MSChromatogram]#
Extracts XIC chromatograms for multiple m/z and RT ranges specified in a matrix
- get2DPeakData(min_rt: float, max_rt: float, min_mz: float, max_mz: float, ms_level: int) tuple#
Retrieves peak data in the given mz-rt range as (rt, mz, intensity) numpy arrays
- get2DPeakDataIM(min_rt: float, max_rt: float, min_mz: float, max_mz: float, ms_level: int) tuple#
Retrieves peak data with ion mobility in the given mz-rt range as (rt, mz, intensity, ion_mobility) numpy arrays
- get2DPeakDataLong(min_rt: float, max_rt: float, min_mz: float, max_mz: float, ms_level: int) tuple#
Retrieves peak data in the given mz-rt range as (rt, mz, intensity) numpy arrays with full precision
- get2DPeakDataSemiWide(ms_levels: collections.abc.Sequence[int]) tuple#
Retrieves peak data as flat arrays + offsets for efficient semi-wide DataFrame construction. Returns (rt, ms_level, mz_flat, intensity_flat, offsets) numpy arrays.
- getChromatogram(id: int) pyopenms.MSChromatogram#
Returns a copy of a single chromatogram by index
- getChromatograms() list[pyopenms.MSChromatogram]#
Returns a copy of the list of chromatograms
- getComment() str#
Returns the free-text comment
- getContacts() list[pyopenms.ContactPerson]#
Returns a copy of the list of contact persons
- getDateTime() pyopenms.DateTime#
Returns the date the experiment was performed
- getExperimentalSettings() pyopenms.ExperimentalSettings#
Returns the meta information of this experiment
- getFractionIdentifier() str#
Returns fraction identifier
- getHPLC() pyopenms.HPLC#
Returns a copy of the description of the HPLC run
- getIdentifier() str#
Retrieve document identifier (e.g. an LSID)
- getInstrument() pyopenms.Instrument#
Returns a copy of the MS instrument description
- getInstrumentConfigurations() dict[str, pyopenms.Instrument]#
- getKeys(keys: list) None#
- getKeys() list
Overloaded function.
getKeys(keys: list) -> None
Fills the given list with all meta value keys
getKeys() -> list
Returns all meta value keys as a list
- getLoadedFilePath() str#
Returns the file_name which is the absolute path to the file loaded
- getLoadedFileType() pyopenms.FileTypes.FileType#
Returns the file_type (e.g. featureXML, consensusXML, mzData, mzXML, mzML, …) of the file loaded
- getMSLevels() list[int]#
Returns a sorted list of unique MS levels in the experiment
- getMaxIntensity() float#
Get the maximum intensity value from the combined ranges
- getMaxMZ() float#
Get the maximum m/z value from the combined ranges
- getMaxMobility() float#
Get the maximum mobility value from the combined ranges
- getMaxRT() float#
Get the maximum RT value from the combined ranges
- getMetaValue(name: str) None | int | float | str | bytes | list[str] | list[int] | list[float]#
Returns the value corresponding to a string, or DataValue::EMPTY if not found
- getMinIntensity() float#
Get the minimum intensity value from the combined ranges
- getMinMZ() float#
Get the minimum m/z value from the combined ranges
- getMinMobility() float#
Get the minimum mobility value from the combined ranges
- getMinRT() float#
Get the minimum RT value from the combined ranges
- getNrChromatograms() int#
Returns the number of chromatograms
- getNrSpectra() int#
Returns the number of MS spectra
- getPrecursorSpectrum(zero_based_index: int) int#
Returns the index of the precursor spectrum for spectrum at index @p zero_based_index
- getPrimaryMSRunPath() list[str]#
References to the first MS file(s) after conversions. Used to trace results back to original data.
- getSample() pyopenms.Sample#
Returns a copy of the sample description
- getSize() int#
Returns the total number of peaks
- getSourceFiles() list[pyopenms.SourceFile]#
Returns a copy of the source data file
- getSpectra() list[pyopenms.MSSpectrum]#
Returns a copy of the list of spectra
- getSpectrum(id: int) pyopenms.MSSpectrum#
Returns a copy of a single spectrum by index
- get_df(*args, **kwargs)#
Deprecated: use to_df() instead.
- get_df_columns(*args, **kwargs)#
Deprecated: Use df_columns() instead.
- get_ion_df()#
Returns a DataFrame with RT, mz, intensity, and ion mobility columns for MS1 spectra.
- get_massql_df(ion_mobility=False)#
Exports MS1 and MS2 data to pandas DataFrames for MassQL queries.
Returns (ms1_df, ms2_df) tuple of DataFrames.
- isMetaEmpty() bool#
Returns if the MetaInfo is empty
- isSorted(check_mz: bool = True) bool#
Checks if all spectra are sorted with respect to ascending RT
- iter_chromatogram_views()#
Yields live views of the chromatograms, one at a time (see chromatogram_view).
- iter_spectrum_views()#
Yields live views of the spectra, one at a time (see spectrum_view).
- static metaRegistry() pyopenms.MetaInfoRegistry#
Returns a reference to the MetaInfoRegistry
- metaValueExists(name: str) bool#
Returns whether an entry with the given name exists
- rasterizeRTMZ(output: ndarray[dtype=float32, shape=(*, *), device='cpu'], min_rt: float, max_rt: float, min_mz: float, max_mz: float, ms_level: int, aggregation: str = 'sum') None#
Rasterize peak data into a 2D intensity matrix. Output shape is [mz_bins, rt_bins].
- removeMetaValue(name: str) None#
Removes the DataValue corresponding to name if it exists
- reserve(n: int) None#
Reserves space for the specified number of spectra
- reserveSpaceChromatograms(s: int) None#
Reserves space for the specified number of chromatograms
- reserveSpaceSpectra(s: int) None#
Reserves space for the specified number of spectra
- reset() None#
Clears all internal data (spectra, chromatograms, ranges and meta data)
- resize(n: int) None#
Resizes the spectrum container to the specified number of spectra
- setChromatograms(chromatograms: collections.abc.Sequence[pyopenms.MSChromatogram]) None#
- setChromatograms(chromatograms: collections.abc.Sequence[pyopenms.MSChromatogram]) None
Sets the chromatogram list
- setComment(comment: str) None#
Sets the free-text comment
- setContacts(contacts: collections.abc.Sequence[pyopenms.ContactPerson]) None#
Sets the list of contact persons
- setDateTime(date: pyopenms.DateTime) None#
Sets the date the experiment was performed
- setFractionIdentifier(fraction_identifier: str) None#
Sets the fraction identifier
- setHPLC(hplc: pyopenms.HPLC) None#
Sets the description of the HPLC run
- setIdentifier(id: str) None#
Sets document identifier (e.g. an LSID)
- setInstrument(instrument: pyopenms.Instrument) None#
Sets the MS instrument description
- setInstrumentConfigurations(configurations: dict[str, pyopenms.Instrument]) None#
- setLoadedFilePath(file_name: str) None#
Sets the file_name according to absolute path of the file loaded, preferably done whilst loading
- setLoadedFileType(file_name: str) None#
Sets the file_type according to the type of the file loaded from, preferably done whilst loading
- setMetaValue(name: str, value: None | int | float | str | bytes | list[str] | list[int] | list[float]) None#
Sets the DataValue corresponding to a name
- setSample(sample: pyopenms.Sample) None#
Sets the sample description
- setSourceFiles(source_files: collections.abc.Sequence[pyopenms.SourceFile]) None#
Sets the source data file
- setSpectra(spectra: collections.abc.Sequence[pyopenms.MSSpectrum]) None#
- setSpectra(spectra: collections.abc.Sequence[pyopenms.MSSpectrum]) None
Sets the spectrum list
- size() int#
Returns the number of spectra
- sortChromatograms(sort_rt: bool = True) None#
Sorts chromatograms by m/z. If sort_rt=True also sort each chromatogram RT
- sortSpectra(sort_mz: bool = True) None#
Sorts spectra by RT. If sort_mz=True also sort each peak in a spectrum by m/z
- spectrumRanges() pyopenms.SpectrumRangeManager#
Returns a copy of the spectrum range manager
- spectrum_view(i: int) pyopenms.MSSpectrum#
Returns a live view of the spectrum at index i. The view aliases this object’s storage: edits through it are visible immediately, and it stays valid only until the spectrum list is resized or reordered (add/set/sort operations invalidate it). The parent object is kept alive automatically. For an owned, hazard-free copy use getSpectrum(i) or exp[i].
- spectrum_views()#
Returns a list of live views of the spectra (see spectrum_view).
- swap(from: pyopenms.MSExperiment) None#
Swaps the content of this experiment with another
- to_arrow(data='spectra', format='long', columns=None, ms_levels=None, min_rt=None, max_rt=None, min_mz=None, max_mz=None, include_precursor_info=True, include_ion_mobility=True, long_format=None)#
Returns an Apache Arrow Table with spectra and/or chromatogram data.
- to_df(columns=None, ms_levels=None, long_format=False)#
Returns a pandas DataFrame of all peaks in the MSExperiment.
- updateRanges() None#
Recalculate global ranges for both spectra and chromatrograms after changes to the data has been made.