biocypher._ontology.OntologyAdapter

class biocypher._ontology.OntologyAdapter(ontology_file: str, root_label: str, ontology_file_format: Optional[str] = None, head_join_node_label: Optional[str] = None, merge_nodes: Optional[bool] = True, switch_label_and_id: 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. Labels are formatted in lower sentence case and underscores are replaced by spaces. Identifiers are taken as defined and the prefixes are removed by default.

__init__(ontology_file: str, root_label: str, ontology_file_format: Optional[str] = None, head_join_node_label: Optional[str] = None, merge_nodes: Optional[bool] = True, switch_label_and_id: 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.

  • ontology_file_format (str) – The format of the ontology file (e.g. “application/rdf+xml”) If format is not passed, it is determined automatically.

  • head_join_node_label (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.

  • switch_label_and_id (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_node()

Get root node in the ontology.

has_label(node, g)

Does the node have a label in g?