Python API Reference

Python bindings to the rustyms library.

class rustyms.MassMode

Bases: object

Mass mode enum.

Average = MassMode.Average
Monoisotopic = MassMode.Monoisotopic
class rustyms.Element(symbol)

Bases: object

Element.

A chemical element, with its isotopes and their properties.

Parameters:

symbol (str) –

average_weight(isotope=None)

The average weight of the specified isotope of this element (if that isotope exists).

Parameters:

isotope (int | None) – The isotope number (default: None).

Return type:

float

isotopes()

Get all available isotopes (N, mass, abundance).

Return type:

list[tuple[int, float, float]]

mass(isotope=None)

The mass of the specified isotope of this element (if that isotope exists).

Parameters:

isotope (int | None) – The isotope number (default: None).

Return type:

float | None

class rustyms.MolecularFormula(elements)

Bases: object

Molecular formula.

A molecular formula: a selection of elements of specified isotopes together forming a structure.

add(element, isotope=None, n=1)

Add the given element to this formula (while keeping it ordered and simplified)

Parameters:
  • element (Element) – The element to add.

  • isotope (int | None) – The isotope number of the element to add (default: None).

  • n (int) – The number of atoms of this element to add (default: 1).

Raises:

ValueError – If the element or isotope is invalid.

average_weight()

The average weight of the molecular formula of this element, if all element species (isotopes) exists.

Return type:

float

charge()

Get the number of electrons (the only charged species, any ionic species is saved as that element +/- the correct number of electrons). The inverse of that number is given as the charge.

Return type:

int

elements()

Get the elements making this formula.

Return type:

list[tuple[Element, int | None, int]]

from_pro_forma()

Create a new molecular formula from a ProForma formula notation string.

Parameters:

proforma (str) –

Return type:

MolecularFormula

from_psi_mod()

Create a new molecular formula from a PSI-MOD formula notation string.

Parameters:

psi_mod (str) –

Return type:

MolecularFormula

hill_notation()

Create a Hill notation from this collections of elements merged with the pro forma notation for specific isotopes.

Return type:

str

hill_notation_fancy()

Create a Hill notation from this collections of elements merged with the pro forma notation for specific isotopes. Using fancy unicode characters for subscript and superscript numbers.

Return type:

str

hill_notation_html()

Create a Hill notation from this collections of elements encoded in HTML.

Return type:

str

mass(mode=Ellipsis)

Get the mass in the given mode.

Parameters:

mode (MassMode) – The mode to get the mass in.

Return type:

float

Raises:

ValueError – If the mode is not one of the valid modes.

monoisotopic_mass()

The mass of the molecular formula of this element, if all element species (isotopes) exists

Return type:

float

with_global_isotope_modifications(substitutions)

Create a new molecular formula with the given global isotope modifications.

class rustyms.MolecularCharge(charge_carriers)

Bases: object

A selection of ions that together define the charge of a peptide.

charge_carriers

List of counts and molecular formulas for the charge carriers.

Returns:

The charge carriers.

Return type:

list[tuple[int, MolecularFormula]]

proton()
Parameters:

charge (int) – The charge.

Return type:

MolecularCharge

class rustyms.AminoAcid(name)

Bases: object

Amino acid.

Parameters:

name (str) – The name of the amino acid.

formula()

Molecular formula of the amino acid.

Returns the molecular formula of the amino acid (the first if multiple are possible).

Return type:

List[MolecularFormula]

formulas()

Molecular formula(s) of the amino acid.

Returns a list of molecular formulas that are possible for the amino acid symbol.

Return type:

List[MolecularFormula]

monoisotopic_mass()

Monoisotopic mass of the amino acid.

Returns the monoisotopic mass of the amino acid (the first if multiple are possible).

Return type:

float

monoisotopic_masses()

Monoisotopic mass(es) of the amino acid.

Returns a list of monoisotopic masses that are possible for the amino acid symbol.

Return type:

List[float]

class rustyms.Modification(name)

Bases: object

Amino acid modification.

Parameters:

name (str) – The name of the modification.

formula()

Molecular formula of the modification.

Return type:

MolecularFormula

monoisotopic_mass()

Monoisotopic mass of the modification.

Return type:

float

class rustyms.AmbiguousModification(id, modification, localisation_score=None, group=None)

Bases: object

Modification with ambiguous localisation.

Parameters:
  • id (int) – The id to compare be able to find the other locations where this modifications can be placed.

  • modification (Modification) – The modification itself.

  • localisation_score (float | None) – If present the localisation score, meaning the chance/ratio for this modification to show up on this exact spot.

  • group (tuple[str, bool] | None) – If this is a named group contain the name and track if this is the preferred location or not.

group

If this is a named group contain the name and track if this is the preferred location or not.

Return type:

tuple[str, bool] | None

id

The id to compare be able to find the other locations where this modifications can be placed.

Return type:

int

localisation_score

If present the localisation score, meaning the chance/ratio for this modification to show up on this exact spot.

Return type:

float | None

modification

The modification itself.

Return type:

Modification

class rustyms.Fragment

Bases: object

A theoretical fragment of a peptide.

charge

The charge.

