Base Classes
Base classes used across multiple modules.
OBO Entity
Shared base class and helpers for ontology entries (UNIMOD, PSI-MOD, RESID, XLMOD,
GNOme, amino acids, elements, …). Every *Info dataclass in this package
(UnimodInfo, PsimodInfo, ElementInfo, …) subclasses OboEntity
and inherits its fields, serialization, and mass/composition helpers.
- class tacular.obo_entity.OboEntity(id, name, formula, monoisotopic_mass, average_mass, dict_composition)[source]
Bases:
objectBase class for OBO file entities.
Subclasses (one per ontology/data type) add no fields of their own beyond what’s declared here; they exist to give each ontology’s entries a distinct type and, where needed, override
id_tagfor that ontology’s id format.- Parameters:
id (str)
name (str)
formula (str | None)
monoisotopic_mass (float | None)
average_mass (float | None)
dict_composition (Mapping[str, int] | None)
- average_mass: float | None
Average (isotope-abundance-weighted) mass delta in Da, or
Noneif not available.
- property composition: dict[ElementInfo, int] | None
dict_compositionwith keys resolved toElementInfoobjects instead of plain symbol strings;Noneif no composition is set.
- dict_composition: Mapping[str, int] | None
Elemental composition as
{symbol: count}(isotope keys like"13C"are supported), orNoneif not available. Usecompositionfor a version keyed byElementInfoinstead of plain strings.
- formula: str | None
Chemical formula string (e.g.
"C2H2O"), orNoneif not available.
- classmethod from_dict(data)[source]
Reconstruct an OboEntity from its
to_dictrepresentation.The inverse of
to_dict(); noteto_dictserialisesdict_compositionunder the"composition"key.- Return type:
Self- Parameters:
data (Mapping[str, Any])
- id: str
The entry’s id, in whatever format its source ontology uses (e.g.
"536"for UNIMOD,"AA0001"for RESID). Useid_tagfor a normalized form.
- property id_tag: str
idwith leading zeros stripped (e.g."00042"->"42").Subclasses whose ids carry a non-numeric prefix (RESID’s
"AA0001", for example) override this to strip that prefix too.
- mass(monoisotopic=True)[source]
Get the mass of the entity
- Return type:
float|None- Parameters:
monoisotopic (bool)
- monoisotopic_mass: float | None
Monoisotopic mass delta in Da, or
Noneif not available.
- name: str
The entry’s human-readable name, as given by the source ontology.
- to_dict(float_precision=6)[source]
Convert the OboEntity to a dictionary.
float_precisionrounds the masses (default 6, as used for the bundledjsons/*.json). PassNoneto preserve full float precision, e.g. when round-tripping through the runtime cache so an updated install matches the precision of the bundleddata.py.- Return type:
dict[str,object]- Parameters:
float_precision (int | None)
OBO Lookup
Shared lookup base class (OntologyLookup) used by every per-ontology
*_LOOKUP singleton in this package (UNIMOD_LOOKUP, PSIMOD_LOOKUP, …).
Handles id/name normalization, query-by-id/name/mass, iteration, and random
sampling; each ontology’s *Lookup subclass just supplies its data, name, and
optional id prefix (see e.g. unimod/lookup.py).
- class tacular.obo_lookup.OntologyLookup(data, ontology_name, _version='', _id_prefix=None)[source]
Bases:
GenericId/name/mass lookup over a dict of
OboEntitysubclass instances.Lookup dictionaries are built lazily on first access (see
_ensure_initialized()), not in__init__, so constructing a lookup with cache-resolved data (seetacular._cache) is cheap even before any query is made.- Parameters:
data (dict[str, T])
ontology_name (str)
_version (str)
_id_prefix (str | None)
- choice(require_monoisotopic_mass=True, require_composition=True)[source]
Get a random entry from the lookup.
- Return type:
TypeVar(T, bound=OboEntity)- Parameters:
require_monoisotopic_mass (bool)
require_composition (bool)
- query_id(mod_id)[source]
Query by ID, stripping known prefixes.
- Return type:
Optional[TypeVar(T, bound=OboEntity)]- Parameters:
mod_id (str | int)
- query_mass(mass, tolerance=0.01, monoisotopic=True)[source]
Query by mass within a given tolerance.
- Return type:
list[TypeVar(T, bound=OboEntity)]- Parameters:
mass (float)
tolerance (float)
monoisotopic (bool)
- query_name(name)[source]
Query by name, stripping known prefixes.
- Return type:
Optional[TypeVar(T, bound=OboEntity)]- Parameters:
name (str)
- property version: str
Get the version of the ontology data.