skm_tools.ckn

CKN (Comprehensive Knowledge Network): load and filter.

Attributes

logger

CKN_RANKS

The CKN edge ranks, from 0 (curated, from PSS) to 4 (only predicted).

TF_REGULATION

The CKN edge type of a transcription factor regulating a gene.

Functions

ckn_to_networkx([edge_path, node_path, as_directed, ...])

Load CKN (v2.1) to a networkx directed graph, including node attributes.

rank_counts(g)

The number of edges of each CKN rank.

transcription_factors(g[, mapman_bins])

Transcription factors in CKN.

tf_target_enrichment(g, degs[, universe, min_targets])

Transcription factors whose CKN targets are over-represented among differentially expressed genes.

filter_ckn_edges(g[, keep_edge_ranks, ...])

Remove CKN edges, in place.

filter_ckn_nodes(g[, node_types, species, tissues, ...])

Remove CKN nodes, in place.

Module Contents

skm_tools.ckn.logger
skm_tools.ckn.CKN_RANKS = (0, 1, 2, 3, 4)

The CKN edge ranks, from 0 (curated, from PSS) to 4 (only predicted).

skm_tools.ckn.ckn_to_networkx(edge_path=None, node_path=None, as_directed=True, create_using=nx.DiGraph, data_dir='.')

Load CKN (v2.1) to a networkx directed graph, including node attributes.

Downloads the CKN files from skm.nib.si if they don’t exist yet.

Parameters:
  • edge_path (str or pathlib.Path, optional) – Path to the edge file (default <data_dir>/AtCKN-v2.1-2026.10.tsv.gz); if the file does not exist, it is downloaded from skm.nib.si, gzipped if the name ends in .gz.

  • node_path (str or pathlib.Path, optional) – Path to the node file (default <data_dir>/AtCKN-v2.1-2026.10_node-annot.tsv.gz); downloaded as for edge_path.

  • as_directed (bool) – Add undirected edges (directed False, e.g. binding) in both directions, so directed path searches can use them either way (default True): A -> B (undirected) becomes A -> B and B -> A. If False, every edge is added once, as listed in the file. To leave out the undirected edges, use filter_ckn_edges(g, filter_function=lambda d: d["directed"]).

  • create_using (networkx graph class) – Graph class to create (default networkx.DiGraph; networkx.MultiDiGraph keeps parallel edges). CKN can have two edges between the same nodes, of different types (e.g. ABI4 binds RGL2, and activates its transcription): a DiGraph keeps the last one of each direction, a MultiDiGraph all of them.

  • data_dir (str or pathlib.Path) – Folder for the default file names (default: the current folder).

Returns:

CKN (or the create_using type): node attributes node_type (the PSS class, e.g. PlantCoding, Metabolite), locus_type (genes and RNAs: the TAIR locus type, e.g. protein_coding, mirna), species, TAIR, display_label, short_name, synonyms, description, mapman, note and tissue; edge attributes interaction (positive-influence, negative-influence or unknown-influence), directed, rank, effect, type, species, isTFregulation and interactionSources. synonyms, mapman, tissue and interactionSources are lists; empty values are None. Nodes of the node file without edges are left out.

Return type:

networkx.DiGraph

skm_tools.ckn.rank_counts(g)

The number of edges of each CKN rank.

Parameters:

g (networkx.Graph) – CKN, e.g. from ckn_to_networkx().

Returns:

Rank -> number of edges, for every rank in CKN_RANKS (and any other rank in g). Edges without a rank are not counted.

Return type:

dict

skm_tools.ckn.TF_REGULATION = 'transcription factor regulation'

The CKN edge type of a transcription factor regulating a gene.

skm_tools.ckn.transcription_factors(g, mapman_bins=None)

Transcription factors in CKN.

The sources of the network’s transcription factor regulation edges (type "transcription factor regulation"), and optionally the nodes annotated with MapMan bins, e.g. "14.5" (RNA biosynthesis.DNA-binding transcriptional regulation in MapMan4), for TFs without regulation edges in CKN. Only the edges in g count: filter the edges first (filter_ckn_edges()) to restrict to some ranks. Load CKN as a MultiDiGraph (ckn_to_networkx(create_using=nx.MultiDiGraph)): a DiGraph keeps one edge per node pair and direction, so a binding edge can hide a regulation edge between the same genes.

