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 (BELGraph) – A BEL graph

  • annotation (str) – The annotation to group by

  • values (Union[str, Iterable[str]]) – The value(s) for the annotation

Return type

BELGraph

Returns

A subgraph of the original BEL graph

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 graph

  • annotations (Union[Mapping[str, str], Mapping[str, Set[str]], Mapping[str, List[Entity]]]) – Annotation filters (match all with pybel.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

pybel.BELGraph

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

  • or list[str] authors (str) – An author or list of authors

Return type

pybel.BELGraph

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 graph

  • nodes (Iterable[BaseEntity]) – An iterable of BEL nodes

Return type

Optional[BELGraph]

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
  • graph (BELGraph) – A BEL graph

  • nodes (Iterable[BaseEntity]) – The list of nodes to use to use to find all shortest paths

  • weight (Optional[str]) – Edge data key corresponding to the edge weight. If none, uses unweighted search.

  • remove_pathologies (bool) – Should pathology nodes be removed first?

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 paths

  • weight (Optional[str]) – Edge data key corresponding to the edge weight. If None, performs unweighted search

  • remove_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 graph

  • n_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.

Parameters
  • node_blacklist (Set[BaseEntity]) – Nodes to filter out

  • invert_degrees (Optional[bool]) – Should the degrees be inverted? Defaults to true.

Return type

Optional[BaseEntity]

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

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.BELGraph

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.BELGraph

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 graph

  • edge_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

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.

Parameters
  • graph (BELGraph) – A BEL graph

  • nodes (Iterable[BaseEntity]) – A list of BEL nodes in the graph

Return type

Optional[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
  • graph (BELGraph) – A BEL graph

  • node_predicates (Union[Callable[[BELGraph, BaseEntity], bool], Iterable[Callable[[BELGraph, BaseEntity], bool]]]) – A node predicate or list of node predicates

Return type

BELGraph

pybel.struct.mutation.induction.get_largest_component(graph)[source]

Get the giant component of a graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

BELGraph

pybel.struct.mutation.induction.get_causal_subgraph(graph)[source]

Build a new sub-graph induced over the causal edges.

Parameters

graph (BELGraph) – A BEL graph

Return type

BELGraph