Subgraph Expansion Workflow¶

pybel_tools.mutation.expansion.
get_upstream_causal_subgraph
(graph, nbunch)[source]¶ Induces a subgraph from all of the upstream causal entities of the nodes in the nbunch
Parameters:  graph (pybel.BELGraph) – A BEL graph
 or list[tuple] nbunch (tuple) – A BEL node or iterable of BEL nodes
Returns: A BEL Graph
Return type:

pybel_tools.mutation.expansion.
get_peripheral_successor_edges
(graph, subgraph)[source]¶ Gets the set of possible successor edges peripheral to the subgraph. The source nodes in this iterable are all inside the subgraph, while the targets are outside.
Parameters:  graph (pybel.BELGraph) – A BEL graph
 subgraph – An iterator of BEL nodes
Returns: An iterable of possible successor edges (4tuples of node, node, key, data)
Return type:

pybel_tools.mutation.expansion.
get_peripheral_predecessor_edges
(graph, subgraph)[source]¶ Gets the set of possible predecessor edges peripheral to the subgraph. The target nodes in this iterable are all inside the subgraph, while the sources are outside.
Parameters:  graph (pybel.BELGraph) – A BEL graph
 subgraph – An iterator of BEL nodes
Returns: An iterable on possible predecessor edges (4tuples of node, node, key, data)
Return type:

pybel_tools.mutation.expansion.
count_sources
(edge_iter)[source]¶ Counts the source nodes in an edge iterator with keys and data
Parameters: edge_iter (iter[tuple]) – An iterable on possible predecessor edges (4tuples of node, node, key, data) Returns: A counter of source nodes in the iterable Return type: collections.Counter

pybel_tools.mutation.expansion.
count_targets
(edge_iter)[source]¶ Counts the target nodes in an edge iterator with keys and data
Parameters: edge_iter (iter[tuple]) – An iterable on possible predecessor edges (4tuples of node, node, key, data) Returns: A counter of target nodes in the iterable Return type: collections.Counter

pybel_tools.mutation.expansion.
count_possible_successors
(graph, subgraph)[source]¶ Parameters:  graph (pybel.BELGraph) – A BEL graph
 subgraph – An iterator of BEL nodes
Returns: A counter of possible successor nodes
Return type:

pybel_tools.mutation.expansion.
count_possible_predecessors
(graph, subgraph)[source]¶ Parameters:  graph (pybel.BELGraph) – A BEL graph
 subgraph – An iterator of BEL nodes
Returns: A counter of possible predecessor nodes
Return type:

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:

pybel_tools.mutation.expansion.
get_subgraph_peripheral_nodes
(graph, subgraph, node_filters=None, edge_filters=None)[source]¶ Gets a summary dictionary of all peripheral nodes to a given subgraph
Parameters:  graph (pybel.BELGraph) – A BEL graph
 subgraph (iter[tuple]) – A set of nodes
 node_filters (lambda) – Optional. A list of node filter predicates with the interface (graph, node) > bool. See
