Obo
- class Obo(date=<factory>, data_version=None, force=False)[source]
Bases:
objectAn OBO document.
Attributes Summary
An annotation about how an ontology was generated
Should the prefix be validated against the Bioregistry?
The ontology version
The date the ontology was generated
Get the date as a formatted string.
Set to true for resources that are unversioned/very dynamic, like MGI
Header for the edges dataframe.
Should this ontology be reloaded?
A graph representing the parent/child relationships between the entities.
The idspaces used in the document
For super-sized datasets that shouldn't be read into memory
Property dataframe header.
The name of the ontology.
Get the header for nodes.
Property dataframe header.
The prefix for the ontology
Property dataframe header.
Header for the relations dataframe.
Root terms to use for the ontology
Allow skipping adding maintainers annotations, in case the resource maintainers don't want their names associated with the OWL exports that e.g. end up on EBI OLS.
Set to a static version for the resource (i.e., the resource is not itself versioned)
Synonym type definitions
Type definitions
Methods Summary
ancestors(identifier)Return a set of identifiers for parents of the given identifier.
cli(*args)Run the CLI for this class.
descendants(identifier)Return a set of identifiers for the children of the given identifier.
Get the CLI for this class.
get_edges_df(*[, use_tqdm])Get an edges dataframe.
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 a grounder from this ontology.
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 literal mappings in a standard data model.
Get a literal mappings dataframe.
get_literal_properties_df(*[, use_tqdm])Get all properties as a dataframe.
get_mappings_df(*[, use_tqdm])Get a dataframe with SSSOM extracted from the OBO document.
Get metadata.
get_object_properties_df(*[, use_tqdm])Get all properties as a dataframe.
get_obsolete(*[, use_tqdm])Get the set of obsolete identifiers.
get_properties_df(*[, use_tqdm, drop_na])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_semantic_mappings(*[, progress])Iterate over semantic mappings.
get_typedef_df([use_tqdm])Get a typedef dataframe.
Get a mapping from typedefs' identifiers to names.
is_descendant(descendant, ancestor)Return if the given identifier is a descendant of the ancestor.
iter_literal_properties(*[, use_tqdm])Iterate over literal properties quads.
iter_object_properties(*[, use_tqdm])Iterate over object property triples.
iter_relation_rows([use_tqdm])Iterate the relations' rows.
iter_terms([force])Iterate over terms in this ontology.
Iterate over typedefs' identifiers and their respective names.
Iterate over pairs of terms' primary identifiers and alternate identifiers.
Iterate over alternative identifiers.
iterate_edge_rows([use_tqdm])Iterate the edge rows.
iterate_edges(*[, use_tqdm, include_xrefs])Iterate over triples of terms, relations, and their targets.
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 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 over literal mapping rows.
iterate_node_rows([sep])Get a nodes iterator appropriate for serialization.
iterate_obo_lines([emit_object_properties, ...])Iterate over the lines to write in an OBO file.
iterate_properties(*[, use_tqdm])Iterate over tuples of terms, properties, and their values.
iterate_references(*[, use_tqdm])Iterate over identifiers.
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_xrefs(*[, use_tqdm])Iterate over xrefs.
to_obonet(*[, use_tqdm])Export as a :mod`obonet` style graph.
write_cache(*[, force])Write cache parts.
write_default([use_tqdm, force, write_obo, ...])Write the OBO to the default path.
write_edges(path)Write a edges TSV file.
Write the metadata JSON file.
write_nodes(path)Write a nodes TSV file.
write_obo([file, use_tqdm, ...])Write the OBO to a file.
write_obograph(path, *[, converter])Write OBO Graph JSON.
write_obonet_gz(path)Write the OBO to a gzipped dump in Obonet JSON.
write_ofn(path)Write as Functional OWL (OFN).
write_owl(path)Write OWL, by first outputting OFN then converting with ROBOT.
Write a prefix map file that includes all prefixes used in this ontology.
write_rdf(path)Write as Turtle RDF.
Attributes Documentation
- check_bioregistry_prefix: ClassVar[bool] = True
Should the prefix be validated against the Bioregistry?
- 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 MGI
- edges_header
Header for the edges dataframe.
- hierarchy
A graph representing the parent/child relationships between the entities.
To get all children of a given entity, do:
from pyobo import get_ontology obo = get_ontology("go") identifier = "1905571" # interleukin-10 receptor complex is_complex = "0032991" in nx.descendants(obo.hierarchy, identifier) # should be true
- literal_properties_header
Property dataframe header.
- name: ClassVar[str | None] = None
The name of the ontology. If not given, tries looking up with the Bioregistry.
- nodes_header
Get the header for nodes.
- object_properties_header
Property dataframe header.
- properties_header
Property dataframe header.
- property_values: ClassVar[list[Annotation] | None] = None
- relations_header
Header for the relations dataframe.
- root_terms: ClassVar[list[NormalizedNamableReference] | None] = None
Root terms to use for the ontology
- skip_maintainers: ClassVar[bool] = False
Allow skipping adding maintainers annotations, in case the resource maintainers don’t want their names associated with the OWL exports that e.g. end up on EBI OLS
- static_version: ClassVar[str | None] = None
Set to a static version for the resource (i.e., the resource is not itself versioned)
- synonym_typedefs: ClassVar[list[SynonymTypeDef] | None] = None
Synonym type definitions
Methods Documentation
- descendants(identifier)[source]
Return a set of identifiers for the children of the given identifier.
- get_edges_df(*, use_tqdm=False)[source]
Get an edges dataframe.
- Parameters:
use_tqdm (bool)
- Return type:
DataFrame
- get_filtered_multixrefs_mapping(prefix, *, use_tqdm=False)[source]
Get filtered xrefs as a dictionary.
- get_filtered_properties_df(prop, *, use_tqdm=False)[source]
Get a dataframe of terms’ identifiers to the given property’s values.
- get_filtered_properties_mapping(prop, *, use_tqdm=False)[source]
Get a mapping from a term’s identifier to the property.
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.
- get_grounder()[source]
Get a grounder from this ontology.
- Returns:
An object that can be used for named entity recognition and named entity normalization
- Return type:
Grounder
Here’s example usage for a built-in ontology:
import pyobo import ssslm ontology = pyobo.get_ontology("taxrank") grounder: ssslm.Grounder = ontology.get_grounder() matches: list[ssslm.Match] = grounder.ground("species")
Here’s example usage for a custom ontology:
import pyobo import ssslm from urllib.request import urlretrieve url = "http://purl.obolibrary.org/obo/taxrank.obo" path = "taxrank.obo" urlretrieve(url, path) ontology = pyobo.from_obo_path(path, prefix="taxrank") grounder: ssslm.Grounder = ontology.get_grounder() matches: list[ssslm.Match] = grounder.get_matches("species")
Warning
It’s required to tell PyOBO the prefix for a custom ontology when using
pyobo.from_obo_path(), and it must be registered in the Bioregistry
- get_id_definition_mapping(*, use_tqdm=False)[source]
Get a mapping from identifiers to definitions.
- get_id_multirelations_mapping(typedef, *, use_tqdm=False)[source]
Get a mapping from identifiers to a list of all references for the given relation.
- get_id_species_mapping(*, prefix=None, use_tqdm=False)[source]
Get a mapping from identifiers to species.
- get_id_synonyms_mapping(*, use_tqdm=False)[source]
Get a mapping from identifiers to a list of sorted synonym strings.
- get_literal_mappings()[source]
Get literal mappings in a standard data model.
- Return type:
Iterable[LiteralMapping]
- get_literal_properties_df(*, use_tqdm=False)[source]
Get all properties as a dataframe.
- Parameters:
use_tqdm (bool)
- Return type:
DataFrame
- get_mappings_df(*, use_tqdm=False)[source]
Get a dataframe with SSSOM extracted from the OBO document.
- Parameters:
use_tqdm (bool) – Should a progres bar be shown
- Returns:
A pandas dataframe representing SSSOM records
- Return type:
DataFrame
- get_object_properties_df(*, use_tqdm=False)[source]
Get all properties as a dataframe.
- Parameters:
use_tqdm (bool)
- 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 HGNCGetter >>> obo = HGNCGetter() >>> human_mapt_hgnc_id = "6893" >>> 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.
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 HGNCGetter >>> obo = HGNCGetter() >>> 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.
- get_relations_df(*, use_tqdm=False)[source]
Get all relations from the OBO.
- Parameters:
use_tqdm (bool)
- Return type:
DataFrame
- get_typedef_df(use_tqdm=False)[source]
Get a typedef dataframe.
- Parameters:
use_tqdm (bool)
- Return type:
DataFrame
- is_descendant(descendant, ancestor)[source]
Return if the given identifier is a descendant of the ancestor.
from pyobo import get_ontology obo = get_ontology("go") interleukin_10_complex = "1905571" # interleukin-10 receptor complex all_complexes = "0032991" assert obo.is_descendant("1905571", "0032991")
- iterate_alt_rows()[source]
Iterate over pairs of terms’ primary identifiers and alternate identifiers.
- iterate_edges(*, use_tqdm=False, include_xrefs=True)[source]
Iterate over triples of terms, relations, and their targets.
- iterate_filtered_properties(prop, *, use_tqdm=False)[source]
Iterate over tuples of terms and the values for the given property.
- iterate_filtered_relations(relation, *, use_tqdm=False)[source]
Iterate over tuples of terms and ther targets for the given relation.
- iterate_filtered_relations_filtered_targets(relation, target_prefix, *, use_tqdm=False)[source]
Iterate over relationships between one identifier and another.
- iterate_id_definition(*, use_tqdm=False)[source]
Iterate over pairs of terms’ identifiers and their respective definitions.
- iterate_id_species(*, prefix=None, use_tqdm=False)[source]
Iterate over terms’ identifiers and respective species (if available).
- iterate_literal_mapping_rows()[source]
Iterate over literal mapping rows.
- Return type:
Iterable[LiteralMappingTuple]
- iterate_obo_lines(emit_object_properties=True, emit_annotation_properties=True)[source]
Iterate over the lines to write in an OBO file.
Here’s the order:
format-version (technically, this is the only required field)
data-version
date
saved-by
auto-generated-by
import
subsetdef
synonymtypedef
default-namespace
namespace-id-rule
idspace
treat-xrefs-as-equivalent
treat-xrefs-as-genus-differentia
treat-xrefs-as-relationship
treat-xrefs-as-is_a
remark
ontology
- iterate_properties(*, use_tqdm=False)[source]
Iterate over tuples of terms, properties, and their values.
- Parameters:
use_tqdm (bool)
- Return type:
Iterable[tuple[Stanza, Annotation]]
- iterate_relations(*, use_tqdm=False)[source]
Iterate over tuples of terms, relations, and their targets.
This only outputs stuff from the relationship: tag, not all possible triples. For that, see
iterate_edges().
- to_obonet(*, use_tqdm=False)[source]
Export as a :mod`obonet` style graph.
- Parameters:
- Return type:
- write_default(use_tqdm=False, force=False, write_obo=False, write_obonet=False, write_obograph=False, write_owl=False, write_ofn=False, write_ttl=False, write_nodes=False, obograph_use_internal=False, write_cache=True)[source]
Write the OBO to the default path.
- write_obo(file=None, *, use_tqdm=False, emit_object_properties=True, emit_annotation_properties=True)[source]
Write the OBO to a file.