Subgraph Expansion Workflow

Deletion functions to supplement pybel.struct.mutation.expansion.

pybel_tools.mutation.expansion.get_peripheral_successor_edges(graph, subgraph)[source]

Get the set of possible successor edges peripheral to the sub-graph.

The source nodes in this iterable are all inside the sub-graph, while the targets are outside.

Return type

Iterable[Tuple[BaseEntity, BaseEntity, str]]

pybel_tools.mutation.expansion.get_peripheral_predecessor_edges(graph, subgraph)[source]

Get the set of possible predecessor edges peripheral to the sub-graph.

The target nodes in this iterable are all inside the sub-graph, while the sources are outside.

Return type

Iterable[Tuple[BaseEntity, BaseEntity, str]]

pybel_tools.mutation.expansion.count_sources(edge_iter)[source]

Count the source nodes in an edge iterator with keys and data.

Return type

Counter

Returns

A counter of source nodes in the iterable

pybel_tools.mutation.expansion.count_targets(edge_iter)[source]

Count the target nodes in an edge iterator with keys and data.

Return type

Counter

Returns

A counter of target nodes in the iterable

pybel_tools.mutation.expansion.count_possible_successors(graph, subgraph)[source]
Parameters
  • graph (BELGraph) – A BEL graph

  • subgraph (BELGraph) – An iterator of BEL nodes

Return type

Counter

Returns

A counter of possible successor nodes

pybel_tools.mutation.expansion.count_possible_predecessors(graph, subgraph)[source]
Parameters
  • graph (BELGraph) – A BEL graph

  • subgraph (BELGraph) – An iterator of BEL nodes

Return type

Counter

Returns

A counter of possible predecessor nodes

pybel_tools.mutation.expansion.get_subgraph_edges(graph, annotation, value, source_filter=None, target_filter=None)[source]

Gets all edges from a given subgraph whose source and target nodes pass all of the given filters

Parameters
  • graph (pybel.BELGraph) – A BEL graph

  • annotation (str) – The annotation to search

  • value (str) – The annotation value to search by

  • source_filter – Optional filter for source nodes (graph, node) -> bool

  • target_filter – Optional filter for target nodes (graph, node) -> bool

Returns

An iterable of (source node, target node, key, data) for all edges that match the annotation/value and node filters

Return type

iter[tuple]

pybel_tools.mutation.expansion.get_subgraph_peripheral_nodes(graph, subgraph, node_predicates=None, edge_predicates=None)[source]

Get a summary dictionary of all peripheral nodes to a given sub-graph.

Returns

A dictionary of {external node: {‘successor’: {internal node: list of (key, dict)}, ‘predecessor’: {internal node: list of (key, dict)}}}

Return type

dict

For example, it might be useful to quantify the number of predecessors and successors:

>>> from pybel.struct.filters import exclude_pathology_filter
>>> value = 'Blood vessel dilation subgraph'
>>> sg = get_subgraph_by_annotation_value(graph, annotation='Subgraph', value=value)
>>> p = get_subgraph_peripheral_nodes(graph, sg, node_predicates=exclude_pathology_filter)
>>> for node in sorted(p, key=lambda n: len(set(p[n]['successor']) | set(p[n]['predecessor'])), reverse=True):
>>>     if 1 == len(p[value][node]['successor']) or 1 == len(p[value][node]['predecessor']):
>>>         continue
>>>     print(node,
>>>           len(p[node]['successor']),
>>>           len(p[node]['predecessor']),
>>>           len(set(p[node]['successor']) | set(p[node]['predecessor'])))
pybel_tools.mutation.expansion.expand_periphery(universe, graph, node_predicates=None, edge_predicates=None, threshold=2)[source]

Iterates over all possible edges, peripheral to a given subgraph, that could be added from the given graph. Edges could be added if they go to nodes that are involved in relationships that occur with more than the threshold (default 2) number of nodes in the subgraph.

Parameters
  • universe (BELGraph) – The universe of BEL knowledge

  • graph (BELGraph) – The (sub)graph to expand

  • threshold (int) – Minimum frequency of betweenness occurrence to add a gap node

A reasonable edge filter to use is pybel_tools.filters.keep_causal_edges() because this function can allow for huge expansions if there happen to be hub nodes.

Return type

None

pybel_tools.mutation.expansion.enrich_complexes(graph)[source]

Add all of the members of the complex abundances to the graph.

Return type

None

pybel_tools.mutation.expansion.enrich_composites(graph)[source]

Adds all of the members of the composite abundances to the graph.

pybel_tools.mutation.expansion.enrich_reactions(graph)[source]

Adds all of the reactants and products of reactions to the graph.

pybel_tools.mutation.expansion.enrich_variants(graph, func=None)[source]

Add the reference nodes for all variants of the given function.

Parameters
  • graph (BELGraph) – The target BEL graph to enrich

  • func (Union[None, str, Iterable[str]]) – The function by which the subject of each triple is filtered. Defaults to the set of protein, rna, mirna, and gene.

pybel_tools.mutation.expansion.enrich_unqualified(graph)[source]

Enrich the sub-graph with the unqualified edges from the graph.

The reason you might want to do this is you induce a sub-graph from the original graph based on an annotation filter, but the unqualified edges that don’t have annotations that most likely connect elements within your graph are not included.

See also

This function thinly wraps the successive application of the following functions:

Equivalent to:

>>> enrich_complexes(graph)
>>> enrich_composites(graph)
>>> enrich_reactions(graph)
>>> enrich_variants(graph)
pybel_tools.mutation.expansion.expand_internal(universe, graph, edge_predicates=None)[source]

Edges between entities in the sub-graph that pass the given filters.

Parameters
  • universe (BELGraph) – The full graph

  • graph (BELGraph) – A sub-graph to find the upstream information

  • edge_predicates (Union[Callable[[BELGraph, BaseEntity, BaseEntity, str], bool], Iterable[Callable[[BELGraph, BaseEntity, BaseEntity, str], bool]], None]) – Optional list of edge filter functions (graph, node, node, key, data) -> bool

Return type

None

pybel_tools.mutation.expansion.expand_internal_causal(universe, graph)[source]

Add causal edges between entities in the sub-graph.

Is an extremely thin wrapper around expand_internal().

Parameters
  • universe (BELGraph) – A BEL graph representing the universe of all knowledge

  • graph (BELGraph) – The target BEL graph to enrich with causal relations between contained nodes

Equivalent to:

>>> from pybel_tools.mutation import expand_internal
>>> from pybel.struct.filters.edge_predicates import is_causal_relation
>>> expand_internal(universe, graph, edge_predicates=is_causal_relation)
Return type

None