Python lib for common ontology operations over a variety of backends.
OAK provides a collection of interfaces for various ontology operations, including:
look up basic features of an ontology element, such as its label, definition, relationships, or aliases
search an ontology for a term
validate an ontology
modify or delete terms
generate and visualize subgraphs
identify lexical matches and export as SSSOM mapping tables
perform more advanced operations, such as graph traversal, OWL axiom processing, or text annotation
These interfaces are separated from any particular backend, for which there a number of different adapters.
This means the same Python API and command line can be used regardless of whether the ontology:
is served by a remote API such as OLS or BioPortal
is present locally on the filesystem in owl, obo, obojson, or sqlite formats
is to be downloaded from a remote repository such as the OBO library
is queried from a remote database, including SPARQL endpoints (Ontobee/Ubergraph), A SQL database, a Solr/ES endpoint
from oaklib import get_adapter
# connect to the CL sqlite database adapter
# (will first download if not already downloaded)
adapter = get_adapter("sqlite:obo:cl")
NEURON = "CL:0000540"
print('## Basic info')
print(f'ID: {NEURON}')
print(f'Label: {adapter.label(NEURON)}')
for alias in adapter.entity_aliases(NEURON):
print(f'Alias: {alias}')
print('## Relationships (direct)')
for relationship in adapter.relationships([NEURON]):
print(f' * {relationship.predicate} -> {relationship.object} "{adapter.label(relationship.object)}"')
print('## Ancestors (over IS_A and PART_OF)')
from oaklib.datamodels.vocabulary import IS_A, PART_OF
from oaklib.interfaces import OboGraphInterface
if not isinstance(adapter, OboGraphInterface):
raise ValueError('This adapter does not support graph operations')
for ancestor in adapter.ancestors(NEURON, predicates=[IS_A, PART_OF]):
print(f' * ANCESTOR: "{adapter.label(ancestor)}"')