skm_tools.dinar
Export networks as DiNAR node and edge tables.
DiNAR (Differential Network Analysis in R) shows
experimental data on a knowledge network, one cluster of nodes at a time. Its custom
networks are tab-separated node and edge tables with fixed column names (as DiNAR’s
Networks/PSS/Ath-based_*.txt); missing values are -.
DiNAR shows one cluster at a time (cluster 0 not at all), and can’t show clusters with more than 2000 edges.
Attributes
Functions
|
Node and edge tables of g in DiNAR's format. |
|
Write g as DiNAR node and edge tables (tab-separated), see |
Module Contents
- skm_tools.dinar.MAX_CLUSTER_EDGES = 2000
- skm_tools.dinar.DINAR_NODE_COLUMNS = ['geneID', 'shortDescription', 'shortName', 'MapManBin', 'clusterID', 'x', 'y',...
- skm_tools.dinar.DINAR_EDGE_COLUMNS = ['geneID1', 'geneID2', 'reactionType', 'clusterID_geneID1', 'clusterID_geneID2',...
- skm_tools.dinar.to_dinar(g, clusters=None, positions=None, seed=0)
Node and edge tables of g in DiNAR’s format.
- Parameters:
g (networkx.Graph) – PSS or CKN network (any networkx graph type), e.g. a PSS gene network.
clusters (str or dict, optional) – The clusters DiNAR shows one at a time: a node attribute (e.g.
"pathway"; for list attributes, the first value is used), or a{node: cluster}mapping (e.g. from community detection). Nodes without a cluster (None or NaN) are put together in one more cluster. Default: all nodes in one cluster (fine for small networks, e.g. PSS). Nodes without edges getclusterID0, which DiNAR doesn’t show.positions (str or dict, optional) – Node coordinates: a
{node: (x, y)}mapping (as returned by the networkx layout functions), or a node attribute holding them. Default: theposnode attribute (the networkx convention,nx.set_node_attributes(g, pos, "pos")) if every node has one; otherwise a spring layout of each cluster, with the clusters on a grid.seed (int, optional) – Random seed for the default layout (default 0, so the layout is the same each time, with the same networkx and numpy versions).
- Returns:
nodes (pandas.DataFrame) – One row per node:
geneID(the node id),shortDescription(description),shortName(display_label, or the node id),MapManBin(themapmanbins joined with" | "),clusterID(1, 2, …, largest cluster first; 0 for nodes without edges),x,y,clusterSimplifiedNodeDegree(number of neighbours in the same cluster) andexpressed(1).edges (pandas.DataFrame) –
geneID1,geneID2,reactionType, the clusters and cluster degrees of both nodes, andexists(1).reactionTypeisact_,inh_orunk_(from theinteraction: positive, negative or unknown influence; DiNAR draws edges by it), followed by the PSSreaction_type(e.g.act_protein activation), orinfluencefor networks without one (CKN). Parallel edges with the samereactionTypeare one row.Missing values are
-.
- Raises:
ValueError – If positions has no coordinates for some nodes, two node ids are the same as text (e.g.
1and"1"), or a cluster has more than 2000 edges (DiNAR can’t show it: use smaller clusters).
Examples
>>> import networkx as nx >>> g = nx.MultiDiGraph() >>> g.add_node("AT2G38470", display_label="WRKY33", mapman=["26.11.3.2.1_External stimuli"]) >>> g.add_node("camalexin") >>> _ = g.add_edge("AT2G38470", "camalexin", interaction="positive-influence") >>> nodes, edges = to_dinar(g) >>> nodes.loc[0, ["geneID", "shortName", "MapManBin"]].tolist() ['AT2G38470', 'WRKY33', '26.11.3.2.1_External stimuli']
- skm_tools.dinar.write_dinar(g, nodes_path, edges_path, clusters=None, positions=None, seed=0)
Write g as DiNAR node and edge tables (tab-separated), see
to_dinar().- Parameters:
g (networkx.Graph) – Network to write.
nodes_path (str or pathlib.Path) – Files to write (overwritten if they exist).
edges_path (str or pathlib.Path) – Files to write (overwritten if they exist).
clusters – As for
to_dinar().positions – As for
to_dinar().seed – As for
to_dinar().