Graphs: cicada_tools.graphs¶
from cicada_analysis.cicada_tools.graphs.<module> import <function>
graphs.graph_building (Building graphs)¶
-
build_connectivity_graphs¶
build_connectivity_graphs(spike_data, ...) -> networkx.Graph
Build a NetworkX graph from spike data using spike triggered averages. spike_data can be a binary 2D array (cells x frames) or a list ([[spiketimes] for each cell]).
| Parameter | Type | Description |
|---|---|---|
spike_data |
np.ndarray or list | Spike data |
Returns: networkx.Graph — Graph object
-
build_graph_from_adjacency_matrix¶
build_graph_from_adjacency_matrix(adjacency_matrix) -> networkx.Graph
Build a weighted NetworkX graph from a square adjacency matrix.
| Parameter | Type | Description |
|---|---|---|
adjacency_matrix |
np.ndarray | Square adjacency matrix |
Returns: networkx.Graph — Weighted graph
-
graph_key¶
graph_key(spike_data, **parameters) -> dict
What a graph depends on, to find it again in a later run (cached_graph): the sha256 of the data it is built from (so every selection of cells, epochs or file is covered), the build parameters and the cicada-analysis version.
| Parameter | Type | Description |
|---|---|---|
spike_data |
np.ndarray or list | The builder's input: a 2-D array (cells x frames) or a list of arrays (spike times per unit) |
**parameters |
The build parameters (JSON-serializable values) |
Returns: dict — {"data_sha256", "cicada_analysis", **parameters}
-
cached_graph¶
cached_graph(path_graphml, key) -> tuple
A graph saved by an earlier run, if it was built from the same inputs: loaded only if its key file <path_graphml>.json (written by save_graph_key) holds key. A graph without key file (saved by an older version) is not loaded.
| Parameter | Type | Description |
|---|---|---|
path_graphml |
str | Path of the .graphml file |
key |
dict | graph_key of the graph to build |
Returns: tuple — (graph, message): the loaded networkx.DiGraph or None (to build), and why (no saved graph, no key file, which key fields differ, or the build date of the graph loaded)
-
save_graph_key¶
save_graph_key(path_graphml, key) -> None
Write the key of a saved graph next to it (<path_graphml>.json), with the build date; read by cached_graph.
| Parameter | Type | Description |
|---|---|---|
path_graphml |
str | Path of the .graphml file |
key |
dict | graph_key of the graph |
-
build_graph_from_transition_dict¶
build_graph_from_transition_dict(transition_dict, n_connected_cell_to_add, ...) -> networkx.DiGraph
Build a directed graph from a neuron-to-neuron transition probability dict.
| Parameter | Type | Description |
|---|---|---|
transition_dict |
dict | Transition probability dictionary |
n_connected_cell_to_add |
int | Number of connected cells to add |
Returns: networkx.DiGraph — Directed graph
graphs.graph_analysis (Analysing graphs)¶
-
graph_tables¶
graph_tables(graph)
A graph as two tables: its nodes (with their in- and out-degree, or degree, and their attributes) and its edges (source, target and their attributes, e.g. weight).
| Parameter | Type | Default | Description |
|---|---|---|---|
graph |
networkx.Graph | The graph (directed or not) |
Returns: tuple[DataFrame, DataFrame] — (nodes, edges)
-
detect_hub_cells¶
detect_hub_cells(graphs_to_analyse, cell_connectivity_threshold=5, top_connected_cells=20, verbose=True) -> dict
Identify hub nodes from multiple graphs (graphs_to_analyse: {graph id: graph}) by identifying highly connected cells (at least cell_connectivity_threshold % local connectivity, in the top_connected_cells % most connected cells) and using betweenness centrality.
| Parameter | Type | Default | Description |
|---|---|---|---|
graphs_to_analyse |
dict | {graph id: graph} dictionary |
|
cell_connectivity_threshold |
int | 5 | Minimum connectivity percentage |
top_connected_cells |
int | 20 | Top N most connected cells |
verbose |
bool | True | Verbose output |
Returns: dict — {'session': list of hub cell indices}
-
find_paths_in_a_graph¶
find_paths_in_a_graph(graph, shortest_path_on_weight, with_weight, use_longest_path=False, debug_mode=False) -> tuple
Extract sequences from a graph: repeatedly take the longest of the shortest paths (or the longest path of the DAG with use_longest_path; ties broken by the lowest weight with shortest_path_on_weight), remove it from the graph, and set aside the cells left without neighbours. Returns (seq_list, isolates_cell). The graph is modified.
| Parameter | Type | Default | Description |
|---|---|---|---|
graph |
networkx.Graph | Input graph | |
shortest_path_on_weight |
bool | Use weighted shortest paths | |
with_weight |
bool | Use edge weights | |
use_longest_path |
bool | False | Use longest path for DAG |
debug_mode |
bool | False | Debug output |
Returns: tuple — (seq_list, isolates_cell)
-
welsh_powell¶
welsh_powell(graph) -> dict
Welsh-Powell graph coloring algorithm.
| Parameter | Type | Description |
|---|---|---|
graph |
networkx.Graph | Input graph |
Returns: dict — {node: color_index}