IndraOntology (indra.ontology
)¶
- class indra.ontology.ontology_graph.IndraOntology(*args, **kwargs)[source]¶
A directed graph representing entities and their properties as nodes and ontological relationships between the entities as edges.
- get_children(ns, id, ns_filter=None)[source]¶
Return all isa or partof children of a given entity.
Importantly, isa and partof edges always point towards higher-level entities in the ontology but here “child” means lower-level entity i.e., ancestors in the graph.
- get_id_from_name(ns, name)[source]¶
Return an entity’s ID given its name space and standard name.
- Parameters
- Return type
- Returns
The pair of namespace and ID corresponding to the given standard name in the given name space or None if it’s not available.
- get_mappings(ns, id)[source]¶
Return entities that are xrefs of a given entity.
This function returns all mappings via xrefs edges from the given entity.
- get_parents(ns, id)[source]¶
Return all isa or partof parents of a given entity.
Importantly, isa and partof edges always point towards higher-level entities in the ontology but here “parent” means higher-level entity i.e., descendants in the graph.
- get_replacement(ns, id)[source]¶
Return a replacement for a given entity or None if no replacement.
A replacement is typically necessary if the given entity is obsolete and has been replaced by another entry.
- get_top_level_parents(ns, id)[source]¶
Return all top-level isa or partof parents of a given entity.
Top level means that this function only returns parents which don’t have any further isa or partof parents above them. Importantly, isa and partof edges always point towards higher-level entities in the ontology but here “parent” means higher-level entity i.e., descendants in the graph.
- initialize()[source]¶
Initialize the ontology by adding nodes and edges.
By convention, ontologies are implemented such that the constructor does not add all the nodes and edges, which can take a long time. This function is called automatically when any of the user-facing methods ot IndraOntology is called. This way, the ontology is only fully constructed if it is used.
- is_opposite(ns1, id1, ns2, id2)[source]¶
Return True if the two entities are opposites of each other.
- isa(ns1, id1, ns2, id2)[source]¶
Return True if the first entity is related to the second as ‘isa’.
- Parameters
- Returns
True if the first entity is related to the second with a directed path containing edges with type isa. Otherwise False.
- Return type
- isa_or_partof(ns1, id1, ns2, id2)[source]¶
Return True if the first entity is related to the second as ‘isa’ or partof.
- Parameters
- Returns
True if the first entity is related to the second with a directed path containing edges with type isa or partof. Otherwise False.
- Return type
- isrel(ns1, id1, ns2, id2, rels)[source]¶
Return True if the two entities are related with a given rel.
- Parameters
- Returns
True if the first entity is related to the second with a directed path containing edges with types in rels . Otherwise False.
- Return type
- static label(ns, id)[source]¶
Return the label corresponding to a given entity.
This is mostly useful for constructing the ontology or when adding new nodes/edges. It can be overriden in subclasses to change the default mapping from ns / id to a label.
- map_to(ns1, id1, ns2)[source]¶
Return an entity that is a unique xref of an entity in a given name space.
This function first finds all mappings via xrefs edges from the given first entity to the given second name space. If exactly one such mapping target is found, the target is returned. Otherwise, None is returned.
- maps_to(ns1, id1, ns2, id2)[source]¶
Return True if the first entity has an xref to the second.
- Parameters
- Returns
True if the first entity is related to the second with a directed path containing edges with type xref. Otherwise False.
- Return type
- name = None¶
- nodes_from_suffix(suffix)[source]¶
Return all node labels which have a given suffix.
This is useful for finding entities in ontologies where the IDs consist of paths like a/b/c/…
- partof(ns1, id1, ns2, id2)[source]¶
Return True if the first entity is related to the second as ‘partof’.
- Parameters
- Returns
True if the first entity is related to the second with a directed path containing edges with type partof. Otherwise False.
- Return type
- static reverse_label(label)[source]¶
Return the name space and ID from a given label.
This is the complement of the label method which reverses a label into a name space and ID.
- Parameters
label – A node label.
- Returns
str – The name space corresponding to the label.
str – The ID corresponding to the label.