cpyMSpec

Fast isotope pattern calculator for small molecules.

API Reference

class cpyMSpec.spectrum.CentroidedSpectrum[source]

Bases: cpyMSpec.spectrum.SpectrumBase

Centroided peaks of a profile/theoretical spectrum

charged(charge)[source]

Adds/subtracts electrons and returns a new object.

Parameters:charge (integer) – number of electrons to add
Returns:a spectrum with appropriately shifted masses
Return type:CentroidedSpectrum
copy()[source]
Returns:a (deep) copy of the instance
Return type:CentroidedSpectrum
removeIntensitiesBelow(min_intensity)[source]
trimmed(n_peaks)[source]
Parameters:n_peaks – number of peaks to keep
Returns:an isotope pattern with removed low-intensity peaks
Return type:CentroidedSpectrum
class cpyMSpec.spectrum.InstrumentModel(instrument_type, resolving_power, at_mz=200)[source]

Bases: object

resolvingPowerAt(mz)[source]

Calculates resolving power at a given m/z value

class cpyMSpec.spectrum.ProfileSpectrum(mzs, intensities)[source]

Bases: cpyMSpec.spectrum.SpectrumBase

Represents profile spectrum data, which means: * neighbor mass differences are supposed to be locally approximately equal; * occasional gaps might be present, indicating zero-intensity regions

centroids(window_size=5)[source]

Detects peaks in raw data.

Parameters:
  • mzs – sorted array of m/z values
  • intensities – array of corresponding intensities
  • window_size – size of m/z averaging window
Returns:

isotope pattern containing the centroids

Return type:

CentroidedSpectrum

copy()[source]
Returns:a (deep) copy of the instance
Return type:ProfileSpectrum
class cpyMSpec.spectrum.SpectrumBase[source]

Bases: object

addCharge(charge)[source]

Adds/subtracts mass of electrons in-place. such that the charge increases by the specified amount.

Parameters:charge (integer) – number of electrons to add
intensities
Returns:peak intensities
Return type:list of floats
masses
Returns:peak masses
Return type:list of floats
size
Returns:number of peaks in the spectrum
Return type:int
sortByIntensity()[source]
sortByMass()[source]
sortedByIntensity()[source]
sortedByMass()[source]
trim(n_peaks)[source]

Sorts mass and intensities arrays in descending intensity order, then removes low-intensity peaks from the spectrum.

Parameters:n_peaks – number of peaks to keep
class cpyMSpec.spectrum.TheoreticalSpectrum[source]

Bases: cpyMSpec.spectrum.SpectrumBase

A bag of isotopic peaks computed for a single or multiple sum formulas.

centroids(instrument, min_abundance=0.0001, points_per_fwhm=25)[source]

Estimates centroided peaks for a given instrument model.

Parameters:
  • instrument – instrument model
  • min_abundance – minimum abundance for including a peak
  • points_per_fwhm – grid density used for envelope calculation
Returns:

peaks visible with the instrument used

Return type:

TheoreticalSpectrum

copy()[source]
Returns:a (deep) copy of the instance
Return type:Spectrum
envelope(instrument)[source]

Computes isotopic envelope for a given instrument model

Parameters:instrument – instrument model to use
Returns:isotopic envelope as a function of mass
Return type:function float(mz: float)
cpyMSpec.spectrum.isotopePattern(sum_formula, threshold=0.0001, rel_threshold=True, desired_prob=None)[source]

Calculates isotopic peaks for a sum formula.

Parameters:
  • sum_formula (str) – text representation of an atomic composition
  • threshold (float) – minimum peak abundance
  • rel_threshold (bool) – if True, threshold is relative to the highest peak, otherwise it is a probability
  • desired_prob (float | None) – total probability covered by the result; if set, threshold parameter is ignored