support for multigraph

10 views
Skip to first unread message

Robert M. Flight

unread,
Jul 16, 2014, 4:51:19 PM7/16/14
to Paul Shannon, rcyto...@googlegroups.com
Hi Paul,

I was wondering if multiGraph class support ever got added to RCy, as I don't see anything in the NEWS file. I have a case where it would be especially useful for this. I know I can do it directly by addCyEdge after passing in the graph, but thought I would check if there is planned support for multiGraph.

Cheers,

-Robert

Mark Grimes

unread,
Jul 17, 2014, 1:03:54 PM7/17/14
to rcyto...@googlegroups.com
Robert

You can use addGraphToGraph.

Below are two functions that you may find useful; "loadedges" illustrates how addGraphToGraph may be used.

Mark

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


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)
}
#
--
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/d/optout.

Reply all
Reply to author
Forward
0 new messages