OboGraph Interface

class oaklib.interfaces.obograph_interface.OboGraphInterface(resource: Optional[oaklib.resource.OntologyResource] = None, strict: bool = False)[source]

an interface that provides an Object Oriented view of an ontology, following the OBO Graph Datamodel

See OBOGraphs

Key datamodel concepts:

  • obograph.Node - any named ontology element

  • obograph.Edge - any relationship between elements; for example between “finger” and “hand”

  • obograph.Graph - a collection of nodes, edges, and other ontology components

This datamodel conceives of an ontology as a graph

add_metadata(graph: oaklib.datamodels.obograph.Graph) None[source]

Decorates the graph with meta objects on all nodes :param graph: :return:

ancestor_graph(start_curies: Union[str, List[str]], predicates: Optional[List[str]] = None) oaklib.datamodels.obograph.Graph[source]

Return a graph object that consists of all the nodes specified in the start_curies list, extended with an interactive walk up the graph following all relationships (optionally filtered by the predicate list)

Parameters
  • start_curies

  • predicates – if supplied then only follow edges with these predicates

Returns

ancestor graph

ancestors(start_curies: Union[str, List[str]], predicates: Optional[List[str]] = None, reflexive=True) Iterable[str][source]

Ancestors obtained from a walk starting from start_curies ending in roots, following only the specified predicates.

Note

This operation is reflexive: self is included

Parameters
  • start_curies – curie or curies to start the walk from

  • predicates – only traverse over these (traverses over all if this is not set)

  • reflexive – include self

Returns

all ancestor CURIEs

as_obograph() oaklib.datamodels.obograph.Graph[source]

Convert entire resource to an OBO Graph object

Warning

some remote resources may choose to throw a NotImplementedError if it is impractical to download the entire ontology as a graph

Returns

descendant_graph(start_curies: Union[str, List[str]], predicates: Optional[List[str]] = None) oaklib.datamodels.obograph.Graph[source]

As ancestor graph, but in opposite direction

Parameters
  • start_curies

  • predicates – if supplied then only follow edges with these predicates

Returns

ancestor graph

descendants(start_curies: Union[str, List[str]], predicates: Optional[List[str]] = None, reflexive=True) Iterable[str][source]

Descendants obtained from a walk downwards starting from start_curies ending in roots, following only the specified predicates.

Note

This operation is reflexive: self is included

Parameters
  • start_curies – curie or curies to start the walk from

  • predicates – only traverse over these (traverses over all if this is not set)

  • reflexive – include self

Returns

all descendant CURIEs

disable_transitive_query_cache()[source]

Do not cache transitive queries (default)

edges() Iterator[oaklib.datamodels.obograph.Edge][source]

Iterator over all edges in all graphs

Returns

enable_transitive_query_cache()[source]

Cache transitive queries

load_graph(graph: oaklib.datamodels.obograph.Graph, replace: True) None[source]

Loads a graph into the repository

Parameters
  • graph

  • replace

Returns

node(curie: str, strict=False, include_metadata=False) oaklib.datamodels.obograph.Node[source]

Look up a node object by CURIE

Parameters
  • curie – identifier of node

  • strict – raise exception if node not found

  • include_metadata – include detailed metadata

Returns

nodes() Iterator[oaklib.datamodels.obograph.Node][source]

Iterator over all nodes in all graphs

Returns

relationships_to_graph(relationships: Iterable[Tuple[str, str, str]]) oaklib.datamodels.obograph.Graph[source]

Generates an OboGraph from a list of relationships

Parameters

relationships

Returns

subgraph(start_curies: Union[str, List[str]], predicates: Optional[List[str]] = None, traversal: Optional[oaklib.interfaces.obograph_interface.TraversalConfiguration] = None) oaklib.datamodels.obograph.Graph[source]

Combines ancestors and descendants according to a traversal configuration

Parameters
  • start_curies

  • predicates

  • traversal

Returns

synonym_map_for_curies(subject: Union[str, Iterable[str]]) Dict[str, List[oaklib.datamodels.obograph.SynonymPropertyValue]][source]

Get a map of SynonymPropertyValue objects keyed by curie

Parameters

subject – curie or list of curies

Returns

walk_up_relationship_graph(start_curies: Union[str, List[str]], predicates: Optional[List[str]] = None) Iterable[Tuple[str, str, str]][source]

Walks up the relation graph from a seed set of curies or individual curie, returning the full ancestry graph

Note: this may be inefficient for remote endpoints, in future a graph walking endpoint will implement this

Parameters
  • start_curies

  • predicates

Returns

class oaklib.interfaces.obograph_interface.TraversalConfiguration(predicates: typing.Optional[typing.List[str]] = None, up_distance: oaklib.interfaces.obograph_interface.Distance = <factory>, down_distance: oaklib.interfaces.obograph_interface.Distance = <factory>)[source]

Specifies how to walk up and down a graph