time

6 views
Skip to first unread message

Grimes Mark

unread,
May 7, 2012, 7:03:02 PM5/7/12
to rcyto...@googlegroups.com, Paul Shannon
Paul

The Cytoscape.Window or new.Cytoscape.Window command takes a VERY long time to execute when the number of Nodes is 2482 and number of attributes is 234.  The makeSimpleGraph command just took a few seconds in Cytoscape v 2.8.3.   At first I thought it was hung, but the cpu is occupied by R.  

By the way I wrote functions to load attributes into a graph and edges into a cytoscape window that are reproduced below.  In case anyone may find them useful.

Mark

#  Function to plot the primary cytoscape file
# syntax: > mywindowname <- plot.cy(cytoscape.file)
#
plot.cy <-function (cytoscape.file) {
mydata <- new("graphNEL", edgemode='undirected', nodes=as.character(cytoscape.file[, 1]))
# Set up and load all the node attributes
for (i in 2:ncol(cytoscape.file)) {
mydata <- initNodeAttribute (graph=mydata,  attribute.name=names(cytoscape.file[i]), attribute.type='numeric', default.value=0.0)
nodeData (mydata, n=as.character(cytoscape.file[, 1]), attr=names(cytoscape.file[i])) <- as.numeric(cytoscape.file[,i])
}
# load standard edge attributes
mydata <- initEdgeAttribute (graph= mydata, attribute.name='edgeType', attribute.type='char', default.value='undefined')
  mydata <- initEdgeAttribute(mydata, attribute.name = "Weight", attribute.type = "numeric", default.value = 0.0)
return(mydata) }
#
#  Function to load a single edge:
load.an.edge <- function (Cy_Wind, Network.File) {
filename=NULL
a = as.character(Network.File$Gene.1)
b = as.character(Network.File $Gene.2)
nodenames <- unique(c(a,b))
edgeTypes <- levels(as.factor(Network.File$edgeType))
subgraph2 <- new("graphNEL", nodes= nodenames, edgemode='undirected')
subgraph2 <- initEdgeAttribute (graph= subgraph2, attribute.name='edgeType', attribute.type='char', default.value='undefined')
  subgraph2 <- initEdgeAttribute(subgraph2, attribute.name = "Weight", attribute.type = "numeric", default.value = 0.0)
subgraph2 = addEdge (as.vector(Network.File$Gene.1, mode="character"), as.vector(Network.File$Gene.2, mode="character"), subgraph2) 
edgeData (subgraph2, as.vector(Network.File$Gene.1, mode="character"), as.vector(Network.File$Gene.2, mode="character"), attr='edgeType') <- as.character(Network.File$edgeType)
edgeData (subgraph2, as.vector(Network.File$Gene.1, mode="character"), as.vector(Network.File$Gene.2, mode="character"), attr='Weight') <- Network.File$Weight
addGraphToGraph (Cy_Wind, subgraph2)
redraw(Cy_Wind) 
showGraphicsDetails(Cy_Wind, TRUE)
}
###
#
# Function to load multiple edges:
loadedges <- function (Cy_Wind, Network.File) {
filename=NULL
a = as.character(Network.File$Gene.1)
b = as.character(Network.File $Gene.2)
nodenames <- unique(c(a,b))
edgeTypes <- levels(as.factor(Network.File$edgeType))
sepedges <- dlply(Network.File, .(edgeType)) 
subgraph2 <- new("graphNEL", nodes= nodenames, edgemode='undirected')
subgraph2 <- initEdgeAttribute (graph= subgraph2, attribute.name='edgeType', attribute.type='char', default.value='undefined')
  subgraph2 <- initEdgeAttribute(subgraph2, attribute.name = "Weight", attribute.type = "numeric", default.value = 0.0)
#
for(i in 1:length(sepedges)) {
filename[i] <- paste(edgeTypes[i], noquote("edges"), sep=" ", collapse=NULL)
edgefile <- data.frame(sepedges[i])
names(edgefile) <- names(Network.File)
subgraph2 = addEdge (as.vector(edgefile$Gene.1, mode="character"), as.vector(edgefile$Gene.2, mode="character"), subgraph2) 
edgeData (subgraph2, as.vector(edgefile$Gene.1, mode="character"), as.vector(edgefile$Gene.2, mode="character"), attr='edgeType') <- as.character(edgefile$edgeType)
edgeData (subgraph2, as.vector(edgefile$Gene.1, mode="character"), as.vector(edgefile$Gene.2, mode="character"), attr='Weight') <-edgefile$Weight
addGraphToGraph (Cy_Wind, subgraph2)
redraw(Cy_Wind) 
cat("\n", filename[i], "\n"
}
cat("\n", filename) 
showGraphicsDetails(Cy_Wind, TRUE)
}
#


Grimes Mark

unread,
May 7, 2012, 7:18:42 PM5/7/12
to rcyto...@googlegroups.com, Paul Shannon
PS  Syntax for plot.cy should read 

syntax: > mygraph <- plot.cy(cytoscape.file)

because plot.cy returns a graph, not a window!

Paul Shannon

unread,
May 7, 2012, 7:57:43 PM5/7/12
to rcyto...@googlegroups.com, Paul Shannon
Hi Mark,

Could you send me the graph as an RData object?
There are some 'pathological' cases I am coming to recognize.

Of course, they should not be pathological. They are only that way because of my sometimes dumb way of doing things.

Send me the graph, I'll send you a fix. (I promise boldly!)

- Paul

Grimes Mark

unread,
May 8, 2012, 11:49:00 AM5/8/12
to rcyto...@googlegroups.com
Paul

The graph is displayed when fewer attributes are included.

But. A new problem: 
\
setPosition(lung.window, as.character(cyf$Gene.Name), sed.ord2)
Error: could not find function "setPosition"
RCytoscape::setPosition(lung.window, as.character(cyf$Gene.Name), sed.ord2)
Error: 'setPosition' is not an exported object from 'namespace:Rycytoscape'
/
Something broke - this used to work.  
SessionInfo:
Cytoscape 2.8.3; RCytoscape_1.6.3

Thanks for your help,

Mark

Paul Shannon

unread,
May 8, 2012, 3:45:27 PM5/8/12
to rcyto...@googlegroups.com, Paul Shannon
It is now setNodePosition. There were too many name collisions with 'setPosition'

See http://db.systemsbiology.net:8080/cytoscape/RCytoscape/versions/current/news.html for other small changes.

Sorry for the trouble. I should have done a better job of getting the word out.

- Paul

Paul Shannon

unread,
May 8, 2012, 4:16:05 PM5/8/12
to Grimes Mark, rcyto...@googlegroups.com, Paul Shannon, Paul Shannon
Hi Mark,

It's a long story but the upshot is: avoid undirected graphs in RCytoscape if you possibly can.

Make this one change:

edgemode (lung.graph) = 'directed'

and you will find that

cw = new.CytoscapeWindow ('lung', lung.graph)
displayGraph (cw)

runs pretty fast. You have 234 * 2482 node attributes, so that takes a while to transmit from R to Cytoscape, so that takes a while, but less than 15 minutes on my MacBook. The 2482 nodes (no edges) in your graph appear in a minute or so.

I hope this helps. Sorry for the trouble.

What is your advice? How should I handle this? In time, we will fix the Bioconductor graphNEL class so that undirected graphs behave as they should. In the meantime, should I display a strong warning?

- Paul


On May 8, 2012, at 8:01 AM, Grimes Mark wrote:

> Paul
>
> I let it go overnight and it still wasn't happening. I'll try loading fewer attributes as a workaround. Meanwhile, attached is the graph object, "lung.graph" made with the plot.cy function.
>
> Thanks,
>
> Mark
>
> <LC_graph.RData>
> On May 7, 2012, at 5:57 PM, Paul Shannon wrote:
>

Grimes Mark

unread,
May 8, 2012, 4:52:44 PM5/8/12
to rcyto...@googlegroups.com
Thanks Paul

I consulted the Functions list on the RCy website - it's still listed as setPosition there.   

But now it didn't work with my list of gene names, which is how I sent the graph to Cy.  Maybe because the node name in Cy is now (conveniently) 'ValidatedObjectAndEditString: validatedObject=TNK2, editString=NULL' when copied and pasted?   "ERROR! unknown nodes in RCytoscape::setNodePosition"

I will change the edgemode to directed in my plot.cy function.  THanks for the tip (which I wouldn't have figured out!).  It might be a good idea to say that in the help file for that command and on the Functions website page, yes.  

THanks,

mark



On May 8, 2012, at 1:45 PM, Paul Shannon wrote:

It is now setNodePosition.   There were too many name collisions with 'setPosition'

See http://db.systemsbiology.net:8080/cytoscape/RCytoscape/versions/current/news.html  for other small changes.

Sorry for the trouble.  I should have done a better job of getting the word out.

 - Paul

Hi Mark,

It's a long story but the upshot is:  avoid undirected graphs in RCytoscape if you possibly can.

Make this one change:

edgemode (lung.graph) = 'directed'

and you will find that 

  cw = new.CytoscapeWindow ('lung', lung.graph) 
  displayGraph (cw)

runs pretty fast.   You have 234 * 2482 node attributes, so that takes a while to transmit from R to Cytoscape, so that takes a while, but less than 15 minutes on my MacBook.  The 2482 nodes (no edges) in your graph appear in a minute or so.

I hope this helps.  Sorry for the trouble.

What is your advice?  How should I handle this?  In time, we will fix the Bioconductor graphNEL class so that undirected graphs behave as they should.  In the meantime, should I display a strong warning?

- Paul

Grimes Mark

unread,
May 8, 2012, 5:05:27 PM5/8/12
to rcyto...@googlegroups.com, Paul Shannon
PS an update on the error
But now it didn't work with my list of gene names, which is how I sent the graph to Cy.  Maybe because the node name in Cy is now (conveniently) 'ValidatedObjectAndEditString: validatedObject=TNK2, editString=NULL' when copied and pasted?   "ERROR! unknown nodes in RCytoscape::setNodePosition"

This error only occurred on a second window that I created using createWindowFromSelection().  Function setNodePosition() worked fine on the original window created with RCy.  Not sure why, perhaps because I set return.graph=FALSE?

By the way, is there a way to modify attributes from createWindowFromSelection()?  If you set return.graph =  TRUE?  I don't know how to access the graph object within the returned window object. 

Mark


On May 8, 2012, at 1:45 PM, Paul Shannon wrote:

Paul Shannon

unread,
May 8, 2012, 11:23:59 PM5/8/12
to rcyto...@googlegroups.com, Paul Shannon
Hi Mark,

Thanks for these reports, and these questions. I updated the rcy website so that setNodePosition is now documented. I have since learned that, rather than simply removing a method, I should 'deprecate' for a release cycle, and only then remove it. Sorry you got stung.

In the website's man page for createNewWindowFromSelection

http://db.systemsbiology.net:8080/cytoscape/RCytoscape/versions/current/methods/createWindowFromSelection.html

under 'Value' -- meaning "the value which the method returns" is this line:

A new CytoscapeWindow object, with the graph slot populated with the new
selected subgraph, if requested. If not requested, the graph slot holds an empty graph.

Does that make more sense?

- Paul

Mark Grimes

unread,
May 9, 2012, 8:24:37 AM5/9/12
to rcyto...@googlegroups.com
Paul

Thanks very much for fixing those things.

I am still not understanding something though. Is it possible to access the graph in the slot in the window object? The goal is to send a new attribute to the subgraph that wasn't in the original (to plot with node size for example).

Mark

Paul Shannon

unread,
May 9, 2012, 9:06:29 AM5/9/12
to rcyto...@googlegroups.com, Grimes Mark, Paul Shannon
Hi Mark,

Yes, you can do that straightforwardly. I can send you a working-code example later today, but here's some pseudo-code

cw = demoSimpleGraph ()

selectNodes (cw, c ('A', 'B'))

cw2 = createWindowFromSelection (cw, 'demo2', return.graph=TRUE)
g2 = getGraph (cw2)

setNodeAttributeDirect (cw2,

stopifnot ('count' %in% noa.names (g2)
result = setNodeAttributesDirect (cw2, 'count', 'int', c ('A', 'B'), c (4, 8))

If, on the other hand, you want to add an entirely new node attribute to g2, you will have a few extra steps.

Let me know…

- Paul

Grimes Mark

unread,
May 9, 2012, 10:05:17 AM5/9/12
to Paul Shannon, rcyto...@googlegroups.com
Paul

Of course, getGraph! I should have perused the functions more
carefully.

Sounds like it may be easier to load the attribute beforehand and draw
the network de novo, which is not difficult, rather than adding an
attribute to an existing network in Cy. In this way setNodeColorRule
and other such functions can be used (since these base the rule on an
attribute).

Thanks for your help,

Mark


On May 9, 2012, at 7:06 AM, Paul Shannon wrote:

> Hi Mark,
>
Reply all
Reply to author
Forward
0 new messages