Obo

class pyobo.Obo(date=<factory>, data_version=None, force=False)[source]

Bases: object

An OBO document.

Attributes Summary

auto_generated_by

An annotation about how an ontology was generated

bioversions_key

data_version

The ontology version

date_formatted

Get the date as a formatted string.

dynamic_version

Set to true for resources that are unversioned/very dynamic, like HGNC

force

Should this ontology be reloaded?

format_version

The OBO format

hierarchy

A graph representing the parent/child relationships between the entities.

idspaces

The idspaces used in the document

iter_only

For super-sized datasets that shouldn't be read into memory

name

The name of the ontology.

properties_header

Property dataframe header.

relations_header

Header for the relations dataframe.

static_version

Set to a static version for the resource (i.e., the resource is not itself versioned)

synonym_typedefs

Synonym type definitions

typedefs

Type definitions

xrefs_header

The header for the xref dataframe.

Methods Summary

ancestors(identifier)

Return a set of identifiers for parents of the given identifier.

cli()

Run the CLI for this class.

descendants(identifier)

Return a set of identifiers for the children of the given identifier.

get_cls_cli()

Get the CLI for this class.

get_filtered_multixrefs_mapping(prefix, *[, ...])

Get filtered xrefs as a dictionary.

get_filtered_properties_df(prop, *[, use_tqdm])

Get a dataframe of terms' identifiers to the given property's values.

get_filtered_properties_mapping(prop, *[, ...])

Get a mapping from a term's identifier to the property.

get_filtered_properties_multimapping(prop, *)

Get a mapping from a term's identifier to the property values.

get_filtered_relations_df(relation, *[, ...])

Get a specific relation from OBO.

get_filtered_xrefs_mapping(prefix, *[, use_tqdm])

Get filtered xrefs as a dictionary.

get_id_alts_mapping()

Get a mapping from identifiers to a list of alternative identifiers.

get_id_definition_mapping(*[, use_tqdm])

Get a mapping from identifiers to definitions.

get_id_multirelations_mapping(typedef, *[, ...])

Get a mapping from identifiers to a list of all references for the given relation.

get_id_name_mapping(*[, use_tqdm])

Get a mapping from identifiers to names.

get_id_species_mapping(*[, prefix, use_tqdm])

Get a mapping from identifiers to species.

get_id_synonyms_mapping(*[, use_tqdm])

Get a mapping from identifiers to a list of sorted synonym strings.

get_ids(*[, use_tqdm])

Get the set of identifiers.

get_metadata()

Get metadata.

get_properties_df(*[, use_tqdm])

Get all properties as a dataframe.

get_relation(source_identifier, relation, ...)

Get the value for a bijective relation mapping between this resource and a target resource.

get_relation_mapping(relation, target_prefix, *)

Get a mapping from the term's identifier to the target's identifier.

get_relation_multimapping(relation, ...[, ...])

Get a mapping from the term's identifier to the target's identifiers.

get_relations_df(*[, use_tqdm])

Get all relations from the OBO.

get_typedef_df([use_tqdm])

Get a typedef dataframe.

get_typedef_id_name_mapping()

Get a mapping from typedefs' identifiers to names.

get_xrefs_df(*[, use_tqdm])

Get a dataframe of all xrefs extracted from the OBO document.

is_descendant(descendant, ancestor)

Return if the given identifier is a descendent of the ancestor.

iter_property_rows(*[, use_tqdm])

Iterate property rows.

iter_relation_rows([use_tqdm])

Iterate the relations' rows.

iter_terms([force])

Iterate over terms in this ontology.

iter_typedef_id_name()

Iterate over typedefs' identifiers and their respective names.

iterate_alt_rows()

Iterate over pairs of terms' primary identifiers and alternate identifiers.

iterate_alts()

Iterate over alternative identifiers.

iterate_filtered_properties(prop, *[, use_tqdm])

Iterate over tuples of terms and the values for the given property.

iterate_filtered_relations(relation, *[, ...])

Iterate over tuples of terms and ther targets for the given relation.

