Summary

Summary functions for BEL graphs.

pybel.struct.summary.iter_annotation_value_pairs(graph)[source]

Iterate over the key/value pairs, with duplicates, for each annotation used in a BEL graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Iterable[Tuple[str, Entity]]

pybel.struct.summary.iter_annotation_values(graph, annotation)[source]

Iterate over all of the values for an annotation used in the graph.

Parameters
  • graph (BELGraph) – A BEL graph

  • annotation (str) – The annotation to grab

Return type

Iterable[Entity]

pybel.struct.summary.get_annotation_values_by_annotation(graph)[source]

Get the set of values for each annotation used in a BEL graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Mapping[str, Set[Entity]]

Returns

A dictionary of {annotation key: set of annotation values}

pybel.struct.summary.get_annotation_values(graph, annotation)[source]

Get all values for the given annotation.

Parameters
  • graph (BELGraph) – A BEL graph

  • annotation (str) – The annotation to summarize

Return type

Set[Entity]

Returns

A set of all annotation values

pybel.struct.summary.count_relations(graph)[source]

Return a histogram over all relationships in a graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Counter

Returns

A Counter from {relation type: frequency}

pybel.struct.summary.get_annotations(graph)[source]

Get the set of annotations used in the graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Set[str]

Returns

A set of annotation keys

pybel.struct.summary.count_annotations(graph)[source]

Count how many times each annotation is used in the graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Counter

Returns

A Counter from {annotation key: frequency}

pybel.struct.summary.get_unused_annotations(graph)[source]

Get the set of all annotations that are defined in a graph, but are never used.

Parameters

graph (BELGraph) – A BEL graph

Return type

Set[str]

Returns

A set of annotations

pybel.struct.summary.get_unused_list_annotation_values(graph)[source]

Get all of the unused values for list annotations.

Parameters

graph (BELGraph) – A BEL graph

Return type

Mapping[str, Set[str]]

Returns

A dictionary of {str annotation: set of str values that aren’t used}

pybel.struct.summary.get_metaedge_to_key(graph)[source]

Get all edge types.

Return type

Mapping[Tuple[str, Optional[Tuple], Optional[Tuple]], Set[Tuple[BaseEntity, BaseEntity, str]]]

pybel.struct.summary.iter_sample_metaedges(graph)[source]

Iterate sampled metaedges.

pybel.struct.summary.get_syntax_errors(graph)[source]

List the syntax errors encountered during compilation of a BEL script.

Return type

List[Tuple[Optional[str], BELParserWarning, Mapping]]

pybel.struct.summary.count_error_types(graph)[source]

Count the occurrence of each type of error in a graph.

Return type

Counter[str]

Returns

A Counter of {error type: frequency}

pybel.struct.summary.count_naked_names(graph)[source]

Count the frequency of each naked name (names without namespaces).

Return type

Counter[str]

Returns

A Counter from {name: frequency}

pybel.struct.summary.get_naked_names(graph)[source]

Get the set of naked names in the graph.

Return type

Set[str]

pybel.struct.summary.calculate_incorrect_name_dict(graph)[source]

Get missing names grouped by namespace.

Return type

Mapping[str, List[str]]

pybel.struct.summary.calculate_error_by_annotation(graph, annotation)[source]

Group error names by a given annotation.

Return type

Mapping[str, List[str]]

pybel.struct.summary.get_functions(graph)[source]

Get the set of all functions used in this graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Set[str]

Returns

A set of functions

pybel.struct.summary.count_functions(graph)[source]

Count the frequency of each function present in a graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Counter[str]

Returns

A Counter from {function: frequency}

pybel.struct.summary.get_namespaces(graph)[source]

Get the set of all namespaces used in this graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Set[str]

Returns

A set of namespaces

pybel.struct.summary.count_namespaces(graph)[source]

Count the frequency of each namespace across all nodes (that have namespaces).

Parameters

graph (BELGraph) – A BEL graph

Return type

Counter[str]

Returns

A Counter from {namespace: frequency}

pybel.struct.summary.get_unused_namespaces(graph)[source]

Get the set of all namespaces that are defined in a graph, but are never used.

Parameters

graph (BELGraph) – A BEL graph

Return type

Set[str]

Returns

A set of namespaces that are included but not used

pybel.struct.summary.count_names_by_namespace(graph, namespace)[source]

Get the set of all of the names in a given namespace that are in the graph.

Parameters
  • graph (BELGraph) – A BEL graph

  • namespace (str) – A namespace prefix

Return type

Counter[str]

Returns

A counter from {name: frequency}

Raises

