Skip to content

Configuration object

ms2ml.config

Provides a place to define the project's configuration.

Defines the constants that are used in the rest of the project.

Such as the masses of aminoacids, supported modifications, length of the encodings, maximum length supported, labels and order of the encoded ions ...

Attributes

Classes

ms2ml.config.Config dataclass

General class to set and store the configuration of the project.

Ideally every project will make one AND ONLY ONE of these. The provided defaults are meant to be reasonable for most projects but can be changed as needed.

All annotation and endoding functionality should require one of this objects to work.

PARAMETER DESCRIPTION
g_tolerances

A tuple of floats, where each float is the tolerance of that corresponding ms level. For instance (10, 20) means that the tolerance for ms1 is 10, 20 for ms2.

TYPE: tuple[float, ...] DEFAULT: (50, 50)

g_tolerance_units

A tuple of strings, that denote what tolerance unit to use for each ms level. For instance ("ppm", "Da") means that the tolerance for ms1 is in ppm, and for ms2 in Da.

TYPE: tuple[MassError, ...] DEFAULT: ('ppm', 'ppm')

g_isotopes

TYPE: tuple[int, ...] DEFAULT: (0, 0)

peptide_length_range

A tuple of ints, where the first int is the minimum length of peptides.

TYPE: tuple[int, int] DEFAULT: (5, 30)

precursor_charges

A tuple of ints, where each int is a possible precursor charge.

TYPE: tuple[int, ...] DEFAULT: (1, 2, 3, 4, 5, 6)

fragment_positions

A tuple of ints, where each int is a possible fragment position.

TYPE: tuple[int, ...] DEFAULT: tuple(range(1, 31))

ion_series

A string of characters, where each character is a possible ion series. An example,a dn the default is ('by')

TYPE: str DEFAULT: 'yb'

ion_charges

A tuple of ints, where each int is a possible ion charge.

TYPE: tuple[int, ...] DEFAULT: (1, 2)

ion_neutral_losses

TYPE: tuple[str, ...] DEFAULT: ()

ion_encoding_nesting

TYPE: tuple[str, ...] DEFAULT: ('ion_charges', 'fragment_positions', 'ion_series')

ion_naming_convention

TYPE: str DEFAULT: '{ion_series}{fragment_positions}^{ion_charges}'

mod_ambiguity_threshold

TYPE: float DEFAULT: 0.99

mod_fixed_mods

TYPE: tuple[str] DEFAULT: ('[UNIMOD:4]@C')

Examples:

>>> config = Config()
>>> config
Config(g_tolerances=(50, 50), ...)
>>> config.fragment_labels
['y1^1', 'y1^2', ... 'b30^2']
Attributes
g_tolerances: tuple[float, ...] = (50, 50) class-attribute
g_tolerance_units: tuple[MassError, ...] = ('ppm', 'ppm') class-attribute
g_isotopes: tuple[int, ...] = (0, 0) class-attribute
peptide_length_range: tuple[int, int] = (5, 30) class-attribute
peptide_mz_range: tuple[float, float] = (200, 20000) class-attribute
precursor_charges: tuple[int, ...] = (1, 2, 3, 4, 5, 6) class-attribute
fragment_positions: tuple[int, ...] = tuple(range(1, 31)) class-attribute
ion_series: str = 'yb' class-attribute
ion_charges: tuple[int, ...] = (1, 2) class-attribute
ion_neutral_losses: tuple[str, ...] = () class-attribute
ion_encoding_nesting: tuple[str, ...] = ('ion_charges', 'fragment_positions', 'ion_series') class-attribute
ion_naming_convention: str = '{ion_series}{fragment_positions}^{ion_charges}' class-attribute
mod_mode: ModModes = 'unimod' class-attribute
mod_ambiguity_threshold: float = 0.99 class-attribute
mod_fixed_mods: tuple[str] = ('[UNIMOD:4]@C') class-attribute
mod_variable_mods: dict[str, tuple[str]] = field(default_factory=_default_var_mods) class-attribute
encoding_aa_order: tuple[str] = tuple(['n_term'] + list(string.ascii_uppercase) + ['c_term', '__missing__']) class-attribute
encoding_mod_order: tuple[str | None, ...] = field(default_factory=_default_mod_order) class-attribute
encoding_mod_alias: dict[str, str] = field(default_factory=_default_mod_aliases) class-attribute
encoding_spec_bin_start: float = field(repr=False, default=0.0) class-attribute
encoding_spec_bin_end: float = field(repr=False, default=2000.0) class-attribute
encoding_spec_bin_binsize: float | None = field(repr=False, default=0.1) class-attribute
encoding_spec_bin_n_bins: int | None = field(repr=False, default=None) class-attribute
encoding_spec_bin_relative: bool = field(repr=False, default=False) class-attribute
encoding_spec_bin_offset: float = field(repr=False, default=0.0) class-attribute
num_fragment_embeddings: int property
Functions
fragment_labels() -> list[str]

Returns a list of the labels that are used to encode the fragments.

Examples:

>>> config = Config()
>>> config.fragment_labels
['y1^1', 'y1^2', ... 'b30^2']
ion_labeller(ion: AnnotatedIon) -> str

Labels an ion

Provided an ion, returns the label for that ion.

Examples:

>>> ion = AnnotatedIon(mass=123.2, charge=2, position=3, ion_series="z")
>>> config = Config()
>>> config.ion_labeller(ion)
'z3^2'
aa_masses()
mod_masses()
encoding_mod_order_mapping() -> dict[str | None, int]
encoding_aa_order_mapping() -> dict[str | None, int]
asdict()

Returns a dictionary representation of the config.

to_toml(path: str)

Writes the config to a toml file.

from_toml(path: str) staticmethod

Loads a config from a toml file.

from_comet(path: str, *args, **kwargs)

Loads a config from a comet params file.

ms2ml.config.ConfigNotSetError

Bases: Exception

Raised when a config is not set but is required.

Functions

ms2ml.config.get_default_config() -> Config