iterate_filtered_relations_filtered_targets(...)

Iterate over relationships between one identifier and another.

iterate_filtered_xrefs(prefix, *[, use_tqdm])

Iterate over xrefs to a given prefix.

iterate_id_definition(*[, use_tqdm])

Iterate over pairs of terms' identifiers and their respective definitions.

iterate_id_name(*[, use_tqdm])

Iterate identifier name pairs.

iterate_id_species(*[, prefix, use_tqdm])

Iterate over terms' identifiers and respective species (if available).

iterate_ids(*[, use_tqdm])

Iterate over identifiers.

iterate_obo_lines()

Iterate over the lines to write in an OBO file.

iterate_properties(*[, use_tqdm])

Iterate over tuples of terms, properties, and their values.

iterate_relations(*[, use_tqdm])

Iterate over tuples of terms, relations, and their targets.

iterate_synonym_rows(*[, use_tqdm])

Iterate over pairs of identifier and synonym text.

iterate_synonyms(*[, use_tqdm])

Iterate over pairs of term and synonym object.

iterate_xref_rows(*[, use_tqdm])

Iterate over terms' identifiers, xref prefixes, and xref identifiers.

iterate_xrefs(*[, use_tqdm])

Iterate over xrefs.

to_obonet(*[, use_tqdm])

Export as a :mod`obonet` style graph.

write_default([use_tqdm, force, write_obo, ...])

Write the OBO to the default path.

write_obo([file, use_tqdm])

Write the OBO to a file.

write_obonet_gz(path)

Write the OBO to a gzipped dump in Obonet JSON.

Attributes Documentation

auto_generated_by: ClassVar[Optional[str]] = None

An annotation about how an ontology was generated

bioversions_key: ClassVar[Optional[str]] = None
data_version: Optional[str] = None

The ontology version

date_formatted

Get the date as a formatted string.

dynamic_version: ClassVar[bool] = False

Set to true for resources that are unversioned/very dynamic, like HGNC

force: bool = False

Should this ontology be reloaded?

format_version: ClassVar[str] = '1.2'

The OBO format

hierarchy

A graph representing the parent/child relationships between the entities.

To get all children of a given entity, do:

from pyobo import get_obo
obo = get_obo('go')

identifier = '1905571'  # interleukin-10 receptor complex
is_complex = '0032991' in  nx.descendants(obo.hierarchy, identifier)  # should be true
idspaces: ClassVar[Optional[Mapping[str, str]]] = None

The idspaces used in the document

iter_only: ClassVar[bool] = False

For super-sized datasets that shouldn’t be read into memory

name: ClassVar[Optional[str]] = None

The name of the ontology. If not given, tries looking up with the Bioregistry.

properties_header

Property dataframe header.

relations_header

Header for the relations dataframe.

static_version: ClassVar[Optional[str]] = None

Set to a static version for the resource (i.e., the resource is not itself versioned)

synonym_typedefs: ClassVar[Optional[List[SynonymTypeDef]]] = None

Synonym type definitions

typedefs: ClassVar[Optional[List[TypeDef]]] = None

Type definitions

xrefs_header

The header for the xref dataframe.

Methods Documentation

ancestors(identifier)[source]

Return a set of identifiers for parents of the given identifier.

Return type:

Set[str]

classmethod cli()[source]

Run the CLI for this class.

Return type:

None

descendants(identifier)[source]

Return a set of identifiers for the children of the given identifier.

Return type:

Set[str]

classmethod get_cls_cli()[source]

Get the CLI for this class.

Return type:

Command

get_filtered_multixrefs_mapping(prefix, *, use_tqdm=False)[source]

Get filtered xrefs as a dictionary.

Return type:

Mapping[str, List[str]]

get_filtered_properties_df(prop, *, use_tqdm=False)[source]

Get a dataframe of terms’ identifiers to the given property’s values.

Return type:

DataFrame

get_filtered_properties_mapping(prop, *, use_tqdm=False)[source]

Get a mapping from a term’s identifier to the property. :rtype: Mapping[str, str]

