imspy.data package¶
Submodules¶
imspy.data.peptide module¶
- class imspy.data.peptide.PeptideIon(sequence, charge, intensity, peptide_id=None)¶
Bases:
RustWrapperObject
- property atomic_composition¶
- calculate_isotopic_spectrum(mass_tolerance=0.001, abundance_threshold=1e-08, max_result=200, intensity_min=0.0001)¶
Calculate the isotopic spectrum of the peptide ion.
- Parameters:
mass_tolerance (
float
) – The mass tolerance for the isotopic spectrum calculation.abundance_threshold (
float
) – The abundance threshold for the isotopic spectrum calculation.max_result (
int
) – The maximum number of results to return.intensity_min (
float
) – The minimum intensity of the isotopic spectrum.
- Return type:
- Returns:
The isotopic spectrum of the peptide ion.
- calculate_isotopic_spectrum_annotated(mass_tolerance=0.001, abundance_threshold=1e-08, max_result=200, intensity_min=0.0001)¶
Calculate the isotopic spectrum of the peptide ion.
- Parameters:
mass_tolerance (
float
) – The mass tolerance for the isotopic spectrum calculation.abundance_threshold (
float
) – The abundance threshold for the isotopic spectrum calculation.max_result (
int
) – The maximum number of results to return.intensity_min (
float
) – The minimum intensity of the isotopic spectrum.
- Return type:
- Returns:
The isotopic spectrum of the peptide ion.
- property charge: int¶
- classmethod from_py_ptr(ion)¶
- get_py_ptr()¶
- property intensity: float¶
- property mz: float¶
- property peptide_id: None | int¶
- property sequence: PeptideSequence¶
- to_json()¶
- Return type:
str
- class imspy.data.peptide.PeptideProductIon(kind, sequence, charge=1, intensity=1.0, peptide_id=None)¶
Bases:
RustWrapperObject
- atomic_composition()¶
- property charge: int¶
- classmethod from_py_ptr(product_ion)¶
- get_py_ptr()¶
- property intensity: float¶
- isotope_distribution(mass_tolerance=0.001, abundance_threshold=1e-08, max_result=200, intensity_min=0.0001)¶
Calculate the isotope distribution of the product ion.
- Parameters:
mass_tolerance (
float
) – The mass tolerance for the isotope distribution calculation.abundance_threshold (
float
) – The abundance threshold for the isotope distribution calculation.max_result (
int
) – The maximum number of results to return.intensity_min (
float
) – The minimum intensity of the isotope distribution.
- Return type:
List
[Tuple
[float
,float
]]- Returns:
The isotope distribution of the product ion.
- property kind: str¶
- property mono_isotopic_mass: float¶
- property mz: float¶
- property sequence: str¶
- to_json()¶
- Return type:
str
- class imspy.data.peptide.PeptideProductIonSeries(charge, n_ions, c_ions)¶
Bases:
RustWrapperObject
- property c_ions: List[PeptideProductIon]¶
- property charge: int¶
- classmethod from_py_ptr(series)¶
- get_py_ptr()¶
- property n_ions: List[PeptideProductIon]¶
- to_json()¶
- Return type:
str
- class imspy.data.peptide.PeptideProductIonSeriesCollection(series)¶
Bases:
RustWrapperObject
- find_series(charge)¶
Find the product ion series with the given charge.
- Parameters:
charge (
int
) – The charge of the product ion series.- Return type:
Optional
[PeptideProductIonSeries
]- Returns:
The product ion series with the given charge, or None if not found.
- classmethod from_py_ptr(collection)¶
- generate_isotopic_spectrum(mass_tolerance=0.001, abundance_threshold=1e-06, max_result=2000, intensity_min=1e-06)¶
Calculate the isotope distribution of the product ion series collection.
- Parameters:
mass_tolerance (
float
) – The mass tolerance for the isotope distribution calculation.abundance_threshold (
float
) – The abundance threshold for the isotope distribution calculation.max_result (
int
) – The maximum number of results to return.intensity_min (
float
) – The minimum intensity of the isotope distribution.
- Return type:
- Returns:
The isotope distribution of the product ion series collection.
- generate_isotopic_spectrum_annotated(mass_tolerance=0.001, abundance_threshold=1e-06, max_result=2000, intensity_min=1e-06)¶
Calculate the isotope distribution of the product ion series collection.
- Parameters:
mass_tolerance (
float
) – The mass tolerance for the isotope distribution calculation.abundance_threshold (
float
) – The abundance threshold for the isotope distribution calculation.max_result (
int
) – The maximum number of results to return.intensity_min (
float
) – The minimum intensity of the isotope distribution.
- Return type:
- Returns:
The isotope distribution of the product ion series collection.
- get_py_ptr()¶
- property series: List[PeptideProductIonSeries]¶
- to_json()¶
- Return type:
str
- class imspy.data.peptide.PeptideSequence(sequence, peptide_id=None)¶
Bases:
RustWrapperObject
- property amino_acid_count: int¶
- associate_fragment_ion_series_with_prosit_intensities(flat_intensities, charge, fragment_type='b', normalize=True, half_charge_one=True)¶
Associate the peptide sequence with predicted intensities from Prosit intensity prediction.
- Parameters:
flat_intensities (
List
[float
]) – The flat intensities.TODO (#) – check how charge should be handled
charge (
int
) – The charge of the product ions.fragment_type (
str
) – The type of the product ions, must be one of ‘a’, ‘b’, ‘c’, ‘x’, ‘y’, ‘z’.normalize (
bool
) – Whether to normalize the intensities.half_charge_one (
bool
) – Whether to use half charge one.
- Return type:
- Returns:
The b and y product ion series of the peptide sequence.
- property atomic_composition¶
- calculate_isotopic_product_ion_spectrum_annotated(charge=1, fragment_type='b', mass_tolerance=0.001, abundance_threshold=1e-08, max_result=200, intensity_min=0.0001)¶
Calculate the isotopic product ion spectrum of the peptide sequence.
- Parameters:
intensity_min (
float
)max_result (
int
)abundance_threshold (
float
)mass_tolerance (
float
)charge (
int
) – The charge of the product ions.fragment_type (
str
) – The type of the product ions, must be one of ‘a’, ‘b’, ‘c’, ‘x’, ‘y’, ‘z’.
- Return type:
- Returns:
The isotopic product ion spectrum of the peptide sequence.
- calculate_mono_isotopic_product_ion_spectrum(charge=1, fragment_type='b')¶
Calculate the mono-isotopic product ion spectrum of the peptide sequence.
- Parameters:
charge (
int
) – The charge of the product ions.fragment_type (
str
) – The type of the product ions, must be one of ‘a’, ‘b’, ‘c’, ‘x’, ‘y’, ‘z’.
- Return type:
- Returns:
The mono-isotopic product ion spectrum of the peptide sequence.
- calculate_mono_isotopic_product_ion_spectrum_annotated(charge=1, fragment_type='b')¶
Calculate the mono-isotopic product ion spectrum of the peptide sequence.
- Parameters:
charge (
int
) – The charge of the product ions.fragment_type (
str
) – The type of the product ions, must be one of ‘a’, ‘b’, ‘c’, ‘x’, ‘y’, ‘z’.
- Return type:
- Returns:
The mono-isotopic product ion spectrum of the peptide sequence.
- calculate_product_ion_series(charge=1, fragment_type='b')¶
Calculate the b and y product ion series of the peptide sequence.
- Parameters:
charge (
int
) – The charge of the product ions.fragment_type (
str
) – The type of the product ions, must be one of ‘a’, ‘b’, ‘c’, ‘x’, ‘y’, ‘z’.
- Return type:
Tuple
[List
[PeptideProductIon
],List
[PeptideProductIon
]]- Returns:
The b and y product ion series of the peptide sequence.
- classmethod from_py_ptr(obj)¶
- get_py_ptr()¶
- property mono_isotopic_mass: float¶
- property peptide_id: None | int¶
- property sequence: str¶
- to_json()¶
- Return type:
str
- to_sage_representation()¶
- Return type:
Tuple
[str
,List
[float
]]
- to_tokens(group_modifications=True)¶
- Return type:
List
[str
]
imspy.data.spectrum module¶
- class imspy.data.spectrum.IndexedMzSpectrum(index, mz, intensity)¶
Bases:
RustWrapperObject
- property df: DataFrame¶
Data.
- Returns:
Data.
- Return type:
pd.DataFrame
- filter(mz_min=0.0, mz_max=2000.0, intensity_min=0.0, intensity_max=1000000000.0)¶
Filter the spectrum for a given m/z range and intensity range.
- Parameters:
mz_min (float) – Minimum m/z value.
mz_max (float) – Maximum m/z value.
intensity_min (float, optional) – Minimum intensity value. Defaults to 0.0.
intensity_max (float, optional) – Maximum intensity value. Defaults to 1e9.
- Returns:
Filtered spectrum.
- Return type:
- classmethod from_py_ptr(spec)¶
Create a IndexedMzSpectrum from a PyIndexedMzSpectrum.
- Parameters:
spec (pims.PyIndexedMzSpectrum) – PyIndexedMzSpectrum to create the IndexedMzSpectrum from.
- Returns:
IndexedMzSpectrum created from the PyIndexedMzSpectrum.
- Return type:
- get_py_ptr()¶
Get the spec_ptr.
- Returns:
spec_ptr.
- Return type:
pims.PyIndexedMzSpectrum
- property index: ndarray[Any, dtype[int32]]¶
Index.
- Returns:
Index.
- Return type:
NDArray[np.int32]
- property intensity: ndarray[Any, dtype[float64]]¶
Intensity.
- Returns:
Intensity.
- Return type:
NDArray[np.float64]
- property mz: ndarray[Any, dtype[float64]]¶
m/z.
- Returns:
m/z.
- Return type:
NDArray[np.float64]
- class imspy.data.spectrum.MzSpectrum(mz, intensity)¶
Bases:
RustWrapperObject
- add_mz_noise_normal(noise_ppm)¶
Add normal noise to the intensity values of the spectrum.
- Parameters:
noise_ppm (float) – Noise ppm, noise will be sampled from a normal distribution with mean 0 and std noise_ppm / 3.0.
- Returns:
Spectrum with added noise.
- Return type:
- add_mz_noise_uniform(noise_ppm, right_drag=False)¶
Add uniform noise to the m/z values of the spectrum.
- Parameters:
noise_ppm (float) – Noise ppm, noise will be sampled from a uniform distribution with mean 0 and std noise_ppm.
right_drag (bool, optional) – If true, the noise will be shifted to the right. Defaults to False.
- Returns:
Spectrum with added noise.
- Return type:
- property df: DataFrame¶
Data.
- Returns:
Data.
- Return type:
pd.DataFrame
- filter(mz_min=0.0, mz_max=2000.0, intensity_min=0.0, intensity_max=1000000000.0)¶
Filter the spectrum for a given m/z range and intensity range.
- Parameters:
mz_min (float) – Minimum m/z value.
mz_max (float) – Maximum m/z value.
intensity_min (float, optional) – Minimum intensity value. Defaults to 0.0.
intensity_max (float, optional) – Maximum intensity value. Defaults to 1e9.
- Returns:
Filtered spectrum.
- Return type:
- classmethod from_jsons(jsons)¶
- Return type:
- classmethod from_mz_spectra_list(spectra_list, resolution)¶
Generates a convoluted mass spectrum by adding all spectra in the given list.
- Parameters:
spectra_list (List[MzSpectrum]) – List of mass spectra.
resolution (int) – Desired resolution of returned spectrum.
- Returns:
Convoluted spectrum.
- Return type:
- classmethod from_py_ptr(spec)¶
Create a MzSpectrum from a PyMzSpectrum.
- Parameters:
spec (pims.PyMzSpectrum) – PyMzSpectrum to create the MzSpectrum from.
- Returns:
MzSpectrum created from the PyMzSpectrum.
- Return type:
- get_py_ptr()¶
Get the spec_ptr.
- Returns:
spec_ptr.
- Return type:
pims.PyMzSpectrum
- property intensity: ndarray[Any, dtype[float64]]¶
Intensity.
- Returns:
Intensity.
- Return type:
NDArray[np.float64]
- property mz: ndarray[Any, dtype[float64]]¶
m/z.
- Returns:
m/z.
- Return type:
NDArray[np.float64]
- to_centroided(baseline_noise_level=0.0, sigma=0.1, normalize=True)¶
Convert the spectrum to a centroided spectrum.
- Returns:
Centroided spectrum.
- Return type:
- to_jsons()¶
generates json string representation of MzSpectrum
- Return type:
str
- to_resolution(resolution)¶
Bins the spectrum’s m/z values to a given resolution and sums the intensities.
- Parameters:
resolution (int) – Negative decadic logarithm of bin size.
- Returns:
A new MzSpectrum where m/z values are binned according to the given resolution.
- Return type:
- to_windows(window_length=10, overlapping=True, min_num_peaks=5, min_intensity=1)¶
Convert the spectrum to a list of windows.
- Parameters:
window_length (float, optional) – Window length. Defaults to 10.
overlapping (bool, optional) – Whether the windows should overlap. Defaults to True.
min_num_peaks (int, optional) – Minimum number of peaks in a window. Defaults to 5.
min_intensity (float, optional) – Minimum intensity of a peak in a window. Defaults to 1.
- Returns:
List of windows.
- Return type:
Tuple[NDArray, List[MzSpectrum]]
- vectorized(resolution=2)¶
Convert the spectrum to a vectorized spectrum.
- Parameters:
resolution (int, optional) – Resolution. Defaults to 2.
- Returns:
Vectorized spectrum.
- Return type:
- class imspy.data.spectrum.MzSpectrumVectorized(indices, values, resolution)¶
Bases:
RustWrapperObject
- classmethod from_py_ptr(spec)¶
Create a MzSpectrum from a PyMzSpectrum.
- Parameters:
spec (pims.PyMzSpectrum) – PyMzSpectrum to create the MzSpectrum from.
- Returns:
MzSpectrum created from the PyMzSpectrum.
- Return type:
- get_py_ptr()¶
Get the spec_ptr.
- Returns:
spec_ptr.
- Return type:
pims.PyMzSpectrumVectorized
- property indices: ndarray[Any, dtype[int32]]¶
m/z.
- Returns:
m/z.
- Return type:
NDArray[np.float64]
- property resolution: float¶
Resolution.
- Returns:
Resolution.
- Return type:
float
- to_centroided(integrate_method=<function get_peak_integral>)¶
Convert the spectrum to a centroided spectrum.
- Returns:
Centroided spectrum.
- Return type:
- property values: ndarray[Any, dtype[float64]]¶
Intensity.
- Returns:
Intensity.
- Return type:
NDArray[np.float64]
- class imspy.data.spectrum.TimsSpectrum(frame_id, scan, retention_time, mobility, ms_type, index, mz, intensity)¶
Bases:
RustWrapperObject
- property df: DataFrame¶
Data.
- Returns:
Data.
- Return type:
pd.DataFrame
- filter(mz_min=0.0, mz_max=2000.0, intensity_min=0.0, intensity_max=1000000000.0)¶
Filter the spectrum for a given m/z range and intensity range.
- Parameters:
mz_min (float) – Minimum m/z value.
mz_max (float) – Maximum m/z value.
intensity_min (float, optional) – Minimum intensity value. Defaults to 0.0.
intensity_max (float, optional) – Maximum intensity value. Defaults to 1e9.
- Returns:
Filtered spectrum.
- Return type:
- property frame_id: int¶
Frame ID.
- Returns:
Frame ID.
- Return type:
int
- classmethod from_py_ptr(spec)¶
Create a TimsSpectrum from a PyTimsSpectrum.
- Parameters:
spec (pims.PyTimsSpectrum) – PyTimsSpectrum to create the TimsSpectrum from.
- Returns:
TimsSpectrum created from the PyTimsSpectrum.
- Return type:
- get_py_ptr()¶
Get the spec_ptr.
- Returns:
spec_ptr.
- Return type:
pims.PyTimsSpectrum
- property index: ndarray[Any, dtype[int32]]¶
Index.
- Returns:
Index.
- Return type:
NDArray[np.int32]
- property intensity: ndarray[Any, dtype[float64]]¶
Intensity.
- Returns:
Intensity.
- Return type:
NDArray[np.float64]
- property mobility: float¶
Inverse mobility.
- Returns:
Inverse mobility.
- Return type:
float
- property ms_type: str¶
MS type.
- Returns:
MS type.
- Return type:
str
- property mz: ndarray[Any, dtype[float64]]¶
m/z.
- Returns:
m/z.
- Return type:
NDArray[np.float64]
- property mz_spectrum: MzSpectrum¶
Get the MzSpectrum.
- Returns:
Spectrum.
- Return type:
- property retention_time: float¶
Retention time.
- Returns:
Retention time.
- Return type:
float
- property scan: int¶
Scan.
- Returns:
Scan.
- Return type:
int
- imspy.data.spectrum.get_peak_integral(peaks, peak_info)¶
Calculates the integral of the peaks in a spectrum.
- Parameters:
peaks (NDArray[np.int32]) – Peak indices.
peak_info (dict) – Peak info.
- Returns:
Peak integrals.
- Return type:
NDArray[np.float64]