#################################################################################### ## RedeR, dynamic networks in R ## Copyright (C) 2012 CRI-CRUK ## ## Source code to reproduce benchmark for RedeR software. ## ## RedeR program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 2 of the License, or ## (at your option) any later version. ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . ## ## Mauro Castro - mauro.castro@cancer.org.uk ################################################################################### #------------------------------------------------------------------------------------ # simple function to generate series of scale-free netwoks #..returns either igraph or graphNEL formats graph.scale.free<-function(n=100, tp=c("igraph","graphNEL")){ #get a ramdom graph with n nodes and p probability for drawing an edge g1 <- barabasi.game(n=n, directed=FALSE) if(tp[1]=="igraph")return(g1) #get nodes and edges to build a graphNEL object name <- as.character(seq(vcount(g1)) - 1) al <- get.adjlist(g1, "out") al <- lapply(al, function(x) as.character(x)) names(al) <- name g2 <- new("graphNEL", nodes=name, edgeL=al, edgemode="undirected") return(g2) } # returns a vector with geometric progression (used to set graph size)! gp <- function(init, mult, n){ if(n==1){ init } else { gp(c(init, init[length(init)] * mult), mult, n-1) } } #------------------------------------------------------------------------------------ # function to plot results from performance tests plotbenchmark<-function(res){ library(gplots) # re-order available tests tests<-c("baseline","igraph","Rgraphviz","tkplot","RCytoscape","RedeR") idx<-tests%in%names(res) res<-res[tests[idx]] # function to plot benchmark results plotbm<-function(x, y, ylim, col, lab, pch, cex=0.6, lwd=1.2){ sem <- apply(y,1,sd, na.rm=TRUE) y <- apply(y,1,mean, na.rm=TRUE) dy <- ylim[2]-ylim[1] checklen <- sem/dy sem[checklen<0.01]=dy*0.01 plotCI(x=x, y=y, uiw=sem, add=TRUE, barcol=col, pch=pch, col=col,cex=0.8, pt.bg=col, type='l', gap=0.0, lwd=lwd) points(x=x, y=y, pch=pch, col=col, cex=cex, bg="white") } # set plot layout (quartz will work only in Mac!) quartz(width=8, height=4.5) graphics::layout(matrix(c(1,2), 1, 2, byrow=TRUE)) # an empty plot xlab="Network size (n vertices)" ylab="Time (s)" ylim=c(0,2800) xlim=c(2,16384) plot(x=xlim, y=ylim, ylab=ylab, xlab=xlab, type="n", main="",sub=NULL, xlim=xlim, ylim=ylim, mgp=c(2.0, 0.6, 0), bty='n', log="x", cex.axis=0.7, cex.lab=0.9) # set labels, colors and formats labs=c('baseline','igraph','Rgraphviz/Graphviz','igraph/tkplot','RCytoscape/CytoscapeRPD','RedeR') names(labs)=tests cols=c('black','grey30','grey60','green','blue','red') names(cols)=tests pchs<-c(18,22,24,21,21,21) names(pchs)=tests # legends legend("topleft", legend=labs[c(1,2,3)], title="image rendering", col=cols[c(1,2,3)],pch=pchs[c(1,2,3)], cex=0.65,bty="n") legend("left", legend=labs[c(4,5,6)], title="data tranfer + image rendering", col=cols[c(4,5,6)],pch=pchs[c(4,5,6)], cex=0.65,bty="n") # main plot for(i in 1:length(res)){ plotbm(res[[i]]$nodecount,res[[i]]$timecount,ylim=ylim, col=cols[names(res)[i]],lab=labs[names(res)[i]],pch=pchs[names(res)[i]]) } # another empty plot ylim=c(0,10) plot(x=xlim, y=ylim, ylab=ylab, xlab=xlab, type="n", main="", sub=NULL, xlim=xlim, ylim=ylim, mgp=c(2.0, 0.6, 0), bty='n', log="x",cex.axis=0.7, cex.lab=0.9) # zoom on the 1st 10 seconds! for(i in 1:length(res)){ plotbm(res[[i]]$nodecount,res[[i]]$timecount, ylim=ylim, col=cols[names(res)[i]], lab=labs[names(res)[i]],pch=pchs[names(res)[i]], cex=0.8, lwd=1.5) } } #------------------------------------------------------------------------------------