biocypher._ontology.OntologyAdapter

class biocypher._ontology.OntologyAdapter(ontology_file: str, root_label: str, format: Optional[str] = None, head_join_node: Optional[str] = None, merge_nodes: Optional[bool] = True, reverse_labels: bool = True, remove_prefixes: bool = True)

Class that represents an ontology to be used in the Biocypher framework. Can read from a variety of formats, including OWL, OBO, and RDF/XML. The ontology is represented by a networkx.DiGraph object; an RDFlib graph is also kept. By default, the DiGraph reverses the label and identifier of the nodes, such that the node name in the graph is the human-readable label. The edges are oriented from child to parent. Going from the Biolink example, labels are formatted in lower sentence case. In some cases, this means that we replace underscores with spaces.

__init__(ontology_file: str, root_label: str, format: Optional[str] = None, head_join_node: Optional[str] = None, merge_nodes: Optional[bool] = True, reverse_labels: bool = True, remove_prefixes: bool = True)

Initialize the OntologyAdapter class.

Parameters:
  • ontology_file (str) – Path to the ontology file. Can be local or remote.

  • root_label (str) – The label of the root node in the ontology. In case of a tail ontology, this is the tail join node.

  • head_join_node (str) – Optional variable to store the label of the node in the head ontology that should be used to join to the root node of the tail ontology. Defaults to None.

  • merge_nodes (bool) – If True, head and tail join nodes will be merged, using the label of the head join node. If False, the tail join node will be attached as a child of the head join node.

  • reverse_labels (bool) – If True, the node names in the graph will be the human-readable labels. If False, the node names will be the identifiers. Defaults to True.

  • remove_prefixes (bool) – If True, the prefixes of the identifiers will be removed. Defaults to True.

Methods

__init__(ontology_file, root_label[, ...])

Initialize the OntologyAdapter class.

get_ancestors(node_label)

Get the ancestors of a node in the ontology.

get_head_join_node()

Get the head join node of the ontology.

get_nx_graph()

Get the networkx graph representing the ontology.

get_rdf_graph()

Get the RDFlib graph representing the ontology.

get_root_label()

Get the label of the root node in the ontology.