IndexError – if the namespace is not defined in the graph.

pybel.struct.summary.get_names(graph)[source]

Get all names for each namespace.

Parameters

graph (BELGraph) – A BEL graph

Return type

Mapping[str, Set[str]]

pybel.struct.summary.get_names_by_namespace(graph, namespace)[source]

Get the set of all of the names in a given namespace that are in the graph.

Parameters
Return type

Set[str]

Returns

A set of names belonging to the given namespace that are in the given graph

Raises

IndexError – if the namespace is not defined in the graph.

pybel.struct.summary.iterate_node_entities(node)[source]

Iterate over all named entities that comprise a node.

This includes the node’s name, the members/reactants/products of the node, the fusion partners, the named variants, and all recursive ones too.

Parameters

node (BaseEntity) – A BEL node

Entities in a simple protein:

>>> from pybel.dsl import Protein
>>> from pybel.language import Entity
>>> from pybel.struct.summary import iterate_entities
>>> protein = Protein(namespace='hgnc', identifier='1455', name='CALR')
>>> protein_entities = list(iterate_node_entities(protein))
>>> assert [Entity(namespace='hgnc', identifier='1455', name='CALR')] == protein_entities

Entities in a protein complex:

>>> from pybel.dsl import Protein, ComplexAbundance
>>> from pybel.language import Entity
>>> from pybel.struct.summary import iterate_entities
>>> protein_1 = Protein(namespace='hgnc', identifier='1')
>>> protein_2 = Protein(namespace='hgnc', identifier='2')
>>> complex_1 = ComplexAbundance([protein_1, protein_2])
>>> complex_entities = list(iterate_node_entities(complex_1))
>>> assert [Entity(namespace='hgnc', identifier='1'), Entity(namespace='hgnc', identifier='2')] == complex_entities
Return type

Iterable[Entity]

pybel.struct.summary.iterate_entities(graph)[source]

Iterate over all entities in the graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Iterable[Entity]

pybel.struct.summary.node_is_grounded(node)[source]

Check if a node is grounded.

Parameters

node (BaseEntity) – A BEL node

Return type

bool

pybel.struct.summary.get_ungrounded_nodes(graph)[source]

Get all ungrounded nodes in the graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Set[BaseEntity]

pybel.struct.summary.count_variants(graph)[source]

Count how many of each type of variant a graph has.

Parameters

graph (BELGraph) – A BEL graph

Return type

Counter[str]

pybel.struct.summary.count_pathologies(graph)[source]

Count the number of edges in which each pathology is incident.

Parameters

graph (BELGraph) – A BEL graph

Return type

Counter[BaseEntity]

pybel.struct.summary.get_top_pathologies(graph, n=15)[source]

Get the top highest relationship-having edges in the graph by BEL.

Parameters
  • graph (BELGraph) – A BEL graph

  • n (Optional[int]) – The number of top connected pathologies to return. If None, returns all nodes

Return type

List[Tuple[BaseEntity, int]]

pybel.struct.summary.get_top_hubs(graph, *, n=15)[source]

Get the top hubs in the graph by BEL.

Parameters
  • graph (BELGraph) – A BEL graph

  • n (Optional[int]) – The number of top hubs to return. If None, returns all nodes

Return type

List[Tuple[BaseEntity, int]]

pybel.struct.summary.iterate_pubmed_identifiers(graph)[source]

Iterate over all PubMed identifiers in a graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Iterable[str]

Returns

An iterator over the PubMed identifiers in the graph

pybel.struct.summary.iterate_pmc_identifiers(graph)[source]

Iterate over all PMC identifiers in a graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Iterable[str]

Returns

An iterator over the PMC identifiers in the graph

pybel.struct.summary.get_pubmed_identifiers(graph)[source]

Get the set of all PubMed identifiers cited in the construction of a graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Set[str]

Returns

A set of all PubMed identifiers cited in the construction of this graph

pybel.struct.summary.get_pmc_identifiers(graph)[source]

Get the set of all PMC identifiers cited in the construction of a graph.

Parameters

graph (BELGraph) – A BEL graph

Return type

Set[str]

Returns

A set of all PMC identifiers cited in the construction of this graph

Misc. getters.

pybel.struct.getters.get_tf_pairs(graph, direct_only=False)[source]

Iterate pairs of p(X) and r(Y) such that complex(p(X), g(Y)) -> r(Y).

Parameters
  • graph (BELGraph) – A BEL graph

  • direct_only (bool) – If true, only uses directlyIncreases and directlyDecreases relations. Otherwise, allows indirect relations.

Return type

Iterable[Tuple[Protein, Rna, int]]