Python API Reference
Python bindings to the rustyms library.
- class rustyms.MassMode
Bases:
objectMass mode enum.
- Average = MassMode.Average
- Monoisotopic = MassMode.Monoisotopic
- class rustyms.Element(symbol)
Bases:
objectElement.
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).
- isotopes()
Get all available isotopes (N, mass, abundance).
- class rustyms.MolecularFormula(elements)
Bases:
objectMolecular 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:
- 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:
- 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:
- elements()
Get the elements making this formula.
- from_pro_forma()
Create a new molecular formula from a ProForma formula notation string.
- Parameters:
proforma (str) –
- Return type:
- from_psi_mod()
Create a new molecular formula from a PSI-MOD formula notation string.
- Parameters:
psi_mod (str) –
- Return type:
- hill_notation()
Create a Hill notation from this collections of elements merged with the pro forma notation for specific isotopes.
- Return type:
- 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:
- hill_notation_html()
Create a Hill notation from this collections of elements encoded in HTML.
- Return type:
- mass(mode=Ellipsis)
Get the mass in the given mode.
- Parameters:
mode (MassMode) – The mode to get the mass in.
- Return type:
- 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:
- with_global_isotope_modifications(substitutions)
Create a new molecular formula with the given global isotope modifications.
- class rustyms.MolecularCharge(charge_carriers)
Bases:
objectA 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:
- class rustyms.AminoAcid(name)
Bases:
objectAmino 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:
- class rustyms.Modification(name)
Bases:
objectAmino acid modification.
- Parameters:
name (str) – The name of the modification.
- formula()
Molecular formula of the modification.
- Return type:
- class rustyms.AmbiguousModification(id, modification, localisation_score=None, group=None)
Bases:
objectModification 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.
- id
The id to compare be able to find the other locations where this modifications can be placed.
- Return type:
- 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:
- class rustyms.Fragment
Bases:
objectA theoretical fragment of a peptide.
- formula
The theoretical composition.
- Return type:
- class rustyms.SequenceElement
Bases:
objectOne 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
- 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:
- possible_modifications
All ambiguous modifications (could be placed here or on another position).
- Return type:
- class rustyms.FragmentationModel
Bases:
objectFragmentation model enum.
- All = FragmentationModel.All
- CidHcd = FragmentationModel.CidHcd
- Etcid = FragmentationModel.Etcid
- Etd = FragmentationModel.Etd
- Ethcd = FragmentationModel.Ethcd
- class rustyms.LinearPeptide(proforma)
Bases:
objectA 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.
- c_term
C-terminal modification.
- Return type:
Modification | 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:
- labile
Labile modifications, which will not be found in the actual spectrum.
- Return type:
- n_term
N-terminal modification.
- Return type:
Modification | None
- reverse()
Get a copy of the peptide with its sequence reversed.
- Return type:
- sequence
Sequence of the peptide including modifications.
- Return type:
- class rustyms.AnnotatedPeak
Bases:
objectRepresents an annotated peak in a mass spectrometry spectrum.
- class rustyms.RawSpectrum(title, num_scans, rt, precursor_charge, precursor_mass, mz_array, intensity_array)
Bases:
objectA raw spectrum (meaning not annotated yet)
- Parameters:
- Return type:
- annotate(peptide, model, mode=Ellipsis)
Annotate this spectrum with the given peptide
- Parameters:
peptide (LinearPeptide) – The peptide to annotate the spectrum with.
model (FragmentationModel) – The model to use for the fragmentation.
mode (MassMode) – The mode to use for the mass.
- Returns:
The annotated spectrum.
- Return type:
- Raises:
ValueError – If the model is not one of the valid models.