Skip to content

ontologies.term

Ontology terms with the information of the ontology release.

An ontology is a class with one attribute per term, e.g., SBO, and a term is an OntologyTerm, i.e., a str which is the identifier of the term and carries what the ontology says about it:

from pymetadata.ontologies import SBO

term = SBO.SIMPLE_CHEMICAL

term == "SBO_0000247"  # True, a term is the identifier
term.label             # 'simple chemical'
term.definition        # 'Simple, non-repetitive chemical entity.'
term.synonyms          # ()
term.curie             # 'SBO:0000247'
term.url               # 'https://identifiers.org/SBO:0000247'

Every term exists under its identifier (SBO.SBO_0000247) and under its name (SBO.SIMPLE_CHEMICAL), both are the same object. The generated modules declare the terms with their definition as docstring, so that an editor shows it when the term is completed, and register the data with _register.

The ontology classes behave like the enums they replace: they are iterable, a term can be looked up with SBO["SBO_0000247"] or SBO("SBO:0000247"), and validate normalizes the notations of an identifier.

OntologyMeta

Bases: type

Metaclass which gives an ontology the lookups of an enum.

The ontology is iterable, contains its terms and resolves an identifier with SBO["SBO_0000247"] and SBO("SBO:0000247").

OntologyTerm

Bases: str

A term of an ontology.

The term is the identifier of the ontology term, i.e., it can be used wherever the identifier is expected: SBO.SIMPLE_CHEMICAL == "SBO_0000247" is True and serializing a term gives the identifier. The information of the ontology release is available as attributes.

Attributes:

Name Type Description
label str

name of the term in the ontology, e.g., simple chemical

definition str | None

definition of the term, None if the ontology has none

synonyms tuple[str, ...]

alternative names of the term

deprecated bool

the term is obsolete and should not be used for annotation

id property

id

Identifier of the term.

Returns:

Type Description
str

The identifier with an underscore, e.g., SBO_0000247.

name property

name

Identifier of the term, the name in the ontology is label.

Returns:

Type Description
str

The identifier with an underscore, e.g., SBO_0000247.

value property

value

Identifier of the term.

Returns:

Type Description
str

The identifier with an underscore, e.g., SBO_0000247.

curie property

curie

Compact identifier of the term.

Returns:

Type Description
str

The identifier with a colon, e.g., SBO:0000247.

url property

url

Identifiers.org URL of the term.

Returns:

Type Description
str

The resolvable url, e.g., https://identifiers.org/SBO:0000247.

get_name classmethod

get_name(term)

Get the name of a term.

Parameters:

Name Type Description Default
term str | OntologyTerm

term or identifier, e.g., SBO_0000247 or SBO:0000247

required

Returns:

Type Description
str | None

The name, or None if the term does not exist in the ontology.

get_term classmethod

get_term(term)

Get a term of the ontology.

Parameters:

Name Type Description Default
term str | OntologyTerm

term or identifier, e.g., SBO_0000247 or SBO:0000247

required

Returns:

Type Description
OntologyTerm

The term with label, definition, synonyms and deprecation.

Raises:

Type Description
ValueError

if the term does not belong to the ontology

AttributeError

if the term does not exist in the ontology

validate classmethod

validate(term)

Validate and normalize a term of the ontology.

Accepts a term, SBO_0000247 and SBO:0000247.

Parameters:

Name Type Description Default
term str | OntologyTerm

term or identifier of a term

required

Returns:

Type Description
OntologyTerm

The term of the ontology.

Raises:

Type Description
ValueError

if the term does not belong to the ontology

AttributeError

if the term does not exist in the ontology