Warning

Assumes there’s only one version of the property for each term.

get_filtered_properties_multimapping(prop, *, use_tqdm=False)[source]

Get a mapping from a term’s identifier to the property values.

Return type:

Mapping[str, List[str]]

get_filtered_relations_df(relation, *, use_tqdm=False)[source]

Get a specific relation from OBO.

Return type:

DataFrame

get_filtered_xrefs_mapping(prefix, *, use_tqdm=False)[source]

Get filtered xrefs as a dictionary.

Return type:

Mapping[str, str]

get_id_alts_mapping()[source]

Get a mapping from identifiers to a list of alternative identifiers.

Return type:

Mapping[str, List[str]]

get_id_definition_mapping(*, use_tqdm=False)[source]

Get a mapping from identifiers to definitions.

Return type:

Mapping[str, str]

get_id_multirelations_mapping(typedef, *, use_tqdm=False)[source]

Get a mapping from identifiers to a list of all references for the given relation.

Return type:

Mapping[str, List[Reference]]

get_id_name_mapping(*, use_tqdm=False)[source]

Get a mapping from identifiers to names.

Return type:

Mapping[str, str]

get_id_species_mapping(*, prefix=None, use_tqdm=False)[source]

Get a mapping from identifiers to species.

Return type:

Mapping[str, str]

get_id_synonyms_mapping(*, use_tqdm=False)[source]

Get a mapping from identifiers to a list of sorted synonym strings.

Return type:

Mapping[str, List[str]]

get_ids(*, use_tqdm=False)[source]

Get the set of identifiers.

Return type:

Set[str]

get_metadata()[source]

Get metadata.

Return type:

Mapping[str, Any]

get_properties_df(*, use_tqdm=False)[source]

Get all properties as a dataframe.

Return type:

DataFrame

get_relation(source_identifier, relation, target_prefix, *, use_tqdm=False)[source]

Get the value for a bijective relation mapping between this resource and a target resource.

>>> from pyobo.sources.hgnc import get_obo
>>> obo = get_obo()
>>> human_mapt_hgnc_id = '6893'
:rtype: :py:data:`~typing.Optional`\[:py:class:`str`]
>>> mouse_mapt_mgi_id = '97180'
>>> assert mouse_mapt_mgi_id == obo.get_relation(human_mapt_hgnc_id, 'ro:HOM0000017', 'mgi')
get_relation_mapping(relation, target_prefix, *, use_tqdm=False)[source]

Get a mapping from the term’s identifier to the target’s identifier. :rtype: Mapping[str, str]

Warning

Assumes there’s only one version of the property for each term.

Example usage: get homology between HGNC and MGI:

>>> from pyobo.sources.hgnc import get_obo
>>> obo = get_obo()
>>> human_mapt_hgnc_id = '6893'
>>> mouse_mapt_mgi_id = '97180'
>>> hgnc_mgi_orthology_mapping = obo.get_relation_mapping('ro:HOM0000017', 'mgi')
>>> assert mouse_mapt_mgi_id == hgnc_mgi_orthology_mapping[human_mapt_hgnc_id]
get_relation_multimapping(relation, target_prefix, *, use_tqdm=False)[source]

Get a mapping from the term’s identifier to the target’s identifiers.

Return type:

Mapping[str, List[str]]

get_relations_df(*, use_tqdm=False)[source]

Get all relations from the OBO.

Return type:

DataFrame

get_typedef_df(use_tqdm=False)[source]

Get a typedef dataframe.

Return type:

DataFrame

get_typedef_id_name_mapping()[source]

Get a mapping from typedefs’ identifiers to names.

Return type:

Mapping[str, str]

get_xrefs_df(*, use_tqdm=False)[source]

Get a dataframe of all xrefs extracted from the OBO document.

Return type:

DataFrame

is_descendant(descendant, ancestor)[source]

Return if the given identifier is a descendent of the ancestor.

from pyobo import get_obo
obo = get_obo('go')

