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.
-
pybel.struct.mutation.induction.
get_subgraph_by_annotations
(graph, annotations, or_=None)[source]¶ Induce a sub-graph given an annotations filter.
- Parameters
graph (
BELGraph
) – A BEL graphannotations (
Union
[Mapping
[str
,str
],Mapping
[str
,Set
[str
]],Mapping
[str
,List
[Entity
]]]) – Annotation filters (match all withpybel.utils.subdict_matches()
)or – if True any annotation should be present, if False all annotations should be present in the edge. Defaults to True.
- Return type
BELGraph
- Returns
A subgraph of the original BEL graph
-
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.
-
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
- Return type
Set
[BaseEntity
]- 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 (
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
graph (
BELGraph
) – A BEL graphn_edges (
int
) – Number of edges to randomly select from the given graph
- Return type
BELGraph
-
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 topybel_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 toSAMPLE_RANDOM_EDGE_SEED_COUNT
(5).invert_degrees (
Optional
[bool
]) – Should the degrees be inverted? Defaults to true.
- Return type
BELGraph
-
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
- Return type
BELGraph
- Returns
A BEL sub-graph induced over the edges passing the given filters
-
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.
-
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).