Expand description
Fine-structure isotopic distributions of molecules, computed by IsoSpec.
The C++ library is compiled from source by the build script (a C++20 compiler is needed); this crate is a safe API over it.
§Overview
A molecule is an Iso: from a formula, a peptide sequence (with Unimod
modifications), a Composition or raw isotope data. Its isotopic
distribution is then computed
- whole, as an
Envelope(arrays of masses and probabilities): the isotopologues above a probability threshold, the smallest set covering a given total probability, a simulated measurement, or binned on a mass grid; envelopes can be added, convolved, binned and compared (Wasserstein distances); - or one isotopologue at a time, by a generator:
ThresholdGenerator,LayeredGenerator,OrderedGenerator(strictly decreasing probability) andStochasticGenerator. Generators iterate overPeaks (for peak in generator), or step one isotopologue at a time withadvance(), which also gives each one’s configuration.
use isospec::{Iso, Threshold, ThresholdGenerator};
// The smallest set of isotopologues of a peptide covering 99.9%.
let iso = Iso::from_formula("C254H377N65O75S6")?;
let mut env = iso.envelope().total_prob(0.999)?;
env.sort_by_mass();
println!("{} peaks, {:.4} Da to {:.4} Da", env.len(), env.masses()[0], env.masses()[env.len() - 1]);
// Or streamed, never stored.
let n = ThresholdGenerator::new(iso, 1e-3, Threshold::Relative)?.into_iter().count();
assert!(n > 0);§Threads
Every type can be sent to another thread. Iso, Envelope and
UnimodTable can be shared: their &self methods may run concurrently.
Generators are stateful and are not Sync.
§Errors
Invalid input is an Error, never undefined behaviour: the C++
library’s exceptions are caught at the boundary, and the arguments the
C++ cannot check itself (slice lengths) are checked before calling it.
The ErrorKind names the exception class.
Modules§
- isa
- The instruction-set level the library’s SIMD kernels run at.
Structs§
- Composition
- Element counts: a molecular formula, or a difference between two (a modification’s delta, say), so counts may be negative.
- Conf
- An isotopologue’s configuration, owned. See
ConfRef. - ConfRef
- An isotopologue’s configuration, borrowed: for each element of the molecule, how many atoms are of each of its isotopes (in the order of the element’s isotopes, lightest first for table elements).
- Element
- A chemical element of IsoSpec’s built-in table, with its stable isotopes’ masses and natural abundances.
- Element
Spec - One element of a molecule given by its isotopes rather than by symbol:
for labelled or otherwise non-natural elements. See
Iso::from_isotopesandIso::add_element; made withElementSpec::new. - Envelope
- An isotopic distribution as arrays: a mass and a probability per peak, and optionally each peak’s isotopologue configuration.
- Envelope
Builder - Options for computing an
Envelopefrom anIso: whether to keep configurations. Start one withIso::envelope. - Error
- An error from IsoSpec: its kind and the library’s message.
- Expanded
Composition - A composition resolved to the flat isotope arrays IsoSpec computes on:
one entry per element in
isotope_numbersandatom_counts, and one per isotope, element after element, inmassesandprobabilities. - Iso
- A molecule, as IsoSpec computes on it: for each element, its atom count and its isotopes’ masses and abundances.
- Isotope
- One isotope of an
Element. - Layered
Generator - Isotopologues in layers of decreasing probability: each layer’s are less probable than the previous layer’s, in no particular order within a layer. Runs through the whole distribution if not stopped; stop once enough probability is covered.
- Layered
Options - Options of a
LayeredGenerator: start fromdefaultand change what you need. - Match
- The result of
Envelope::wasserstein_match. - Ordered
Generator - Isotopologues in strictly decreasing order of probability. Slower than the others (a priority queue); use it when the order itself matters.
- Peak
- One isotopologue as a generator reports it.
- Peaks
- The isotopologues of a generator, as an iterator: see the generators’
IntoIterator. Peaks come from the library 256 at a time. - Peptide
Options - How a peptide sequence is read: see
Composition::from_peptideandIso::from_peptide. Start fromdefaultand change what you need. - Stochastic
Generator - A simulated measurement:
moleculesmolecules sampled from the distribution, reported as the isotopologues that received any, each with its count inPeak::prob. - Stochastic
Options - Options of stochastic sampling:
StochasticGeneratorandEnvelope::stochastic. Start fromdefaultand change what you need. - Threshold
Generator - Every isotopologue with probability above a threshold, in no particular order. The fastest generator.
- Threshold
Options - Options of a
ThresholdGenerator: start fromdefaultand change what you need, so that options added later leave your code compiling. - Unimod
Entry - One entry of a
UnimodTable. - Unimod
Table - A table of Unimod modifications: id → name,
monoisotopic mass delta and composition delta. Used to resolve
[UNIMOD:<id>]in peptide sequences.
Enums§
- Error
Kind - What went wrong, by the C++ exception class the library threw (or, for arguments the Rust side rejects before calling in, the class it would have thrown).
- Masses
- Which isotope masses a molecule is built with.
- Threshold
- Whether a probability threshold is absolute or relative to the most probable isotopologue.
Constants§
- LIBRARY_
VERSION - The version of the bundled IsoSpec C++ library.
Functions§
- simd_
level - What the SIMD kernels run as on this machine: see
isa::simd_level.