Question: WGCNA network visualisation in RCyjs
1
gravatar for christopher.clarskon15
3.4 years ago by
christopher.clarskon1520 wrote:

I have used the Pearson correlation method to infer a network of interacting genes from microarray data. And ultimately, I would like to study this network with 'WGCNA'. However as useful as some of the commands in WGCNA seem, I can't find anywhere in the tutorials a command that actually allows me to visualise the networks.... So I instead used the package 'network' to plot and visualise this network.....

Subsequently I'd like to use 'RCyjs' to visualise the networks via javascript and ultimately create a website. Does anyone know if it is possible to jointly use shiny and RCyjs to make a pipeline that can accept microarray data and via these packages, produce a network?? Or should I try to use Django (if that's possible)?

p1<-cor(t(E.rna[1:20,1:20]),use="p") #pearson correlation

plot(as.network.matrix(p1)) #network package

RCyjs(portRange=9047:9057, quiet=TRUE, graph=as.network.matrix(p1)); #RCyjs

Error in validObject(.Object) : 
  invalid class “RCyjsClass” object: invalid object for slot "graph" in class "RCyjsClass": got class "network", should be or extend class "graph"

RCyjs does not seem to accept networks and instead only takes 'graphs'.... how can I rectify this? If possible could anyone recommend alternate packages?

ADD COMMENTlink modified 3.4 years ago by Paul Shannon370 • written 3.4 years ago by christopher.clarskon1520
Answer: WGCNA network visualisation in RCyjs
2
gravatar for Paul Shannon
3.4 years ago by
Paul Shannon370
Paul Shannon370 wrote:

Christopher,

Sorry for my delay.   Here is a complete example modeled after yours.  Not having access to your E.rna matrix, I generated a small random network

library(RCyjs)
set.seed(3)
size <- 5
m <- matrix(runif(size * size), nrow=size, dimnames=list(LETTERS[1:size], LETTERS[1:size]))
m.cor <- cor(m)
diag(m.cor) <- 0

# create an adjacency matrix from the correlation, with edges between
# every pair of nodes with absolute correlation > threshold
threshold <- 0.45
m.adjacency.logical <- abs(m.cor) > threshold
m.adjacency <- 1 * m.adjacency.logical
g.am <- graphAM(m.adjacency)
g <- asg.am, "graphNEL")
nodeDataDefaults(g, attr="label") <- "not yet assigned"
nodeData(g, nodes(g), attr="label") <- nodes(g)
edgeDataDefaults(g, attr="cor") <- 0

# extract the corrleations to use as edge weights
m.corFiltered <- m.cor * m.adjacency
for(source.node in colnames(m.corFiltered)){
   correlations <- as.list(m.corFiltered[, source.node])
   correlations <- correlations[correlations != 0]
   if(length(correlations) > 0)
      edgeData(g, source.node, names(correlations), attr = "cor") <- as.numeric(correlations)
   }

rcy <- RCyjs(7000:7010, graph=g)
layout(rcy, "cose")
httpSetStyle(rcy, "style.js") # see below

 

Visual mapping rules are available as function calls in RCyjs, but I have found that using cytoscape.js native approach - loading json style files - to be easier overall.  Here is the verbatim text of the "style.js" referred to above:

vizmap = [

   {selector: "node", css: {
      "text-valign":"center",
      "text-halign":"center",
      "content":"data(label)",
      "background-color": "white",
      "border-color":"black","border-width":"1px",
      "shape": "ellipse",
      "width": 40,
      "height": 40,
      "font-size":"12px"}},

   {selector: 'edge', css:{
      "width": "2px",
      "curve-style": "bezier"
      }},

   {selector: 'edge[cor < 0]', css: {
      "line-color": "mapData(cor, -1.0, 0.0, rgb(220,255, 220), rgb(0, 255, 0))",
      "source-arrow-shape": "none",
      "target-arrow-shape": "triangle",
      "target-arrow-color": "rgb(0, 192, 0)",
      }},

   {selector: 'edge[cor > 0]', css: {
      "line-color": "mapData(cor, 0.0, 1.0, rgb(255,200,200), rgb(255, 0, 0))",
      "source-arrow-shape": "none",
      "target-arrow-shape": "triangle",
      "target-arrow-color": "rgb(192, 0, 0)",
      }}
      ];
ADD COMMENTlink modified 3.4 years ago • written 3.4 years ago by Paul Shannon370
Answer: WGCNA network visualisation in RCyjs
0
gravatar for Paul Shannon
3.4 years ago by
Paul Shannon370
Paul Shannon370 wrote:

Hi Christopher,

As you say, RCyjs (and RCy3) expect graphNEL objects, which are defined in the Bioconductor graph package.

It is quite easy  to convert among the various common graph/network representations.  If you will provide a small reproducible example (a few lines of code ought to be enough) I will respond with a few more lines of code which transform your network object into a graphNEL.

 Paul

ADD COMMENTlink written 3.4 years ago by Paul Shannon370

Hi Paul,

Thanks for the reply

all i'm doing is running a pearsson correlation on a 20x20 matrix as follows:

p1<-cor(t(E.rna[1:20,1:20]),use="p")

Then with the 'network' package and 'graph' package as per your recommendation i tried the following:

graphNEL(as.network.matrix(p1))

But i get the following error:

Error in checkValidNodeName(nodes) : 
  node names must be character, got: ‘network’

Is this the example you were hoping for... this is the only way that I know how to make a network as of yet

 

ADD REPLYlink written 3.4 years ago by christopher.clarskon1520

Further Development: I have used the following code to make an RCyjs graph:

rcy <- RCyjs(portRange=9047:9057, quiet=TRUE, graph=igraph.to.graphNEL(graph_from_adjacency_matrix(p1, weighted=T)))

I am yet to check if the graph is congruent with the one that I originally plotted in Rstudio with the package 'Network' (a few recommendations of commands would be much appreciated here). However in the RCyjs graph I can not seem to eliminate the self-interacting nodes.... this seemed to be a default in the network package so I suppose there is an argument in the 'graph_from_adjacency_matrix' command that prevents that from happening??

ADD REPLYlink written 3.4 years ago by christopher.clarskon1520
1
In my code you will see

  diag(m.cor) <- 0

This removes the self edges implied by the correlation matrix.  Make that change before you create the graph.

ADD REPLYlink written 3.4 years ago by Paul Shannon370
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 462 users visited in the last hour