pyms.eic

Class to model a subset of data from an Intensity Matrix.

Classes:

ExtractedIntensityMatrix(time_list, …)

Represents an extracted subset of the chromatographic data.

Functions:

build_extracted_intensity_matrix(im, masses)

Given an intensity matrix and a list of masses, construct a ExtractedIntensityMatrix for those masses.

class ExtractedIntensityMatrix(time_list, mass_list, intensity_array)[source]

Bases: BaseIntensityMatrix

Represents an extracted subset of the chromatographic data.

Parameters
Authors

Dominic Davis-Foster

New in version 2.3.0.

Methods:

__eq__(other)

Return whether this intensity matrix object is equal to another object.

__len__()

Returns the number of scans in the intensity matrix.

crop_mass(mass_min, mass_max)

Crops mass spectrum.

dump(file_name[, protocol])

Dumps an object to a file through pickle.dump().

get_ic_at_index(ix)

Returns the ion chromatogram at the specified index.

get_ic_at_mass([mass])

Returns the ion chromatogram for the nearest binned mass to the specified mass.

get_index_at_time(time)

Returns the nearest index corresponding to the given time.

get_index_of_mass(mass)

Returns the index of the nearest binned mass to the given mass.

get_mass_at_index(ix)

Returns binned mass at index.

get_ms_at_index(ix)

Returns a mass spectrum for a given scan index.

get_scan_at_index(ix)

Returns the spectral intensities for scan index.

get_time_at_index(ix)

Returns time at given index.

iter_ic_indices()

Iterate over column indices.

iter_ms_indices()

Iterates over row indices.

null_mass(mass)

Ignore given (closest) mass in spectra.

reduce_mass_spectra([n_intensities])

Reduces the mass spectra by retaining the top n_intensities, discarding all other intensities.

set_ic_at_index(ix, ic)

Sets the intensity of the mass at index ix in each scan to a new value.

Attributes:

bpc

Constructs a Base Peak Chromatogram from the data.

eic

Returns an IonChromatogram object representing this EIC.

intensity_array

Returns a copy of the intensity array.

intensity_array_list

Returns a copy of the intensity array as a list of lists of floats.

intensity_matrix

Returns a copy of the intensity matrix.

mass_list

Returns a list of the masses.

matrix_list

Returns the intensity matrix as a list of lists of floats.

max_mass

Returns the maximum m/z value in the spectrum.

min_mass

Returns the minimum m/z value in the spectrum.

size

Gets the size of intensity matrix.

time_list

Returns a copy of the time list.

__eq__(other)

Return whether this intensity matrix object is equal to another object.

Parameters

other – The other object to test equality with.

Return type

bool

__len__()

Returns the number of scans in the intensity matrix.

Return type

int

property bpc

Constructs a Base Peak Chromatogram from the data.

This represents the most intense ion – out of those used to create the ExtractedIntensityMatrix – for each scan.

Authors

Dominic Davis-Foster

New in version 2.3.0.

Return type

IonChromatogram

crop_mass(mass_min, mass_max)

Crops mass spectrum.

Parameters
  • mass_min (float) – Minimum mass value

  • mass_max (float) – Maximum mass value

Author

Andrew Isaac

dump(file_name, protocol=3)

Dumps an object to a file through pickle.dump().

Parameters
  • file_name (Union[str, Path, PathLike]) – Filename to save the dump as.

  • protocol (int) – The pickle protocol to use. Default 3.

Authors

Vladimir Likic, Dominic Davis-Foster (pathlib and pickle protocol support)

property eic

Returns an IonChromatogram object representing this EIC.

Return type

ExtractedIonChromatogram

get_ic_at_index(ix)

Returns the ion chromatogram at the specified index.

Parameters

ix (int) – Index of an ion chromatogram in the intensity data matrix.

Return type

IonChromatogram

Returns

Ion chromatogram at given index.

Authors

Qiao Wang, Andrew Isaac, Vladimir Likic

get_ic_at_mass(mass=None)[source]

Returns the ion chromatogram for the nearest binned mass to the specified mass.

If no mass value is given, the function returns the extracted ion chromatogram.

Parameters

mass (Optional[float]) – Mass value of an ion chromatogram. Default None.

Return type

IonChromatogram

Returns