interleukin_10_complex = '1905571'  # interleukin-10 receptor complex
all_complexes = '0032991'
assert obo.is_descendant('1905571', '0032991')
Return type:

bool

iter_property_rows(*, use_tqdm=False)[source]

Iterate property rows.

Return type:

Iterable[Tuple[str, str, str]]

iter_relation_rows(use_tqdm=False)[source]

Iterate the relations’ rows.

Return type:

Iterable[Tuple[str, str, str, str, str]]

iter_terms(force=False)[source]

Iterate over terms in this ontology.

Return type:

Iterable[Term]

iter_typedef_id_name()[source]

Iterate over typedefs’ identifiers and their respective names.

Return type:

Iterable[Tuple[str, str]]

iterate_alt_rows()[source]

Iterate over pairs of terms’ primary identifiers and alternate identifiers.

Return type:

Iterable[Tuple[str, str]]

iterate_alts()[source]

Iterate over alternative identifiers.

Return type:

Iterable[Tuple[Term, Reference]]

iterate_filtered_properties(prop, *, use_tqdm=False)[source]

Iterate over tuples of terms and the values for the given property.

Return type:

Iterable[Tuple[Term, str]]

iterate_filtered_relations(relation, *, use_tqdm=False)[source]

Iterate over tuples of terms and ther targets for the given relation.

Return type:

Iterable[Tuple[Term, Reference]]

iterate_filtered_relations_filtered_targets(relation, target_prefix, *, use_tqdm=False)[source]

Iterate over relationships between one identifier and another.

Return type:

Iterable[Tuple[Term, Reference]]

iterate_filtered_xrefs(prefix, *, use_tqdm=False)[source]

Iterate over xrefs to a given prefix.

Return type:

Iterable[Tuple[Term, Reference]]

iterate_id_definition(*, use_tqdm=False)[source]

Iterate over pairs of terms’ identifiers and their respective definitions.

Return type:

Iterable[Tuple[str, str]]

iterate_id_name(*, use_tqdm=False)[source]

Iterate identifier name pairs.

Return type:

Iterable[Tuple[str, str]]

iterate_id_species(*, prefix=None, use_tqdm=False)[source]

Iterate over terms’ identifiers and respective species (if available).

Return type:

Iterable[Tuple[str, str]]

iterate_ids(*, use_tqdm=False)[source]

Iterate over identifiers.

Return type:

Iterable[str]

iterate_obo_lines()[source]

Iterate over the lines to write in an OBO file.

Return type:

Iterable[str]

iterate_properties(*, use_tqdm=False)[source]

Iterate over tuples of terms, properties, and their values.

Return type:

Iterable[Tuple[Term, str, str]]

iterate_relations(*, use_tqdm=False)[source]

Iterate over tuples of terms, relations, and their targets.

Return type:

Iterable[Tuple[Term, TypeDef, Reference]]

iterate_synonym_rows(*, use_tqdm=False)[source]

Iterate over pairs of identifier and synonym text.

Return type:

Iterable[Tuple[str, str]]

iterate_synonyms(*, use_tqdm=False)[source]

Iterate over pairs of term and synonym object.

Return type:

Iterable[Tuple[Term, Synonym]]

iterate_xref_rows(*, use_tqdm=False)[source]

Iterate over terms’ identifiers, xref prefixes, and xref identifiers.

Return type:

Iterable[Tuple[str, str, str]]

iterate_xrefs(*, use_tqdm=False)[source]

Iterate over xrefs.

Return type:

Iterable[Tuple[Term, Reference]]

to_obonet(*, use_tqdm=False)[source]

Export as a :mod`obonet` style graph.

Return type:

MultiDiGraph

write_default(use_tqdm=False, force=False, write_obo=False, write_obonet=False, write_obograph=False, write_owl=False)[source]

Write the OBO to the default path.

Return type:

None

write_obo(file: None | str | TextIO | Path = None, use_tqdm: bool = False) None[source]

Write the OBO to a file.

Return type:

None

write_obonet_gz(path)[source]

Write the OBO to a gzipped dump in Obonet JSON.

Return type:

None