Parameters:
Return type:

set

skm_tools.ckn.tf_target_enrichment(g, degs, universe=None, min_targets=5)

Transcription factors whose CKN targets are over-represented among differentially expressed genes.

For each TF (source of transcription factor regulation edges in g), a one-sided hypergeometric test of its targets among the DEGs. The background is the universe genes with at least one incoming transcription factor regulation edge in g: genes no TF is known to regulate can’t be hits, and would make every TF look enriched. Only the edges in g count: filter the ranks first (filter_ckn_edges()) if needed. Load CKN as a MultiDiGraph (ckn_to_networkx(create_using=nx.MultiDiGraph)): a DiGraph keeps one edge per node pair and direction, so a binding edge can hide a regulation edge between the same genes.

The activity score is computed over the TF’s DE targets with a signed edge (interaction positive-influence / negative-influence; all edges from the TF to the target must agree) and a direction: the mean of sign(edge) x direction(target), +1 if all are consistent with a more active TF, -1 with a less active one.

Parameters:
  • g (networkx.Graph) – CKN, e.g. from ckn_to_networkx() (DiGraph or MultiDiGraph).

  • degs (dict or iterable) – The DEGs: node -> direction (+1 up, -1 down, 0 unknown or mixed), or just the nodes (no direction).

  • universe (iterable, optional) – The genes that could be DE, e.g. those measured. Default: every node of g.

  • min_targets (int) – Test only TFs with at least this many targets in the background (default 5).

Returns:

One row per tested TF, sorted by p: tf, targets (in the background), hits (DE targets), up_hits, down_hits, expected, fold, p, padj (Benjamini-Hochberg over the TFs), n_signed, activity_score (NaN without signed hits), hit_genes (list). The background size and the number of DEGs in it are in attrs["background"] and attrs["n_degs"].

Return type:

pandas.DataFrame

skm_tools.ckn.filter_ckn_edges(g, keep_edge_ranks=None, keep_edge_types=None, filter_function=None, remove_isolates=True)

Remove CKN edges, in place.

The filters are combined: an edge is kept only if it passes all of them.

Parameters:
  • g (networkx.Graph) – CKN, e.g. from ckn_to_networkx(). Changed in place.

  • keep_edge_ranks (int or iterable of int, optional) – Keep only edges of these ranks (0: best supported, to 4). Edges without a rank attribute are kept.

  • keep_edge_types (str or iterable of str, optional) – Keep only edges of these type values (e.g. "binding").

  • filter_function (callable, optional) – Called with each edge’s attribute dict; return True to keep the edge.

  • remove_isolates (bool) – Also remove nodes without edges afterwards (default True); this includes nodes that had no edges before.

Returns:

  • removed_edges (list) – The removed edges, (u, v) or, for a multigraph, (u, v, key).

  • removed_nodes (dict) – Removed node -> "isolate".

skm_tools.ckn.filter_ckn_nodes(g, node_types=None, species=None, tissues=None, remove_isolates=True)

Remove CKN nodes, in place.

Complexes with a removed component are removed too: if a component is removed, the complex can’t exist.

Parameters:
  • g (networkx.Graph) – CKN, e.g. from ckn_to_networkx(). Changed in place.

  • node_types (str or iterable of str, optional) – Keep only nodes of these node_type values (the PSS classes, e.g. "PlantCoding", "Metabolite").

  • species (str or iterable of str, optional) – Keep only nodes of these species (e.g. "ath"); nodes without a species (e.g. metabolites) are kept. Complexes of an Arabidopsis protein and a pathogen (species "ath/foreign", e.g. RISC - vsiRNA) are removed with species="ath", as their foreign component is.

  • tissues (str or iterable of str, optional) – Keep only nodes annotated with at least one of these tissues.

  • remove_isolates (bool) – Also remove nodes without edges afterwards (default True); this includes nodes that had no edges before.

Returns:

Removed node -> reason ("wrong species", "wrong node type", "wrong tissue type", "complex component removed" or "isolate").

Return type:

dict