edge addtion to graph

7 views
Skip to first unread message

Grimes Mark

unread,
May 23, 2013, 1:10:02 PM5/23/13
to rcyto...@googlegroups.com

Paul

This command

addCyEdgeR Documentation

addCyEdge

Description

Given a CytoscapeWindow containing a (possibly empty) graph, this method adds a edge. Edge attributes are added separately, via successive calls to sendEdgeAttributesDirect. The two nodes must already exist in the Cytoscape network.


Usage

addCyEdge(obj, sourceNode, targetNode, edgeType, directed)
appears to be limited in its ability to add edge attributes.  The command 'sendEdgeAttributesDirect' is inaccessible.  The command 'sendEdges' doesn't help because it doesn't allow any new edges to be sent.  

Here is what I am trying to do.  To simplify my typing, I created a function:

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)
}

This function works fine if there are more than two nodes, but if there are only two nodes and one edge, the error results as follows.  The offending step is 'addGraphToGraph':

addGraphToGraph (Cy_Wind, subgraph2)
[1] sending eda edgeType
[1] other.graph: 1
[1] obj@graph: 0
entering setEdgeAttributesDirect, edgeType, with 2 names and 2 values
[1] sending eda Weight
[1] other.graph: 1
[1] obj@graph: 0
entering setEdgeAttributesDirect, Weight, with 2 names and 2 values
Error: faultCode0  faultStringFailed to parse XML-RPC request: Failed to parse double value: NA
Timing stopped at: 0.03 0.001 0.072 


For this reason I tried the 'addCyEdge' command, but can't figure out how to get another attribute into the graph's edge.  The graph is simply two nodes and the edge "Network.File" is shown below.
 Network.File:


         Weight    Gene.1 Gene.2             edgeType

  0.94  GENE1    GENE2 positive correlation





Thanks Paul.  I hope I have given you enough information to understand what the problem is here.  There is probably a better way to do this.

Mark


> sessionInfo()
R version 3.0.0 (2013-04-03)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
 [1] parallel  grid      splines   stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] rgl_0.93.932         plyr_1.8             GOstats_2.26.0       Category_2.26.0      GO.db_2.9.0          org.Hs.eg.db_2.9.0  
 [7] RSQLite_0.11.3       DBI_0.2-5            AnnotationDbi_1.22.2 Biobase_2.20.0       BiocGenerics_0.6.0   RCytoscape_1.10.0   
[13] XMLRPC_0.3-0         graph_1.38.0         gplots_2.11.0        KernSmooth_2.23-10   caTools_1.14         gdata_2.12.0        
[19] gtools_2.7.1         tsne_0.1-2           vegan_2.0-7          permute_0.7-0        RUnit_0.4.26         bio3d_1.1-5         
[25] adegenet_1.3-7       ape_3.0-8            igraph_0.6.5-1       ade4_1.5-2           MASS_7.3-26          cluster_1.14.4      
[31] Hmisc_3.10-1         survival_2.37-4      stringr_0.6.2        fdrtool_1.2.10       qgraph_1.2.1        

loaded via a namespace (and not attached):
 [1] annotate_1.38.0       AnnotationForge_1.2.0 bitops_1.0-5          ellipse_0.3-8         genefilter_1.42.0    
 [6] GSEABase_1.22.0       IRanges_1.18.0        jpeg_0.1-2            lattice_0.20-15       lavaan_0.5-12        
[11] nlme_3.1-109          png_0.1-4             psych_1.3.2           RBGL_1.36.0           RCurl_1.95-4.1       
[16] sem_3.1-3             stats4_3.0.0          tools_3.0.0           XML_3.95-0.2          xtable_1.7-1         



Paul Shannon

unread,
May 23, 2013, 4:58:48 PM5/23/13
to rcyto...@googlegroups.com, Grimes Mark, Paul Shannon
Hi Mark,

I'm stacked up with deadlines. Can this wait till the weekend?

- Paul
> --
> You received this message because you are subscribed to the Google Groups "RCytoscape" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rcytoscape+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Robert M. Flight

unread,
Jun 6, 2013, 9:27:39 AM6/6/13
to rcyto...@googlegroups.com, Grimes Mark, Paul Shannon
Mark,

What happens if instead of trying to add the graph to an existing, you create *all* of the nodes and edges, add *all* of the attributes, and then pass the resulting network to Cytoscape using the "CytoscapeWindow" command?

This might be an alternate way to create the network instead of using "addGraph2Graph".

-Robert

Mark Grimes

unread,
Jun 6, 2013, 6:06:10 PM6/6/13
to rcyto...@googlegroups.com, Paul Shannon
Robert

This certainly works.  I created a function to do this, pasted below, for cytoscape files in which 
> names(cytoscape.file)
 [1] "Gene.Name"       …
and
> names(edge.file)
[1] "Weight"   "Gene.1"   "Gene.2"   "edgeType"

But it is still no clear why addGraphToGraph works sometimes and fails at other times.

Best,

Mark

Function to minimize typing: 

plot.cy.2 <- function (cytoscape.file, edge.file) {
mydata <- new("graphNEL", edgemode='directed', nodes=as.character(cytoscape.file[, 1]))
# Set up and load all the node attributes
for (i in 2:ncol(cytoscape.file)) {
if (class(cytoscape.file[1,i]) != "numeric") {
mydata <- initNodeAttribute (graph=mydataattribute.name=names(cytoscape.file[i]), attribute.type='char', default.value=0.0)
nodeData (mydata, n=as.character(cytoscape.file[, 1]), attr=names(cytoscape.file[i])) <- as.character(cytoscape.file[,i]) }
if (class(cytoscape.file[1,i])=="numeric") {
mydata <- initNodeAttribute (graph=mydataattribute.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)
  mydata = addEdge (as.vector(edge.file$Gene.1, mode="character"), as.vector(edge.file$Gene.2, mode="character"), mydata
  edgeData (mydata, as.vector(edge.file$Gene.1, mode="character"), as.vector(edge.file$Gene.2, mode="character"), attr='edgeType') <- as.character(edge.file$edgeType)
edgeData (mydata, as.vector(edge.file$Gene.1, mode="character"), as.vector(edge.file$Gene.2, mode="character"), attr='Weight') <- edge.file$Weight
#
return(mydata) }

Reply all
Reply to author
Forward
0 new messages