[BioC] RCytoscape setPosition error

Paul Shannon pshannon at systemsbiology.org
Sun Feb 20 19:42:32 CET 2011


Hi Fahim,

I reworked your second (and failing) example so that it works.   I will paste the code in below, along with a tiny example data file, so you can see the kind of nodes and edges I was testing with.

Please keep this general scheme in mind.  RCytoscape expects to be used primarily like this:

  1) create the graph
  2) add all nodes and edges
  3) add all node and edge attributes
  4) cw = new.CytoscapeWindow ('your.window.title', graph=yourGraph)
  5) call 'displayGraph (cw)
  6) call 'layout (cw)' or
  7) do manual layout using setPosition
  8) apply visual mapping rules (e.g., setNodeColor, setEdgeLineStyleRule, setEdgeTargetArrowRule, etc)
  9) redraw (cw)

I see that RCytoscape does not always handle undirected graphs cleanly.  Nishant and I may need to talk a bit further, in order for me to understand recent changes he has made to his graph classes.  So this should get better soon.  In the meantime, I apologize, and recommend your stick with directed graphs.

Please let me know if this code works for you, and provides you the foundation to do the analyses you have in mind.

Cheers!

 - Paul

#------------------------------------------------------------------------------------------------------------------
# my version of your second example, with quite a few modifications
filename = 'nodePairs.csv'   # my guess at the kind of file you wish to read, with node pairs implying edges
intxn = read.csv (filename, header=TRUE);  # the edge list is represented as node pair

all.nodes = unique (c (intxn$from, intxn$to))
g <- new ('graphNEL', edgemode='directed')   # at present -- soon to be remedied -- RCy handles directed graphs best
g <- graph::addNode (all.nodes, g)
for (i in 1:nrow (intxn)) {
  from.node = intxn$from [i]
  to.node   = intxn$to [i]
  printf (sprintf ('adding edge between %s and %s', from.node, to.node))
  g <- graph::addEdge (from.node, to.node, g)
  }

   # create a CytoscapeConnection object for utility functions not restricted to a particular window
   # here we will check to see if a prior attempt at your window is still hanging around, as
   # will happen in debugging, and deleting it before creating a new one

cy <- CytoscapeConnection ()

window.title <- 'intxOutFromSkin'
if (window.title %in% as.character (getWindowList (cy)))
  destroyWindow (cy, window.title)

cw <- new.CytoscapeWindow (window.title, graph=g)
displayGraph (cw)
redraw (cw)

  # now perform manual layout, by explicit calls to setPosition
  # note that this particular layout obscures some of the edges

node.count = length (all.nodes)
x.start = -150
y.start = -50
x.incr = 60
y.incr = ceiling (120/node.count)

x.locations = seq (from=x.start, by=x.incr, length.out=node.count)
y.locations = seq (from=y.start, by=y.incr, length.out=node.count)
setPosition (cw, all.nodes, x.locations, y.locations)

# my sample data file, nodePairs.csv
from,to
A,B
A,C
D,E
F,A




On Feb 18, 2011, at 10:50 AM, Fahim M wrote:

