imspy-core 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- imspy_core/__init__.py +75 -0
- imspy_core/chemistry/__init__.py +37 -0
- imspy_core/chemistry/amino_acids.py +7 -0
- imspy_core/chemistry/constants.py +12 -0
- imspy_core/chemistry/elements.py +6 -0
- imspy_core/chemistry/mobility.py +82 -0
- imspy_core/chemistry/sum_formula.py +38 -0
- imspy_core/chemistry/unimod.py +5 -0
- imspy_core/chemistry/utility.py +43 -0
- imspy_core/core/__init__.py +9 -0
- imspy_core/core/base.py +38 -0
- imspy_core/data/__init__.py +17 -0
- imspy_core/data/peptide.py +528 -0
- imspy_core/data/spectrum.py +586 -0
- imspy_core/timstof/__init__.py +25 -0
- imspy_core/timstof/collision.py +31 -0
- imspy_core/timstof/data.py +429 -0
- imspy_core/timstof/dda.py +364 -0
- imspy_core/timstof/dia.py +131 -0
- imspy_core/timstof/frame.py +604 -0
- imspy_core/timstof/quadrupole.py +189 -0
- imspy_core/timstof/slice.py +506 -0
- imspy_core/utility/__init__.py +21 -0
- imspy_core/utility/sequence.py +38 -0
- imspy_core/utility/utilities.py +278 -0
- imspy_core-0.4.0.dist-info/METADATA +70 -0
- imspy_core-0.4.0.dist-info/RECORD +28 -0
- imspy_core-0.4.0.dist-info/WHEEL +4 -0
imspy_core/__init__.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
imspy_core - Core data structures and utilities for processing timsTOF ion mobility spectrometry data.
|
|
3
|
+
|
|
4
|
+
This package provides the foundational components for working with timsTOF data:
|
|
5
|
+
- Data structures for spectra and peptides
|
|
6
|
+
- Chemistry utilities (elements, amino acids, UNIMOD)
|
|
7
|
+
- TimsTOF dataset readers (DDA and DIA)
|
|
8
|
+
- General utilities
|
|
9
|
+
|
|
10
|
+
For ML-based predictions, install imspy-predictors.
|
|
11
|
+
For database search functionality, install imspy-search.
|
|
12
|
+
For simulation tools, install imspy-simulation.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
__version__ = "0.4.0"
|
|
16
|
+
|
|
17
|
+
# Core base classes
|
|
18
|
+
from imspy_core.core import RustWrapperObject
|
|
19
|
+
|
|
20
|
+
# Data structures
|
|
21
|
+
from imspy_core.data import (
|
|
22
|
+
MzSpectrum, IndexedMzSpectrum, MzSpectrumVectorized, TimsSpectrum,
|
|
23
|
+
PeptideSequence, PeptideIon, PeptideProductIon,
|
|
24
|
+
PeptideProductIonSeries, PeptideProductIonSeriesCollection
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# Chemistry
|
|
28
|
+
from imspy_core.chemistry import (
|
|
29
|
+
MASS_PROTON, MASS_NEUTRON, MASS_ELECTRON, MASS_WATER,
|
|
30
|
+
AMINO_ACID_MASSES, AMINO_ACIDS,
|
|
31
|
+
UNIMOD_MASSES,
|
|
32
|
+
one_over_k0_to_ccs, ccs_to_one_over_k0,
|
|
33
|
+
SumFormula, calculate_mz
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# TimsTOF
|
|
37
|
+
from imspy_core.timstof import (
|
|
38
|
+
TimsDataset, AcquisitionMode,
|
|
39
|
+
TimsFrame, TimsFrameVectorized,
|
|
40
|
+
TimsSlice, TimsSliceVectorized,
|
|
41
|
+
TimsDatasetDDA, PrecursorDDA, FragmentDDA,
|
|
42
|
+
TimsDatasetDIA,
|
|
43
|
+
TimsTofQuadrupoleDDA, TimsTofQuadrupoleDIA
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# Utility
|
|
47
|
+
from imspy_core.utility import (
|
|
48
|
+
re_index_indices, tokenize_unimod_sequence
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
__all__ = [
|
|
52
|
+
# Version
|
|
53
|
+
'__version__',
|
|
54
|
+
# Core
|
|
55
|
+
'RustWrapperObject',
|
|
56
|
+
# Data
|
|
57
|
+
'MzSpectrum', 'IndexedMzSpectrum', 'MzSpectrumVectorized', 'TimsSpectrum',
|
|
58
|
+
'PeptideSequence', 'PeptideIon', 'PeptideProductIon',
|
|
59
|
+
'PeptideProductIonSeries', 'PeptideProductIonSeriesCollection',
|
|
60
|
+
# Chemistry
|
|
61
|
+
'MASS_PROTON', 'MASS_NEUTRON', 'MASS_ELECTRON', 'MASS_WATER',
|
|
62
|
+
'AMINO_ACID_MASSES', 'AMINO_ACIDS',
|
|
63
|
+
'UNIMOD_MASSES',
|
|
64
|
+
'one_over_k0_to_ccs', 'ccs_to_one_over_k0',
|
|
65
|
+
'SumFormula', 'calculate_mz',
|
|
66
|
+
# TimsTOF
|
|
67
|
+
'TimsDataset', 'AcquisitionMode',
|
|
68
|
+
'TimsFrame', 'TimsFrameVectorized',
|
|
69
|
+
'TimsSlice', 'TimsSliceVectorized',
|
|
70
|
+
'TimsDatasetDDA', 'PrecursorDDA', 'FragmentDDA',
|
|
71
|
+
'TimsDatasetDIA',
|
|
72
|
+
'TimsTofQuadrupoleDDA', 'TimsTofQuadrupoleDIA',
|
|
73
|
+
# Utility
|
|
74
|
+
're_index_indices', 'tokenize_unimod_sequence',
|
|
75
|
+
]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Chemistry module for imspy_core.
|
|
3
|
+
|
|
4
|
+
Contains elements, amino acids, UNIMOD, mobility functions, and sum formulas.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .constants import (
|
|
8
|
+
MASS_PROTON, MASS_NEUTRON, MASS_ELECTRON, MASS_WATER,
|
|
9
|
+
STANDARD_TEMPERATURE, STANDARD_PRESSURE, ELEMENTARY_CHARGE,
|
|
10
|
+
K_BOLTZMANN, AVOGADRO_NUMBER
|
|
11
|
+
)
|
|
12
|
+
from .elements import (
|
|
13
|
+
ELEMENTAL_MONO_ISOTOPIC_MASSES, ELEMENTAL_ISOTOPIC_MASSES,
|
|
14
|
+
ELEMENTAL_ISOTOPIC_ABUNDANCES
|
|
15
|
+
)
|
|
16
|
+
from .amino_acids import AMINO_ACID_MASSES, AMINO_ACIDS, AMINO_ACID_ATOMIC_COMPOSITIONS
|
|
17
|
+
from .unimod import UNIMOD_MASSES, UNIMOD_ATOMIC_COMPOSITIONS
|
|
18
|
+
from .mobility import (
|
|
19
|
+
one_over_k0_to_ccs, ccs_to_one_over_k0,
|
|
20
|
+
ccs_to_one_over_k0_par, one_over_k0_to_ccs_par
|
|
21
|
+
)
|
|
22
|
+
from .sum_formula import SumFormula
|
|
23
|
+
from .utility import calculate_mz, calculate_transmission_dependent_fragment_ion_isotope_distribution
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
'MASS_PROTON', 'MASS_NEUTRON', 'MASS_ELECTRON', 'MASS_WATER',
|
|
27
|
+
'STANDARD_TEMPERATURE', 'STANDARD_PRESSURE', 'ELEMENTARY_CHARGE',
|
|
28
|
+
'K_BOLTZMANN', 'AVOGADRO_NUMBER',
|
|
29
|
+
'ELEMENTAL_MONO_ISOTOPIC_MASSES', 'ELEMENTAL_ISOTOPIC_MASSES',
|
|
30
|
+
'ELEMENTAL_ISOTOPIC_ABUNDANCES',
|
|
31
|
+
'AMINO_ACID_MASSES', 'AMINO_ACIDS', 'AMINO_ACID_ATOMIC_COMPOSITIONS',
|
|
32
|
+
'UNIMOD_MASSES', 'UNIMOD_ATOMIC_COMPOSITIONS',
|
|
33
|
+
'one_over_k0_to_ccs', 'ccs_to_one_over_k0',
|
|
34
|
+
'ccs_to_one_over_k0_par', 'one_over_k0_to_ccs_par',
|
|
35
|
+
'SumFormula',
|
|
36
|
+
'calculate_mz', 'calculate_transmission_dependent_fragment_ion_isotope_distribution'
|
|
37
|
+
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import imspy_connector
|
|
2
|
+
ims = imspy_connector.py_constants
|
|
3
|
+
|
|
4
|
+
MASS_PROTON = ims.mass_proton()
|
|
5
|
+
MASS_NEUTRON = ims.mass_neutron()
|
|
6
|
+
MASS_ELECTRON = ims.mass_electron()
|
|
7
|
+
MASS_WATER = ims.mass_water()
|
|
8
|
+
STANDARD_TEMPERATURE = ims.standard_temperature()
|
|
9
|
+
STANDARD_PRESSURE = ims.standard_pressure()
|
|
10
|
+
ELEMENTARY_CHARGE = ims.elementary_charge()
|
|
11
|
+
K_BOLTZMANN = ims.k_boltzmann()
|
|
12
|
+
AVOGADRO_NUMBER = ims.avogadro()
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import imspy_connector
|
|
2
|
+
ims = imspy_connector.py_elements
|
|
3
|
+
|
|
4
|
+
ELEMENTAL_MONO_ISOTOPIC_MASSES = ims.get_elemental_mono_isotopic_weight_map()
|
|
5
|
+
ELEMENTAL_ISOTOPIC_MASSES = ims.get_elemental_isotope_weight_map()
|
|
6
|
+
ELEMENTAL_ISOTOPIC_ABUNDANCES = ims.get_elemental_isotope_abundance_map()
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from numpy.typing import NDArray
|
|
3
|
+
import imspy_connector
|
|
4
|
+
ims = imspy_connector.py_chemistry
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def one_over_k0_to_ccs(one_over_k0, mz, charge, mass_gas=28.013, temp=31.85, t_diff=273.15):
|
|
8
|
+
"""Convert reduced ion mobility (1/k0) to CCS.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
one_over_k0: reduced ion mobility
|
|
12
|
+
mz: mass-over-charge of the ion
|
|
13
|
+
charge: charge state of the ion
|
|
14
|
+
mass_gas: mass of drift gas
|
|
15
|
+
temp: temperature of the drift gas in C°
|
|
16
|
+
t_diff: factor to translate from C° to K
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
float: collision cross-section
|
|
20
|
+
"""
|
|
21
|
+
return ims.one_over_reduced_mobility_to_ccs(one_over_k0, mz, charge, mass_gas, temp, t_diff)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def ccs_to_one_over_k0(ccs, mz, charge, mass_gas=28.013, temp=31.85, t_diff=273.15):
|
|
25
|
+
"""Convert CCS to reduced ion mobility (1/k0).
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
ccs: collision cross-section
|
|
29
|
+
mz: mass-over-charge of the ion
|
|
30
|
+
charge: charge state of the ion
|
|
31
|
+
mass_gas: mass of drift gas
|
|
32
|
+
temp: temperature of the drift gas in C°
|
|
33
|
+
t_diff: factor to translate from C° to K
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
float: reduced ion mobility
|
|
37
|
+
"""
|
|
38
|
+
return ims.ccs_to_one_over_reduced_mobility(ccs, mz, charge, mass_gas, temp, t_diff)
|
|
39
|
+
|
|
40
|
+
def ccs_to_one_over_k0_par(ccs: NDArray, mz: NDArray, charge: NDArray, mass_gas: float = 28.013, temp: float = 31.85,
|
|
41
|
+
t_diff: float = 273.15, num_threads: int = -1) -> NDArray:
|
|
42
|
+
"""Convert CCS to reduced ion mobility (1/k0) in parallel.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
ccs: collision cross-section
|
|
46
|
+
mz: mass-over-charge of the ion
|
|
47
|
+
charge: charge state of the ion
|
|
48
|
+
mass_gas: mass of drift gas
|
|
49
|
+
temp: temperature of the drift gas in C°
|
|
50
|
+
t_diff: factor to translate from C° to K
|
|
51
|
+
num_threads: number of threads
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
NDArray: reduced ion mobility
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
if num_threads == -1:
|
|
58
|
+
num_threads = os.cpu_count()
|
|
59
|
+
|
|
60
|
+
return ims.ccs_to_one_over_reduced_mobility_par(ccs, mz, charge, mass_gas, temp, t_diff, num_threads)
|
|
61
|
+
|
|
62
|
+
def one_over_k0_to_ccs_par(one_over_k0: NDArray, mz: NDArray, charge: NDArray, mass_gas: float = 28.013, temp: float = 31.85,
|
|
63
|
+
t_diff: float = 273.15, num_threads: int = -1) -> NDArray:
|
|
64
|
+
"""Convert reduced ion mobility (1/k0) to CCS in parallel.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
one_over_k0: reduced ion mobility
|
|
68
|
+
mz: mass-over-charge of the ion
|
|
69
|
+
charge: charge state of the ion
|
|
70
|
+
mass_gas: mass of drift gas
|
|
71
|
+
temp: temperature of the drift gas in C°
|
|
72
|
+
t_diff: factor to translate from C° to K
|
|
73
|
+
num_threads: number of threads
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
NDArray: collision cross-section
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
if num_threads == -1:
|
|
80
|
+
num_threads = os.cpu_count()
|
|
81
|
+
|
|
82
|
+
return ims.one_over_reduced_mobility_to_ccs_par(one_over_k0, mz, charge, mass_gas, temp, t_diff, num_threads)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import imspy_connector
|
|
2
|
+
|
|
3
|
+
from imspy_core.data.spectrum import MzSpectrum
|
|
4
|
+
from imspy_core.core.base import RustWrapperObject
|
|
5
|
+
|
|
6
|
+
ims = imspy_connector.py_sum_formula
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SumFormula(RustWrapperObject):
|
|
10
|
+
def __init__(self, sum_formula: str):
|
|
11
|
+
self.__ptr = ims.PySumFormula(sum_formula)
|
|
12
|
+
|
|
13
|
+
@property
|
|
14
|
+
def formula(self) -> str:
|
|
15
|
+
return self.__ptr.formula
|
|
16
|
+
|
|
17
|
+
@property
|
|
18
|
+
def formula_dict(self) -> dict:
|
|
19
|
+
return self.__ptr.elements
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def monoisotopic_mass(self) -> float:
|
|
23
|
+
return self.__ptr.monoisotopic_mass
|
|
24
|
+
|
|
25
|
+
def __repr__(self):
|
|
26
|
+
return f"SumFormula('{self.formula}')"
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def from_py_ptr(cls, py_ptr):
|
|
30
|
+
instance = cls.__new__(cls)
|
|
31
|
+
instance.__ptr = py_ptr
|
|
32
|
+
return instance
|
|
33
|
+
|
|
34
|
+
def get_py_ptr(self):
|
|
35
|
+
return self.__ptr
|
|
36
|
+
|
|
37
|
+
def generate_isotope_distribution(self, charge: int) -> 'MzSpectrum':
|
|
38
|
+
return MzSpectrum.from_py_ptr(self.__ptr.generate_isotope_distribution(charge))
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import imspy_connector
|
|
2
|
+
|
|
3
|
+
from imspy_core.data.spectrum import MzSpectrum
|
|
4
|
+
|
|
5
|
+
ims = imspy_connector.py_chemistry
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def calculate_mz(mass: float, charge: int) -> float:
|
|
9
|
+
"""Calculate m/z value.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
mass (float): Mass.
|
|
13
|
+
charge (int): Charge.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
float: m/z value.
|
|
17
|
+
"""
|
|
18
|
+
return ims.calculate_mz(mass, charge)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def calculate_transmission_dependent_fragment_ion_isotope_distribution(
|
|
22
|
+
target_spec: MzSpectrum,
|
|
23
|
+
complement_spec: MzSpectrum,
|
|
24
|
+
transmitted_isotopes: MzSpectrum,
|
|
25
|
+
max_isotope: int) -> MzSpectrum:
|
|
26
|
+
"""Calculate transmission dependent fragment ion isotope distribution.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
target_spec (MzSpectrum): Target spectrum.
|
|
30
|
+
complement_spec (MzSpectrum): Complement spectrum.
|
|
31
|
+
transmitted_isotopes (MzSpectrum): Transmitted isotopes.
|
|
32
|
+
max_isotope (int): Maximum isotope.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
MzSpectrum: Transmission dependent fragment ion isotope distribution.
|
|
36
|
+
"""
|
|
37
|
+
return MzSpectrum.from_py_ptr(
|
|
38
|
+
ims.calculate_transmission_dependent_fragment_ion_isotope_distribution(
|
|
39
|
+
target_spec.get_py_ptr(),
|
|
40
|
+
complement_spec.get_py_ptr(),
|
|
41
|
+
transmitted_isotopes.get_py_ptr(), max_isotope
|
|
42
|
+
)
|
|
43
|
+
)
|
imspy_core/core/base.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Base classes for imspy_core.
|
|
3
|
+
|
|
4
|
+
This module contains base classes used across the package,
|
|
5
|
+
separated to avoid circular imports.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from abc import ABC, abstractmethod
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class RustWrapperObject(ABC):
|
|
12
|
+
"""Abstract base class for Python wrappers around Rust objects.
|
|
13
|
+
|
|
14
|
+
All classes that wrap PyO3 Rust objects should inherit from this
|
|
15
|
+
and implement from_py_ptr and get_py_ptr methods.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
@classmethod
|
|
19
|
+
@abstractmethod
|
|
20
|
+
def from_py_ptr(cls, obj):
|
|
21
|
+
"""Create a Python wrapper from a PyO3 pointer.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
obj: The PyO3 Rust object pointer.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
An instance of the wrapper class.
|
|
28
|
+
"""
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
@abstractmethod
|
|
32
|
+
def get_py_ptr(self):
|
|
33
|
+
"""Get the underlying PyO3 Rust object pointer.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
The PyO3 Rust object pointer.
|
|
37
|
+
"""
|
|
38
|
+
pass
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Data module for imspy_core.
|
|
3
|
+
|
|
4
|
+
Contains spectrum and peptide data structures.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .spectrum import MzSpectrum, IndexedMzSpectrum, MzSpectrumVectorized, TimsSpectrum
|
|
8
|
+
from .peptide import (
|
|
9
|
+
PeptideSequence, PeptideIon, PeptideProductIon,
|
|
10
|
+
PeptideProductIonSeries, PeptideProductIonSeriesCollection
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
'MzSpectrum', 'IndexedMzSpectrum', 'MzSpectrumVectorized', 'TimsSpectrum',
|
|
15
|
+
'PeptideSequence', 'PeptideIon', 'PeptideProductIon',
|
|
16
|
+
'PeptideProductIonSeries', 'PeptideProductIonSeriesCollection'
|
|
17
|
+
]
|