skm_tools.connectivity ====================== .. py:module:: skm_tools.connectivity .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: skm_tools.connectivity.logger Functions --------- .. autoapisummary:: skm_tools.connectivity.induced_connectivity Module Contents --------------- .. py:data:: logger .. py:function:: 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. :param g: The network, e.g. CKN filtered to the edge ranks of interest. :type g: networkx.Graph :param nodes: The nodes to test, e.g. the DEGs. Nodes that are not in `g` or not in the universe are left out. :type nodes: iterable :param universe: 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. :type universe: iterable, optional :param n_random: Number of random node sets (default 500). The smallest possible p-value is 1 / (n_random + 1). :type n_random: int :param n_bins: Number of degree bins (default 10). :type n_bins: int :param seed: For reproducible random sets. :type seed: int or numpy.random.Generator, optional :returns: ``n_nodes`` (nodes tested), ``n_universe``; for ``edges`` and ``lcc``: 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 only ``n_nodes`` and ``n_universe`` are returned. :rtype: dict .. rubric:: 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)