> Hi Paul 
> Thanks a lot for ur help and sorry for being late since my system broke after upgrading my system.
> 
> I managed to execute my example program as desired by following your suggestion in the prev mail. However, my actual data it is still showing the error. 
> 
> #This is my example program which is working fine now 
> g <- new ('graphNEL', edgemode='directed') 
> nodesFr = c('A', 'B', 'C') 
> nodesTo =c('D', 'E', 'F') 
> nodesAll = union(nodesFr, nodesTo) 
> nElemFr = length(nodesFr) 
> nElemTo = length(nodesTo)
>  
> #add all the nodes to the graph
> g <- graph::addNode(nodesAll, g) 
> #create cytoscape window
> cw <- CytoscapeWindow ('smallExample', graph=g) 
> displayGraph (cw)       
> 
> #calculate the location of 'From' nodes   
> locx= rep(400, nElemFr) 
> yPos = 100 
> incr = ceiling(600/nElemFr) 
> locy = c() 
> for(j in 1: nElemFr) {locy = c(locy, (yPos+j*incr))} 
> setPosition(cw, nodesFr , locx, locy)
> 
> #calculate the location of 'To' nodes
> locx= rep(600, nElemTo) 
> yPos = 100 
> incr = ceiling(600/nElemTo) 
> locy = c() 
> for(j in 1: nElemTo) {locy = c(locy, (yPos+j*incr))} 
> setPosition(cw, nodesTo , locx, locy)
> 
> #add edge to the graph: Suppose the edges are: (A ->D , A -> E, B ->E, C->F, C->E)
> edgeList = rbind(c('A', 'D'),rbind(c('A','E'), rbind(c('B','E'), rbind(c('C','F'), c('C', 'E')))))
> for(j in 1: length(edgeList[,1]))
>     {
>     g = graph::addEdge(edgeList[j,1], edgeList[j,2], g)
>     }
> 
> cw at graph = g 
> layout (cw, 'jgraph-spring') 
> displayGraph(cw) 
> 
> #This works fine and show output as desired in cytoscape  
> #########################
> 
> #However, an  error is shown in the following code which is almost similar to the example code above.
> 
> > g <- new ('graphNEL', edgemode='undirected')
> > cw <- new.CytoscapeWindow ('intxOutFromSkin', graph=g)
> > displayGraph (cw) 
> entering RCytoscape::displayGraph
> RCytoscape::displayGraph, empty graph, returning
> NULL
> > intxn = read.csv(fileNames[i], header=TRUE);  # the edge list is represented as node pair 
> > numEdge = length(intxn[,1])
> > to = sort(unique(as.character(intxn[,'to']))) #find unique destination nodes 
> > g <- graph::addNode(to, g) #add nodes to the graph
> > nNodes = length(to)
> > locx = rep(i*150, nNodes)
> > yPos = 10
> > incr = ceiling(600/nNodes)
> > locy = c()
> > for(j in 1: nElem) {locy = c(locy, (yPos+j*incr))}
> 
> > setPosition(cw, to , locx, locy)
> Error in convertToR(xmlParse(node, asText = TRUE)) : 
>   faultCode: 1001 faultString: Node with id: 10108 could not be found.
> > 
> I am not sure why this error is coming as '10108' is already a node in the the graph (g)
> 
> > nodes(g)
>   [1] "10108"  "102056" "106563" "106873" "107425" "107886" "113095" "11369" 
>   [9] "118326" "118596" "119236" "119823" "119827" "124746" "125026" "125212"
>  [17] "130086" "130658" "131786" "131860" "136566" "136742" "137170" "137540"
>  [..............
> 
> 
> 
> #######
> SessionInfo()
> > sessionInfo()
> R version 2.12.1 (2010-12-16)
> Platform: x86_64-pc-linux-gnu (64-bit)
> 
> locale:
>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
>  [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8   
>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base     
> 
> other attached packages:
> [1] hash_2.0.1        RCytoscape_1.1.32 XMLRPC_0.2-4      RBGL_1.26.0      
> [5] graph_1.28.0     
> 
> loaded via a namespace (and not attached):
> [1] RCurl_1.5-0  tools_2.12.1 XML_3.2-0   
> > 
> 
> 
> Thanks a lot for your reply. 
> 
> --Fahim
> 
> 
>  
> On Mon, Feb 14, 2011 at 9:57 AM, Paul Shannon <pshannon at systemsbiology.org> wrote:
> Hi Fahim,
> 
> There is an easily resolved omission in the sample code you sent.
> 
> Please note the the 3rd line below, 'displayGraph', which does not appear in your email.  This method transmits your graph from R to Cytoscape, creating a Cytoscape network.
> 
>  cw <- CytoscapeWindow ('smallExample', graph=RCytoscape::makeSimpleGraph())
>  displayGraph (cw)      # this command sends your R graph to Cytoscape.  I believe you left this out...
>  layout (cw, 'jgraph-spring')
>  redraw (cw)
>  setPosition (cw, 'A', 50, 80)
> 
> If you want to place 'A' directly between 'B' and 'C', try this:
> 
>  pos.b <- getPosition (cw, 'B')[[1]]    # where is B?
>  pos.c <- getPosition (cw, 'C')[[1]]    # where is c?
>  new.x <- (pos.b$x + pos.c$x)/2         # calculate the x coordinate for A
>  new.y <- (pos.b$y + pos.c$y)/2         # and the y
>  setPosition (cw, 'A', new.x, new.y)    # place A mid-way between B and C
> 
> Please try these steps, ensure that they work for you, then we can then look at the next spot where trouble arises for you.
> 
> Also, please attach your sessionInfo.  It may be wise to update your code to the latest version of the package.
> 
> Cheers!
> 
> - Paul
> 
> On Feb 14, 2011, at 5:25 AM, Martin Morgan wrote:
> 
> > On 02/13/2011 11:28 AM, Fahim M wrote:
> >> Hi
> >> Can some one please point out where i am wrong.
> >>
> >> I am trying to position set of nodes column-wise in cytoscape using
> >> RCytoscape
> >> A----D
> >> B----E
> >> C----F
> >
> > Hi Fahim -- please ask questions about Bioconductor packages on the
> > Bioconductor mailing list
> >
> > http://bioconductor.org/help/mailing-list/
> >
> > and include packageMaintainer('RCytoscape') in the post.
> >
> > Martin
> >
> >>
> >> -------------------
> >>
> >> g <- new ('graphNEL', edgemode='undirected')
> >> cw <- CytoscapeWindow ('smallExample', graph=RCytoscape::makeSimpleGraph())
> >> layout (cw, 'jgraph-spring')
> >> redraw(cw)
> >>
> >> nodesFr = c('A', 'B', 'C')
> >> nodesTo =c('D', 'E', 'F')
> >> nodesAll = union(nodesFr, nodesTo)
> >>
> >> nElemFr = length(nodesFr)
> >> nElemTo = length(nodesTo)
> >>
> >> g <- graph::addNode(nodesAll, g)
> >>
> >> setPosition(cw, nodesFr , c(400, 400, 400), c(100, 200, 300))
> >> setPosition(cw, nodesTo , c(600, 600, 600), c(100, 200, 300))
> >> Error in convertToR(xmlParse(node, asText = TRUE)) :
> >>  faultCode: 0 faultString: Failed to invoke method setNodesPositions in
> >> class tudelft.CytoscapeRPC.CytoscapeRPCCallHandler: null
> >>
> >> setPosition(cw, nodesTo , c(600, 600, 600), c(100, 200, 300))
> >> Error in convertToR(xmlParse(node, asText = TRUE)) :
> >>  faultCode: 1001 faultString: Node with id: D could not be found.
> >>
> >> Thanks
> >> --Fahim
> >>
> >>      [[alternative HTML version deleted]]
> >>
> >> ______________________________________________
> >> R-help at r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >
> >
> > --
> > Computational Biology
> > Fred Hutchinson Cancer Research Center
> > 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109
> >
> > Location: M1-B861
> > Telephone: 206 667-2793
> 
> 
> 
> 
> -- 
> Fahim Mohammad 
> Bioinforformatics Lab
> University of Louisville
> Louisville, KY, USA
> Ph:  +1-502-409-1167



More information about the Bioconductor mailing list