Utilities¶
This module contains functions useful throughout PyBEL Tools
-
pybel_tools.utils.pairwise(iterable)[source]¶ Iterate over pairs in list s -> (s0,s1), (s1,s2), (s2, s3), …
- Return type
Iterable[Tuple[~X, ~X]]
-
pybel_tools.utils.count_defaultdict(dict_of_lists)[source]¶ Count the number of elements in each value of the dictionary.
-
pybel_tools.utils.count_dict_values(dict_of_counters)[source]¶ Count the number of elements in each value (can be list, Counter, etc).
-
pybel_tools.utils.tanimoto_set_similarity(x, y)[source]¶ Calculate the tanimoto set similarity.
- Return type
-
pybel_tools.utils.min_tanimoto_set_similarity(x, y)[source]¶ Calculate the tanimoto set similarity using the minimum size.
-
pybel_tools.utils.calculate_single_tanimoto_set_distances(target, dict_of_sets)[source]¶ Return a dictionary of distances keyed by the keys in the given dict.
Distances are calculated based on pairwise tanimoto similarity of the sets contained
-
pybel_tools.utils.calculate_tanimoto_set_distances(dict_of_sets)[source]¶ Return a distance matrix keyed by the keys in the given dict.
Distances are calculated based on pairwise tanimoto similarity of the sets contained.
-
pybel_tools.utils.calculate_global_tanimoto_set_distances(dict_of_sets)[source]¶ Calculate an alternative distance matrix based on the following equation.
\[distance(A, B)=1- \|A \cup B\| / \| \cup_{s \in S} s\|\]
-
pybel_tools.utils.barh(d, plt, title=None)[source]¶ A convenience function for plotting a horizontal bar plot from a Counter
-
pybel_tools.utils.barv(d, plt, title=None, rotation='vertical')[source]¶ A convenience function for plotting a vertical bar plot from a Counter
-
pybel_tools.utils.safe_add_edge(graph, u, v, key, attr_dict, **attr)[source]¶ Adds an edge while preserving negative keys, and paying no respect to positive ones
- Parameters
graph (pybel.BELGraph) – A BEL Graph
u (tuple) – The source BEL node
v (tuple) – The target BEL node
key (int) – The edge key. If less than zero, corresponds to an unqualified edge, else is disregarded
attr_dict (dict) – The edge data dictionary
attr (dict) – Edge data to assign via keyword arguments
-
pybel_tools.utils.prepare_c3(data, y_axis_label='y', x_axis_label='x')[source]¶ Prepares C3 JSON for making a bar chart from a Counter
-
pybel_tools.utils.prepare_c3_time_series(data, y_axis_label='y', x_axis_label='x')[source]¶ Prepare C3 JSON string dump for a time series.
-
pybel_tools.utils.calculate_betweenness_centality(graph, number_samples=200)[source]¶ Calculate the betweenness centrality over nodes in the graph.
Tries to do it with a certain number of samples, but then tries a complete approach if it fails.
- Return type
-
pybel_tools.utils.get_circulations(elements)[source]¶ Iterate over all possible circulations of an ordered collection (tuple or list).
Example:
>>> list(get_circulations([1, 2, 3])) [[1, 2, 3], [2, 3, 1], [3, 1, 2]]
- Return type
Iterable[~T]