Hierarchy manager (indra.preassembler.hierarchy_manager)¶
-
class
indra.preassembler.hierarchy_manager.HierarchyManager(rdf_file=None, build_closure=None, uri_as_name=True)[source]¶ Store hierarchical relationships between different types of entities.
Used to store, e.g., entity hierarchies (proteins and protein families) and modification hierarchies (serine phosphorylation vs. phosphorylation).
Parameters: - rdf_file (string) – Path to the RDF file containing the hierarchy.
- build_closure (bool or list or None) – If True, the transitive closure of the hierarchy is generated up front to speed up processing. If a list, the entries in the list are namespaces for which a transitive closure should be built. Namespaces not listed are ignored and isa/partof lookups will not use the transitive closure. If False, no transitive closure is built. Default: True
- uri_as_name (Optional[bool]) – If True, entries are accessed directly by their URIs. If False entries are accessed by finding their name through the hasName relationship. Default: True
-
graph¶ The RDF graph containing the hierarchy.
Type: instance of rdflib.Graph
-
build_transitive_closure(rel, tc_set)[source]¶ Build a transitive closure for a given relation in a given dict.
-
build_transitive_closures()[source]¶ Build the transitive closures of the hierarchy.
This method constructs dictionaries which contain terms in the hierarchy as keys and either all the “isa+” or “partof+” related terms as values.
Return True if two entities have the speicified relationship.
This relation is constructed possibly through multiple links connecting the two entities directly or indirectly.
Parameters: - ns1 (str) – Namespace code for an entity.
- id1 (str) – URI for an entity.
- ns2 (str) – Namespace code for an entity.
- id2 (str) – URI for an entity.
- closure_set (set) – A set containing tuples of entities that have the specified relationship, directly or indirectly. Empty if this has not been precomputed.
- relation_func (function) – Function with arguments (node, graph) that generates objects with some relationship with node on the given graph.
Returns: True if t1 has the specified relationship with t2, either directly or through a series of intermediates; False otherwise.
Return type: bool
-
extend_with(rdf_file)[source]¶ Extend the RDF graph of this HierarchyManager with another RDF file.
Parameters: rdf_file (str) – An RDF file which is parsed such that the current graph and the graph described by the file are merged.
-
find_entity[source]¶ Return the entity that has the specified name (or synonym).
Parameters: x (str) – Name or synonym for the target entity. Returns: The URI or value corresponding to the entry, represented as a string. Return type: str
-
get_children(uri)[source]¶ Return all (not just immediate) children of a given entry.
Parameters: uri (str) – The URI of the entry whose children are to be returned. See the get_uri method to construct this URI from a name space and id.
-
get_parents(uri, type='all')[source]¶ Return parents of a given entry.
Parameters: - uri (str) – The URI of the entry whose parents are to be returned. See the get_uri method to construct this URI from a name space and id.
- type (str) – ‘all’: return all parents irrespective of level; ‘immediate’: return only the immediate parents; ‘top’: return only the highest level parents
-
is_equal(ns1, id1, ns2, id2)[source]¶ Return True if two entities are in an “is_equal” relationship
Parameters: - ns1 (str) – Namespace code for an entity.
- id1 (str) – URI for an entity.
- ns2 (str) – Namespace code for an entity.
- id2 (str) – URI for an entity.
Returns: True if t1 has an “is_equal” relationship with t2.
Return type: bool
-
is_opposite(ns1, id1, ns2, id2)[source]¶ Return True if two entities are in an “is_opposite” relationship
Parameters: - ns1 (str) – Namespace code for an entity.
- id1 (str) – URI for an entity.
- ns2 (str) – Namespace code for an entity.
- id2 (str) – URI for an entity.
Returns: True if t1 has an “is_opposite” relationship with t2.
Return type: bool
-
isa(ns1, id1, ns2, id2)[source]¶ Return True if one entity has an “isa” relationship to another.
Parameters: - ns1 (str) – Namespace code for an entity.
- id1 (string) – URI for an entity.
- ns2 (str) – Namespace code for an entity.
- id2 (str) – URI for an entity.
Returns: True if t1 has an “isa” relationship with t2, either directly or through a series of intermediates; False otherwise.
Return type: bool
-
isa_or_partof(ns1, id1, ns2, id2)[source]¶ Return True if two entities are in an “isa” or “partof” relationship
Parameters: - ns1 (str) – Namespace code for an entity.
- id1 (str) – URI for an entity.
- ns2 (str) – Namespace code for an entity.
- id2 (str) – URI for an entity.
Returns: True if t1 has a “isa” or “partof” relationship with t2, either directly or through a series of intermediates; False otherwise.
Return type: bool
-
load_from_rdf_file(rdf_file)[source]¶ Initialize given an RDF input file representing the hierarchy.”
Parameters: rdf_file (str) – Path to an RDF file.
-
load_from_rdf_graph(rdf_graph)[source]¶ Initialize given an RDF Graph representing the hierarchy.”
Parameters: rdf_graph (rdflib.Graph) – An rdflib Graph representing the hierarchy.
-
load_from_rdf_string(rdf_str)[source]¶ Initialize given an RDF string representing the hierarchy.”
Parameters: rdf_str (str) – An RDF string.
-
partof(ns1, id1, ns2, id2)[source]¶ Return True if one entity is “partof” another.
Parameters: - ns1 (str) – Namespace code for an entity.
- id1 (str) – URI for an entity.
- ns2 (str) – Namespace code for an entity.
- id2 (str) – URI for an entity.
Returns: True if t1 has a “partof” relationship with t2, either directly or through a series of intermediates; False otherwise.
Return type: bool
-
class
indra.preassembler.hierarchy_manager.YamlHierarchyManager(root, yaml_to_rdf, add_leaves)[source]¶ Class to manage YAML-based hierarchies.
Parameters: - root (dict) – A YAML data structure loaded with the yaml package.
- yaml_to_rdf (function) – A function that takes the root object as an argument and returns an RDF graph.
-
indra.preassembler.hierarchy_manager.get_bio_hierarchies(from_pickle=True)[source]¶ Return default hierarchies for the Bio context.
Parameters: from_pickle (Optional[bool[) – If True, hierarchies are loded from a pre-generated pickle file. Otherwise, they are regenerated from RDF files (slower). Default: True Returns: A dict of hierarchy managers for each type of hierarchy. Return type: dict[str, HierarchyManager]
-
indra.preassembler.hierarchy_manager.get_wm_hierarchies()[source]¶ Return default hierarchy managers for the World Modeling context.
Returns: A dict of hierarchy managers for each type of hierarchy, in this context only an entity hierarchy is provided in the dict. Return type: dict[str, HierarchyManager]