Ion chromatogram for given mass

Authors

Andrew Isaac, Vladimir Likic

get_index_at_time(time)

Returns the nearest index corresponding to the given time.

Parameters

time (float) – Time in seconds

Return type

int

Returns

Nearest index corresponding to given time

Authors

Lewis Lee, Tim Erwin, Vladimir Likic

Changed in version 2.3.0: Now returns -1 if no index is found.

get_index_of_mass(mass)

Returns the index of the nearest binned mass to the given mass.

Parameters

mass (float) – Mass to lookup in list of masses

Author

Andrew Isaac

Return type

int

get_mass_at_index(ix)

Returns binned mass at index.

Parameters

ix (int) – Index of binned mass

Return type

float

Returns

Binned mass

Author

Andrew Isaac

get_ms_at_index(ix)

Returns a mass spectrum for a given scan index.

Parameters

ix (int) – The index of the scan.

Author

Andrew Isaac

Return type

MassSpectrum

get_scan_at_index(ix)

Returns the spectral intensities for scan index.

Parameters

ix (int) – The index of the scan

Return type

List[float]

Returns

Intensity values of scan spectra

Author

Andrew Isaac

get_time_at_index(ix)

Returns time at given index.

Parameters

ix (int)

Authors

Lewis Lee, Vladimir Likic

Return type

float

property intensity_array

Returns a copy of the intensity array.

Return type

ndarray

Returns

Matrix of intensity values.

Authors

Andrew Isaac, Lewis Lee

property intensity_array_list

Returns a copy of the intensity array as a list of lists of floats.

Return type

List[List[float]]

Returns

Matrix of intensity values.

Author

Andrew Isaac

property intensity_matrix

Returns a copy of the intensity matrix.

Return type

ndarray

Returns

Matrix of intensity values.

Author

Andrew Isaac

iter_ic_indices()

Iterate over column indices.

Return type

Iterator[int]

iter_ms_indices()

Iterates over row indices.

Return type

Iterator[int]

property mass_list

Returns a list of the masses.

Authors

Qiao Wang, Andrew Isaac, Vladimir Likic

Return type

List[float]

property matrix_list

Returns the intensity matrix as a list of lists of floats.

Return type

ndarray

Returns

Matrix of intensity values

Author

Andrew Isaac

property max_mass

Returns the maximum m/z value in the spectrum.

Author

Andrew Isaac

Return type

Optional[float]

property min_mass

Returns the minimum m/z value in the spectrum.

Author

Andrew Isaac

Return type

Optional[float]

null_mass(mass)

Ignore given (closest) mass in spectra.

Parameters

mass (float) – Mass value to remove

Author

Andrew Isaac

reduce_mass_spectra(n_intensities=5)

Reduces the mass spectra by retaining the top n_intensities, discarding all other intensities.

Parameters

n_intensities (int) – The number of top intensities to keep. Default 5.

Author

Vladimir Likic

set_ic_at_index(ix, ic)

Sets the intensity of the mass at index ix in each scan to a new value.

Parameters
  • ix (int) – Index of an ion chromatogram in the intensity data matrix to be set

  • ic (IonChromatogram) – Ion chromatogram that will be copied at position ix in the data matrix

The length of the ion chromatogram must match the appropriate dimension of the intensity matrix.

Author

Vladimir Likic

property size

Gets the size of intensity matrix.

Return type

Tuple[int, int]

Returns

Number of rows and cols

Authors

Qiao Wang, Andrew Isaac, Luke Hodkinson, Vladimir Likic

property time_list

Returns a copy of the time list.

Return type

List[float]

Returns

List of retention times

Authors

Andrew Isaac, Lewis Lee, Vladimir Likic

build_extracted_intensity_matrix(im, masses, left_bound=0.5, right_bound=0.5)[source]

Given an intensity matrix and a list of masses, construct a ExtractedIntensityMatrix for those masses.

The masses can either be:

  • single masses (of type float),

  • an iterable of masses.

left_bound and right_bound specify a range in which to include values for around each mass. For example, a mass of 169 with bounds of 0.3 and 0.7 would include every mass between 168.7 and 169.7 (inclusive on both sides).

Set the bounds to 0 to include only the given masses.

Parameters
Return type

ExtractedIntensityMatrix