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
- 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
pubmed_identifiers (str or list[str]) – A PubMed identifier or list of PubMed identifiers
- Return type
- pybel.struct.mutation.induction.get_subgraph_by_authors(graph, authors)[source]
Induce a sub-graph over the edges retrieved publications by the given author(s).
- Parameters
graph (pybel.BELGraph) – A BEL graph
- 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 (
BELGraph
) – A BEL graphnodes (
Iterable
[BaseEntity
]) – An iterable of BEL nodes
- Return type
- Returns
A BEL graph induced around the neighborhoods of the given nodes
- 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
- 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
- pybel.struct.mutation.induction.get_graph_with_random_edges(graph, n_edges)[source]
Build a new graph from a seeding of edges.
- 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.
- Parameters
node_blacklist (
Set
[BaseEntity
]) – Nodes to filter outinvert_degrees (
Optional
[bool
]) – Should the degrees be inverted? Defaults to true.
- Return type
- 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
- 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
graph (
BELGraph
) – A BEL graphedge_predicates (
Union
[Callable
[[BELGraph
,BaseEntity
,BaseEntity
,str
],bool
],Iterable
[Callable
[[BELGraph
,BaseEntity
,BaseEntity
,str
],bool
]],None
]) – An edge predicate or list of edge predicates
- Return type
- 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.
- Parameters
graph (
BELGraph
) – A BEL graphnodes (
Iterable
[BaseEntity
]) – A list of BEL nodes in the graph
- Return type
- 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).