pyms.Spectrum
¶
Classes to model Mass Spectra and Scans.
Classes:
|
Represents a composite mass spectrum. |
|
Models a binned mass spectrum. |
|
Generic object for a single Scan's raw data. |
Data:
Invariant |
|
Invariant |
|
Invariant |
Functions:
|
Convert the given numpy array to a numeric data type. |
|
Normalize the intensities in the given Mass Spectrum to values between |
-
class
CompositeMassSpectrum
(mass_list, intensity_list)[source]¶ Bases:
MassSpectrum
Represents a composite mass spectrum.
- Parameters:
- Author:
Dominic Davis-Foster
Methods:
__copy__
()Returns a copy of the object.
__eq__
(other)Return whether this object is equal to another object.
__len__
()Returns the length of the object.
crop
([min_mz, max_mz, inplace])Crop the Mass Spectrum between the given mz values.
dump
(file_name[, protocol])Dumps an object to a file through
pickle.dump()
.from_dict
(dictionary)Create a
Scan
from a dictionary.from_jcamp
(file_name)Create a MassSpectrum from a JCAMP-DX file.
from_mz_int_pairs
(mz_int_pairs)Construct a MassSpectrum from a list of (m/z, intensity) tuples.
from_spectra
(spectra)Construct a
CompositeMassSpectrum
from multipleMassSpectrum
objects.get_intensity_for_mass
(mass)Returns the intensity for the given mass.
get_mass_for_intensity
(intensity)Returns the mass for the given intensity.
icrop
([min_index, max_index, inplace])Crop the Mass Spectrum between the given indices.
Iterate over the peaks in the mass spectrum.
Returns the indices of the
n
largest peaks in the Mass Spectrum.Attributes:
Returns a copy of the intensity list.
Returns a list of the masses.
Returns the intensity list.
Returns the maximum m/z value in the spectrum.
Returns the minimum m/z value in the spectrum.
The number of mass spectra combined to create this composite spectrum.
-
__eq__
(other)¶ Return whether this object is equal to another object.
-
__len__
()¶ Returns the length of the object.
- Authors:
Andrew Isaac, Qiao Wang, Vladimir Likic
- Return type:
-
crop
(min_mz=None, max_mz=None, inplace=False)¶ Crop the Mass Spectrum between the given mz values.
- Parameters:
- Return type:
- Returns:
The cropped Mass Spectrum
-
dump
(file_name, protocol=3)¶ Dumps an object to a file through
pickle.dump()
.
-
classmethod
from_dict
(dictionary)¶ Create a
Scan
from a dictionary.The dictionary’s keys must match the arguments taken bt the class’s constructor.
-
classmethod
from_jcamp
(file_name)¶ Create a MassSpectrum from a JCAMP-DX file.
-
classmethod
from_mz_int_pairs
(mz_int_pairs)¶ Construct a MassSpectrum from a list of (m/z, intensity) tuples.
-
classmethod
from_spectra
(spectra)[source]¶ Construct a
CompositeMassSpectrum
from multipleMassSpectrum
objects.If no
MassSpectrum
objects are given an emptyCompositeMassSpectrum
is returned.- Parameters:
spectra (
Iterable
[MassSpectrum
])- Return type:
-
get_intensity_for_mass
(mass)¶ Returns the intensity for the given mass.
-
get_mass_for_intensity
(intensity)¶ Returns the mass for the given intensity. If more than one mass has the given intensity, the first mass is returned.
-
icrop
(min_index=0, max_index=-1, inplace=False)¶ Crop the Mass Spectrum between the given indices.
- Parameters:
- Return type:
- Returns:
The cropped Mass Spectrum
-
property
intensity_list
¶ Returns a copy of the intensity list.
- Authors:
Qiao Wang, Andrew Isaac, Vladimir Likic
- Return type:
-
iter_peaks
()¶ Iterate over the peaks in the mass spectrum.
-
property
mass_list
¶ Returns a list of the masses.
-
property
mass_spec
¶ Returns the intensity list.
- Authors:
Qiao Wang, Andrew Isaac, Vladimir Likic
- Return type:
-
property
max_mass
¶ Returns the maximum m/z value in the spectrum.
-
property
min_mass
¶ Returns the minimum m/z value in the spectrum.
-
n_largest_peaks
(n)¶ Returns the indices of the
n
largest peaks in the Mass Spectrum.
-
class
MassSpectrum
(mass_list, intensity_list)[source]¶ Bases:
Scan
Models a binned mass spectrum.
- Parameters:
- Authors:
Andrew Isaac, Qiao Wang, Vladimir Likic, Dominic Davis-Foster
Methods:
__copy__
()Returns a copy of the object.
__eq__
(other)Return whether this object is equal to another object.
__len__
()Returns the length of the object.
crop
([min_mz, max_mz, inplace])Crop the Mass Spectrum between the given mz values.
dump
(file_name[, protocol])Dumps an object to a file through
pickle.dump()
.from_dict
(dictionary)Create a
Scan
from a dictionary.from_jcamp
(file_name)Create a MassSpectrum from a JCAMP-DX file.
from_mz_int_pairs
(mz_int_pairs)Construct a MassSpectrum from a list of (m/z, intensity) tuples.
get_intensity_for_mass
(mass)Returns the intensity for the given mass.
get_mass_for_intensity
(intensity)Returns the mass for the given intensity.
icrop
([min_index, max_index, inplace])Crop the Mass Spectrum between the given indices.
Iterate over the peaks in the mass spectrum.
Returns the indices of the
n
largest peaks in the Mass Spectrum.Attributes:
Returns a copy of the intensity list.
Returns a list of the masses.
Returns the intensity list.
Returns the maximum m/z value in the spectrum.
Returns the minimum m/z value in the spectrum.
-
__eq__
(other)¶ Return whether this object is equal to another object.
-
__len__
()¶ Returns the length of the object.
- Authors:
Andrew Isaac, Qiao Wang, Vladimir Likic
- Return type:
-
crop
(min_mz=None, max_mz=None, inplace=False)[source]¶ Crop the Mass Spectrum between the given mz values.
- Parameters:
- Return type:
- Returns:
The cropped Mass Spectrum
-
dump
(file_name, protocol=3)¶ Dumps an object to a file through
pickle.dump()
.
-
classmethod
from_dict
(dictionary)¶ Create a
Scan
from a dictionary.The dictionary’s keys must match the arguments taken bt the class’s constructor.
-
classmethod
from_mz_int_pairs
(mz_int_pairs)[source]¶ Construct a MassSpectrum from a list of (m/z, intensity) tuples.
-
get_mass_for_intensity
(intensity)[source]¶ Returns the mass for the given intensity. If more than one mass has the given intensity, the first mass is returned.
-
icrop
(min_index=0, max_index=-1, inplace=False)[source]¶ Crop the Mass Spectrum between the given indices.
- Parameters:
- Return type:
- Returns:
The cropped Mass Spectrum
-
property
intensity_list
¶ Returns a copy of the intensity list.
- Authors:
Qiao Wang, Andrew Isaac, Vladimir Likic
- Return type:
-
iter_peaks
()¶ Iterate over the peaks in the mass spectrum.
-
property
mass_list
¶ Returns a list of the masses.
-
property
mass_spec
¶ Returns the intensity list.
- Authors:
Qiao Wang, Andrew Isaac, Vladimir Likic
- Return type:
-
property
max_mass
¶ Returns the maximum m/z value in the spectrum.
-
property
min_mass
¶ Returns the minimum m/z value in the spectrum.
-
class
Scan
(mass_list, intensity_list)[source]¶ Bases:
pymsBaseClass
,MassListMixin
Generic object for a single Scan’s raw data.
- Parameters:
- Authors:
Andrew Isaac, Qiao Wang, Vladimir Likic, Dominic Davis-Foster
Methods:
__copy__
()Returns a copy of the object.
__eq__
(other)Return whether this object is equal to another object.
__len__
()Returns the length of the object.
dump
(file_name[, protocol])Dumps an object to a file through
pickle.dump()
.from_dict
(dictionary)Create a
Scan
from a dictionary.Iterate over the peaks in the mass spectrum.
Attributes:
Returns a copy of the intensity list.
Returns a list of the masses.
Returns the intensity list.
Returns the maximum m/z value in the spectrum.
Returns the minimum m/z value in the spectrum.
-
__len__
()[source]¶ Returns the length of the object.
- Authors:
Andrew Isaac, Qiao Wang, Vladimir Likic
- Return type:
-
dump
(file_name, protocol=3)¶ Dumps an object to a file through
pickle.dump()
.
-
classmethod
from_dict
(dictionary)[source]¶ Create a
Scan
from a dictionary.The dictionary’s keys must match the arguments taken bt the class’s constructor.
-
property
intensity_list
¶ Returns a copy of the intensity list.
- Authors:
Qiao Wang, Andrew Isaac, Vladimir Likic
- Return type:
-
property
mass_list
¶ Returns a list of the masses.
-
property
mass_spec
¶ Returns the intensity list.
- Authors:
Qiao Wang, Andrew Isaac, Vladimir Likic
- Return type:
-
property
max_mass
¶ Returns the maximum m/z value in the spectrum.
-
_C
= TypeVar(_C, bound=CompositeMassSpectrum)¶ Type:
TypeVar
Invariant
TypeVar
bound topyms.Spectrum.CompositeMassSpectrum
.
-
_M
= TypeVar(_M, bound=MassSpectrum)¶ Type:
TypeVar
Invariant
TypeVar
bound topyms.Spectrum.MassSpectrum
.
-
_S
= TypeVar(_S, bound=Scan)¶ Type:
TypeVar
Invariant
TypeVar
bound topyms.Spectrum.Scan
.
-
array_as_numeric
(array)[source]¶ Convert the given numpy array to a numeric data type.
If the data in the array is already in a numeric data type no changes will be made.
If
array
is a pythonSequence
then it will first be converted to a numpy array.
-
normalize_mass_spec
(mass_spec, relative_to=None, inplace=False, max_intensity=100)[source]¶ Normalize the intensities in the given Mass Spectrum to values between
0
andmax_intensity
, which by default is100.0
.- Parameters:
mass_spec (
MassSpectrum
) – The Mass Spectrum to normalizerelative_to (
Optional
[float
]) – The largest intensity in the original data set. If not None the intensities are computed relative to this value. If None the value is calculated from the mass spectrum. This can be useful when normalizing several mass spectra to each other. DefaultNone
.inplace (
bool
) – Whether the normalization should be applied to theMassSpectrum
object given, or to a copy (default behaviour). DefaultFalse
.max_intensity (
float
) – The maximum intensity in the normalized spectrum. If omitted the range 0-100.0 is used. If an integer the normalized intensities will be integers. Default100
.
- Return type:
- Returns:
The normalized mass spectrum