Induction¶
Mutations that induce a sub-graph.
-
pybel.struct.mutation.induction.
get_subgraph_by_annotation_value
(graph, annotation, values)[source]¶ Induce a sub-graph over all edges whose annotations match the given key and value.
- Parameters
graph (pybel.BELGraph) – A BEL graph
annotation (str) – The annotation to group by
- Returns
A subgraph of the original BEL graph
- Return type
-
pybel.struct.mutation.induction.
get_subgraph_by_annotations
(graph, annotations, or_=None)[source]¶ Induce a sub-graph given an annotations filter.
- Parameters
- Returns
A subgraph of the original BEL graph
- Return type
-
pybel.struct.mutation.induction.
get_subgraph_by_pubmed
(graph, pubmed_identifiers)[source]¶ Induce a sub-graph over the edges retrieved from the given PubMed identifier(s).
- Parameters
graph (pybel.BELGraph) – A BEL graph
or list[str] pubmed_identifiers (str) – A PubMed identifier or list of PubMed identifiers
- Return type
Induce a sub-graph over the edges retrieved publications by the given author(s).
- Parameters
graph (pybel.BELGraph) – A BEL graph
or list[str] authors (str) – An author or list of authors
- Return type
-
pybel.struct.mutation.induction.
get_subgraph_by_neighborhood
(graph, nodes)[source]¶ Get a BEL graph around the neighborhoods of the given nodes.
Returns none if no nodes are in the graph.
- Parameters
graph (pybel.BELGraph) – A BEL graph
nodes (
Iterable
[BaseEntity
]) – An iterable of BEL nodes
- Returns
A BEL graph induced around the neighborhoods of the given nodes
- Return type
Optional[pybel.BELGraph]
-
pybel.struct.mutation.induction.
get_nodes_in_all_shortest_paths
(graph, nodes, weight=None, remove_pathologies=False)[source]¶ Get a set of nodes in all shortest paths between the given nodes.
Thinly wraps
networkx.all_shortest_paths()
.- Parameters
graph (pybel.BELGraph) – A BEL graph
nodes (
Iterable
[BaseEntity
]) – The list of nodes to use to use to find all shortest pathsweight (
Optional
[str
]) – Edge data key corresponding to the edge weight. If none, uses unweighted search.remove_pathologies (
bool
) – Should pathology nodes be removed first?
- Returns
A set of nodes appearing in the shortest paths between nodes in the BEL graph
Note
This can be trivially parallelized using
networkx.single_source_shortest_path()
-
pybel.struct.mutation.induction.
get_subgraph_by_all_shortest_paths
(graph, nodes, weight=None, remove_pathologies=False)[source]¶ Induce a subgraph over the nodes in the pairwise shortest paths between all of the nodes in the given list.
- Parameters
graph (pybel.BELGraph) – A BEL graph
nodes (
Iterable
[BaseEntity
]) – A set of nodes over which to calculate shortest pathsweight (
Optional
[str
]) – Edge data key corresponding to the edge weight. If None, performs unweighted searchremove_pathologies (
bool
) – Should the pathology nodes be deleted before getting shortest paths?
- Returns
A BEL graph induced over the nodes appearing in the shortest paths between the given nodes
- Return type
Optional[pybel.BELGraph]
-
pybel.struct.mutation.induction.
get_random_path
(graph)[source]¶ Get a random path from the graph as a list of nodes.
- Parameters
graph (pybel.BELGraph) – A BEL graph
- Return type
List
[BaseEntity
]
-
pybel.struct.mutation.induction.
get_graph_with_random_edges
(graph, n_edges)[source]¶ Build a new graph from a seeding of edges.
- Parameters
n_edges (
int
) – Number of edges to randomly select from the given graph- Return type
-
pybel.struct.mutation.induction.
get_random_node
(graph, node_blacklist, invert_degrees=None)[source]¶ Choose a node from the graph with probabilities based on their degrees.
-
pybel.struct.mutation.induction.
get_random_subgraph
(graph, number_edges=None, number_seed_edges=None, seed=None, invert_degrees=None)[source]¶ Generate a random subgraph based on weighted random walks from random seed edges.
- Parameters
number_edges (Optional[int]) – Maximum number of edges. Defaults to
pybel_tools.constants.SAMPLE_RANDOM_EDGE_COUNT
(250).number_seed_edges (Optional[int]) – Number of nodes to start with (which likely results in different components in large graphs). Defaults to
SAMPLE_RANDOM_EDGE_SEED_COUNT
(5).seed (Optional[int]) – A seed for the random state
invert_degrees (Optional[bool]) – Should the degrees be inverted? Defaults to true.
- Return type
-
pybel.struct.mutation.induction.
get_upstream_causal_subgraph
(graph, nbunch)[source]¶ Induce a sub-graph from all of the upstream causal entities of the nodes in the nbunch.
- Return type
-
pybel.struct.mutation.induction.
get_downstream_causal_subgraph
(graph, nbunch)[source]¶ Induce a sub-graph from all of the downstream causal entities of the nodes in the nbunch.
- Return type
-
pybel.struct.mutation.induction.
get_subgraph_by_edge_filter
(graph, edge_predicates=None)[source]¶ Induce a sub-graph on all edges that pass the given filters.
- Parameters
- Returns
A BEL sub-graph induced over the edges passing the given filters
- Return type
-
pybel.struct.mutation.induction.
get_subgraph_by_induction
(graph, nodes)[source]¶ Induce a sub-graph over the given nodes or return None if none of the nodes are in the given graph.
- Parameters
graph (pybel.BELGraph) – A BEL graph
nodes (
Iterable
[BaseEntity
]) – A list of BEL nodes in the graph
- Return type
Optional[pybel.BELGraph]
-
pybel.struct.mutation.induction.
get_subgraph_by_node_filter
(graph, node_predicates)[source]¶ Induce a sub-graph on the nodes that pass the given predicate(s).
- Parameters
- Return type
-
pybel.struct.mutation.induction.
get_largest_component
(graph)[source]¶ Get the giant component of a graph.
- Parameters
graph (pybel.BELGraph) – A BEL graph
- Return type
-
pybel.struct.mutation.induction.
get_causal_subgraph
(graph)[source]¶ Build a new sub-graph induced over the causal edges.
- Parameters
graph (pybel.BELGraph) – A BEL graph
- Return type