Graph Utils¶
Utility methods for working with graphs.
kgx.utils.graph_utils¶
-
kgx.utils.graph_utils.
curie_lookup
(curie: str) → Optional[str][source]¶ Given a CURIE, find its label.
This method first does a lookup in predefined maps. If none found, it makes use of CurieLookupService to look for the CURIE in a set of preloaded ontologies.
- Parameters
curie (str) – A CURIE
- Returns
The label corresponding to the given CURIE
- Return type
Optional[str]
-
kgx.utils.graph_utils.
get_ancestors
(graph: kgx.graph.base_graph.BaseGraph, node: str, relations: List[str] = None) → List[str][source]¶ Return all ancestors of specified node, filtered by
relations
.- Parameters
graph (kgx.graph.base_graph.BaseGraph) – Graph to traverse
node (str) – node identifier
relations (List[str]) – list of relations
- Returns
A list of ancestor nodes
- Return type
List[str]
-
kgx.utils.graph_utils.
get_category_via_superclass
(graph: kgx.graph.base_graph.BaseGraph, curie: str, load_ontology: bool = True) → Set[str][source]¶ Get category for a given CURIE by tracing its superclass, via
subclass_of
hierarchy, and getting the most appropriate category based on the superclass.- Parameters
graph (kgx.graph.base_graph.BaseGraph) – Graph to traverse
curie (str) – Input CURIE
load_ontology (bool) – Determines whether to load ontology, based on CURIE prefix, or to simply rely on
subclass_of
hierarchy from graph
- Returns
A set containing one (or more) category for the given CURIE
- Return type
Set[str]
-
kgx.utils.graph_utils.
get_parents
(graph: kgx.graph.base_graph.BaseGraph, node: str, relations: List[str] = None) → List[str][source]¶ Return all direct parents of a specified node, filtered by
relations
.- Parameters
graph (kgx.graph.base_graph.BaseGraph) – Graph to traverse
node (str) – node identifier
relations (List[str]) – list of relations
- Returns
A list of parent node(s)
- Return type
List[str]