johnny utah
johnny utah

Reputation: 279

RCyjs specifying node labels from adjacency matrix columns

I plan to make an interactive app whereby users will upload data to a website and my app will return a Cytoscape (RCyjs) graph from this data. I will specify to the users that the nodes in the graph will be labelled according to the columns of the data being read....

For example I want my app to be implemented through RCyjs so when a user uploads a text file containing data I can make an adjacency matrix and use something like the following code:

> data<-read.table("text_file_containing_data.txt", sep="\t")
> p1<-cor(data[1:20,1:20], use="p") #correlations taken from sample of
> library(graph) 
> library(RCyjs) 
> library(igraph)
> rcy<-RCyjs(portRange=9047:9057, quiet=TRUE, graph=igraph.to.graphNEL(simplify(graph_from_adjacency_matrix(p1, weighted=T))))

So what I am wondering is how can I get the output to look like this:

enter image description here

Is there an command in the RCyjs command that allows the node names to be specified by a parameter in the dataset e.g. the column names? In the RCyjs manual it seems to say that arguments such as node.attribute.name and nodes can be specified in the RCyjs command e.g.

    for (i in colnames(p1)){
        nodeDataDefaults(g, "label") <- colnames(p1)[i]
        }
    setNodeLabelRule(rcy, "label")
    redraw(rcy)

however this makes no difference to the graph

When I check the output of the above commands, I get:

    noa(g, "label")
    6450255 2570615 6370619 2600039 2650615 5340672 2000519 3870044 7050209 1580181 5220554 5390438 
    NA      NA      NA      NA      NA      NA      NA      NA      NA      NA      NA      NA 
    6420681 4760377 2370438 4050154 1740066 4830092 3610072 6480136 
    NA      NA      NA      NA      NA      NA      NA      NA 

So maybe I missed something in the commands above where I should have labelled them initially in the graph package but I can not seem to get that to work.....

I have also tried the following:

  nodes<-getNodes(rcy)
  setNodeLabelRule(rcy, for(i in nodes[,1]){
       i
        }
   )

but the graph does not label as I would like it to...

enter image description here

Wondering why this is....

Upvotes: 0

Views: 122

Answers (1)

paul shannon
paul shannon

Reputation: 375

In the vignette that accompanies the RCyjs package, you can find these lines (look for Example 3, Hypoxia Induction):

RCyjs package vignette

Assign node data attributes to a graphNEL explicitly after first setting a default:

nodeDataDefaults(g, attr="label") <- "default node label"
nodeData (g, all.nodes, "label") = all.nodes

You skipped the second step, as best I can tell. The full sequence might look like this:

all.nodes <- colnames(p1)
g <- new("graphNEL", edgemode = "directed")
g <- addNode(all.nodes, g)
nodeDataDefaults(g, attr="label") <- ""  # initialize
  # vector assignment of labels 
nodeData(g, all.nodes, attr="label") <- all.nodes
  • Paul

Upvotes: 1

Related Questions