pybel_tools.filters.node_filters
for more information  edge_filters (lambda) – Optional. A list of edge filter predicates with the interface (graph, node, node, key, data)
> bool. See
pybel_tools.filters.edge_filters
for more information
Returns: A dictionary of {external node: {‘successor’: {internal node: list of (key, dict)}, ‘predecessor’: {internal node: list of (key, dict)}}}
Return type: For example, it might be useful to quantify the number of predecessors and successors
>>> import pybel_tools as pbt >>> sgn = 'Blood vessel dilation subgraph' >>> sg = pbt.selection.get_subgraph_by_annotation_value(graph, annotation='Subgraph', value=sgn) >>> p = pbt.mutation.get_subgraph_peripheral_nodes(graph, sg, node_filters=pbt.filters.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[sgn][node]['successor']) or 1 == len(p[sgn][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_filters=None, edge_filters=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 (pybel.BELGraph) – The universe of BEL knowledge
 graph (pybel.BELGraph) – The (sub)graph to expand
 node_filters (lambda) – Optional. A list of node filter predicates with the interface (graph, node) > bool. See
pybel_tools.filters.node_filters
for more information  edge_filters (lambda) – Optional. A list of edge filter predicates with the interface (graph, node, node, key, data)
> bool. See
pybel_tools.filters.edge_filters
for more information  threshold – 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.

pybel_tools.mutation.expansion.
enrich_grouping
(universe, graph, function, relation)[source]¶ Adds all of the grouped elements. See
enrich_complexes()
,enrich_composites()
, andenrich_reactions()
Parameters:  universe (pybel.BELGraph) – A BEL graph representing the universe of all knowledge
 graph (pybel.BELGraph) – The target BEL graph to enrich
 function (str) – The function by which the subject of each triple is filtered
 relation (str) – The relationship by which the predicate of each triple is filtered

pybel_tools.mutation.expansion.
enrich_complexes
(universe, graph)[source]¶ Adds all of the members of the complexes in the subgraph that are in the original graph with appropriate
pybel.constants.HAS_COMPONENT
relationships, in place.Parameters:  universe (pybel.BELGraph) – A BEL graph representing the universe of all knowledge
 graph (pybel.BELGraph) – The target BEL graph to enrich

pybel_tools.mutation.expansion.
enrich_composites
(universe, graph)[source]¶ Adds all of the members of the composite abundances in the subgraph that are in the original graph with appropriate
pybel.constants.HAS_COMPONENT
relationships, in place.Parameters:  universe (pybel.BELGraph) – A BEL graph representing the universe of all knowledge
 graph (pybel.BELGraph) – The target BEL graph to enrich

pybel_tools.mutation.expansion.
enrich_reactions
(universe, graph)[source]¶ Adds all of the reactants and products of reactions in the subgraph that are in the original graph with appropriate
pybel.constants.HAS_REACTANT
andpybel.constants.HAS_PRODUCT
relationships, respectively, in place.Parameters:  universe (pybel.BELGraph) – A BEL graph representing the universe of all knowledge
 graph (pybel.BELGraph) – The target BEL graph to enrich

pybel_tools.mutation.expansion.
enrich_variants
(universe, graph)[source]¶ Adds the reference nodes for all variants of genes, RNAs, miRNAs, and proteins
Parameters:  universe (pybel.BELGraph) – A BEL graph representing the universe of all knowledge
 graph (pybel.BELGraph) – The target BEL graph to enrich
Equivalent to:
>>> from pybel.constants import PROTEIN, RNA, MIRNA, GENE >>> enrich_variants_helper(universe, graph, PROTEIN) >>> enrich_variants_helper(universe, graph, RNA) >>> enrich_variants_helper(universe, graph, MIRNA) >>> enrich_variants_helper(universe, graph, GENE)
See also
enrich_variants_helper()

pybel_tools.mutation.expansion.
enrich_unqualified
(universe, graph)[source]¶ Enriches the subgraph with the unqualified edges from the graph.
Parameters:  universe (pybel.BELGraph) – A BEL graph representing the universe of all knowledge
 graph (pybel.BELGraph) – The target BEL graph to enrich
The reason you might want to do this is you induce a subgraph 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(universe, graph) >>> enrich_composites(universe, graph) >>> enrich_reactions(universe, graph) >>> enrich_variants(universe, graph)

pybel_tools.mutation.expansion.
expand_internal
(universe, graph, edge_filters=None)[source]¶ Edges between entities in the subgraph that pass the given filters
Parameters:  universe (pybel.BELGraph) – The full graph
 graph (pybel.BELGraph) – A subgraph to find the upstream information
 edge_filters (list or lambda) – Optional list of edge filter functions (graph, node, node, key, data) > bool

pybel_tools.mutation.expansion.
expand_internal_causal
(universe, graph)[source]¶ Adds causal edges between entities in the subgraph. Is an extremely thin wrapper around
expand_internal()
.Parameters:  universe (pybel.BELGraph) – A BEL graph representing the universe of all knowledge
 graph (pybel.BELGraph) – The target BEL graph to enrich with causal relations between contained nodes
Equivalent to:
>>> import pybel_tools as pbt >>> pbt.mutation.expand_internal(universe, graph, edge_filters=pbt.filters.edge_is_causal)

pybel_tools.mutation.expansion.
expand_node_neighborhood
(universe, graph, node)[source]¶ Expands around the neighborhoods of the given node in the result graph by looking at the universe graph, in place.
Parameters:  universe (pybel.BELGraph) – The graph containing the stuff to add
 graph (pybel.BELGraph) – The graph to add stuff to
 node (tuple) – A node tuples from the query graph

pybel_tools.mutation.expansion.
expand_nodes_neighborhoods
(universe, graph, nodes)[source]¶ Expands around the neighborhoods of the given node in the result graph by looking at the universe graph, in place.
Parameters:  universe (pybel.BELGraph) – The graph containing the stuff to add
 graph (pybel.BELGraph) – The graph to add stuff to
 nodes (list[tuple]) – A node tuples from the query graph

pybel_tools.mutation.expansion.
expand_all_node_neighborhoods
(universe, graph, filter_pathologies=False)[source]¶ Expands the neighborhoods of all nodes in the given graph based on the universe graph.
Parameters:  universe (pybel.BELGraph) – The graph containing the stuff to add
 graph (pybel.BELGraph) – The graph to add stuff to
 filter_pathologies (bool) – Should expansion take place around pathologies?

pybel_tools.mutation.expansion.
expand_upstream_causal_subgraph
(universe, graph)[source]¶ Adds the upstream causal relations to the given subgraph
Parameters:  universe (pybel.BELGraph) – A BEL graph representing the universe of all knowledge
 graph (pybel.BELGraph) – The target BEL graph to enrich with upstream causal controllers of contained nodes