Return type:

int

formula

The theoretical composition.

Return type:

MolecularFormula

ion

All possible annotations for this fragment.

Return type:

str

label

Additional description for humans.

Return type:

str

neutral_loss

Any neutral losses applied.

Return type:

str | None

peptide_index

The peptide this fragment comes from, saved as the index into the list of peptides in the overarching crate::ComplexPeptide struct.

Return type:

int

class rustyms.SequenceElement

Bases: object

One block in a sequence meaning an amino acid and its accompanying modifications.

ambiguous

If this amino acid is part of an ambiguous sequence group (QA)? in ProForma

Return type:

int | None

aminoacid

The amino acid.

Return type:

AminoAcid

formula_all()

Get the molecular formulas for this position with all ambiguous modifications, without any global isotype modifications

Return type:

List[MolecularFormula]

formula_greedy(placed)

Get the molecular formulas for this position with the ambiguous modifications placed on the very first placed (and updating this in placed), without any global isotype modifications

Parameters:

placed (bool) –

Return type:

List[MolecularFormula]

formulas(selected_ambiguous)

Get the molecular formulas for this position with the selected ambiguous modifications, without any global isotype modifications

Parameters:

selected_ambiguous (int) –

Return type:

List[MolecularFormula]

modifications

All present modifications.

Return type:

list[Modification]

possible_modifications

All ambiguous modifications (could be placed here or on another position).

Return type:

list[AmbiguousModification]

class rustyms.FragmentationModel

Bases: object

Fragmentation model enum.

All = FragmentationModel.All
CidHcd = FragmentationModel.CidHcd
Etcid = FragmentationModel.Etcid
Etd = FragmentationModel.Etd
Ethcd = FragmentationModel.Ethcd
class rustyms.LinearPeptide(proforma)

Bases: object

A peptide with all data as provided by ProForma 2.0.

Parameters:

proforma (str) – The ProForma string.

ambiguous_modifications

For each ambiguous modification list all possible positions it can be placed on. Indexed by the ambiguous modification id.

Return type:

list[list[int]]

c_term

C-terminal modification.

Return type:

Modification | None

charge

The precursor charge of the peptide.

Return type:

int | None

formula()

Gives the formulas for the whole peptide. With the global isotope modifications applied. (Any B/Z will result in multiple possible formulas.)

Return type:

List[MolecularFormula]

generate_theoretical_fragments(max_charge, model)

Generate the theoretical fragments for this peptide, with the given maximal charge of the fragments, and the given model. With the global isotope modifications applied.

Parameters:
  • max_charge (int) – The maximal charge of the fragments.

  • model (FragmentationModel) – The model to use for the fragmentation.

Returns:

The theoretical fragments.

Return type:

list[Fragment]

labile

Labile modifications, which will not be found in the actual spectrum.

Return type:

list[Modification]

n_term

N-terminal modification.

Return type:

Modification | None

reverse()

Get a copy of the peptide with its sequence reversed.

Return type:

LinearPeptide

sequence

Sequence of the peptide including modifications.

Return type:

list[SequenceElement]

stripped_sequence

Stripped sequence, meaning the sequence without any modifications.

Return type:

str

class rustyms.RawPeak

Bases: object

intensity

The intensity of the peak.

Return type:

float

mz

The m/z value of the peak.

Return type:

float

class rustyms.AnnotatedPeak

Bases: object

Represents an annotated peak in a mass spectrometry spectrum.

annotation

All annotations of the peak. Can be empty.

Return type:

list[Fragment]

experimental_mz

The experimental m/z value of the peak.

Return type:

float

intensity

The intensity of the peak.

Return type:

float

class rustyms.RawSpectrum(title, num_scans, rt, precursor_charge, precursor_mass, mz_array, intensity_array)

Bases: object

A raw spectrum (meaning not annotated yet)

Parameters:
  • title (str) – The title of the spectrum.

  • num_scans (int) – The number of scans.

  • rt (float) – The retention time.

  • precursor_charge (float) – The found precursor charge.

  • precursor_mass (float) – The found precursor mass.

  • mz_array (list[float]) – The m/z values of the peaks.

  • intensity_array (list[float]) – The intensities of the peaks.

Return type:

RawSpectrum

annotate(peptide, model, mode=Ellipsis)

Annotate this spectrum with the given peptide

Parameters:
Returns:

The annotated spectrum.

Return type:

AnnotatedSpectrum

Raises:

ValueError – If the model is not one of the valid models.

charge

The found precursor charge.

Return type:

float

mass

The found precursor mass.

Return type:

float

num_scans

The number of scans.

Return type:

int

rt

The retention time.

Return type:

float

spectrum

The peaks of which this spectrum consists.

Return type:

list[RawPeak]

title

The title.

Return type:

str

class rustyms.AnnotatedSpectrum

Bases: object

An annotated spectrum.

charge

The found precursor charge.

Return type:

float

mass

The found precursor mass.

Return type:

float

num_scans

The number of scans.

Return type:

int

rt

The retention time.

Return type:

float

spectrum

The peaks of which this spectrum consists.

Return type:

list[AnnotatedPeak]

title

The title.

Return type:

str