Base Classes

Base classes used across multiple modules.

OBO Entity

class tacular.obo_entity.OboEntity(id, name, formula, monoisotopic_mass, average_mass, dict_composition)[source]

Bases: object

Base class for OBO file entities

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
property composition: dict[ElementInfo, int] | None

Get the composition as a dict of element symbols to counts

dict_composition: Mapping[str, int] | None
formula: str | None
id: str
property id_tag: str
mass(monoisotopic=True)[source]

Get the mass of the entity

Return type:

float | None

Parameters:

monoisotopic (bool)

monoisotopic_mass: float | None
name: str
to_dict(float_precision=6)[source]

Convert the OboEntity to a dictionary

Return type:

dict[str, object]

Parameters:

float_precision (int)

update(**kwargs)[source]

Return a new instance with updated fields

Return type:

Self

Parameters:

kwargs (Any)

tacular.obo_entity.filter_infos(infos, has_monoisotopic_mass=None, has_composition=None, **criteria)[source]

Filter a list of OboEntity or its subclasses based on criteria.

Return type:

list[TypeVar(T, bound= OboEntity)]

Parameters:
  • infos (list[T])

  • has_monoisotopic_mass (bool | None)

  • has_composition (bool | None)

  • criteria (Any)

OBO Lookup

class tacular.obo_lookup.OntologyLookup(data, ontology_name, _version='', _id_prefix=None)[source]

Bases: Generic

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)

get(key, default=None)[source]
Return type:

Optional[TypeVar(T, bound= OboEntity)]

Parameters:
  • key (str | int)

  • default (T | None)

keys()[source]

Get all keys (names) in the lookup.

Return type:

list[str]

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)

values()[source]

Get all entries in the lookup.

Return type:

list[TypeVar(T, bound= OboEntity)]

property version: str

Get the version of the ontology data.

tacular.obo_lookup.convert_key(key, prefix=None)[source]
Return type:

int | None

Parameters:
  • key (str)

  • prefix (str | None)

tacular.obo_lookup.strip_id(key, prefix=None)[source]

Strip known prefix from ID

Return type:

str

Parameters:
  • key (str)

  • prefix (str | None)