skm_tools.connectivity
Are a set of nodes (e.g. differentially expressed genes) more connected than random nodes?
The test compares the subnetwork induced by the nodes with the subnetworks induced by random node sets of the same size and degree distribution, drawn from a universe (e.g. the genes measured in the experiment). Statistics: the number of edges among the nodes, and the size of the largest connected component (LCC).
Attributes
Functions
|
Are nodes more connected among themselves in g than random nodes? |
Module Contents
- skm_tools.connectivity.logger
- skm_tools.connectivity.induced_connectivity(g, nodes, universe=None, n_random=500, n_bins=10, seed=None)
Are nodes more connected among themselves in g than random nodes?
g is treated as undirected: edge directions, parallel edges (e.g. a CKN binding and a regulation edge between the same genes) and self-loops count once / not at all, so the statistics are about node pairs. Random node sets have the same size as nodes and the same degree distribution: the universe’s nodes are split into n_bins quantile bins of their degree (within the universe), and each random set draws as many nodes from each bin as nodes has there.
- Parameters:
g (networkx.Graph) – The network, e.g. CKN filtered to the edge ranks of interest.
nodes (iterable) – The nodes to test, e.g. the DEGs. Nodes that are not in g or not in the universe are left out.
universe (iterable, optional) – The nodes the random sets are drawn from, e.g. the genes measured in the experiment (default: all nodes of g). Only nodes of g count.
n_random (int) – Number of random node sets (default 500). The smallest possible p-value is 1 / (n_random + 1).
n_bins (int) – Number of degree bins (default 10).
seed (int or numpy.random.Generator, optional) – For reproducible random sets.
- Returns:
n_nodes(nodes tested),n_universe; foredgesandlcc: the observed value, the mean over the random sets (edges_random,lcc_random), the ratio (edges_fold,lcc_fold) and the empirical p-value, (number of random sets at least as high + 1) / (n_random + 1) (edges_p,lcc_p). With fewer than 2 nodes onlyn_nodesandn_universeare returned.- Return type:
Examples
>>> import networkx as nx >>> g = nx.complete_graph(5) >>> g.add_edges_from((i, i + 1) for i in range(5, 40)) >>> r = induced_connectivity(g, [0, 1, 2, 3, 4], n_random=99, seed=1) >>> r["edges"], r["lcc"] (10, 5)