Skip to content.

bioconductor.org

Bioconductor is an open source and open development software project
for the analysis and comprehension of genomic data.

Sections

labgraph.R

################################################### ### chunk number 1: setup ################################################### library(graph) library(Rgraphviz)

################################################### ### chunk number 2: writeDot ################################################### writeDot <- function(g, y="dot", f) { filegxl <- paste(f, ".gxl", sep="") filedot <- paste(f, ".dot", sep="") filegif <- paste(f, ".gif", sep="") saveXML(toGXL(g)$value(), file=filegxl) #$ system(paste("gxl2dot", filegxl, ">", filedot)) system(paste(y, "-Tgif", filedot, ">", filegif)) return(filegif) }

################################################### ### chunk number 3: my1stgraph ################################################### edges <- list(a=list(edges=2:3), b=list(edges=2:3), c=list(edges=c(2,4)), d=list(edges=1)) g <- new("graphNEL", nodes=letters[1:4], edgeL=edges, edgemode="directed") g

################################################### ### chunk number 4: plotmy1stgraph ################################################### plot(g, main="My first graph") writeDot(g, f="myfirstgraph")

################################################### ### chunk number 5: nodesedges ################################################### nodes(g) edges(g) degree(g)

################################################### ### chunk number 6: adjacc ################################################### edges <- list(a=list(edges=2:3), b=list(edges=2:3), c=list(edges=c(2,4)), d=list(edges=1), e=list(edges=6,7), f=list(edges=7), g=list(edges=7)) g <- new("graphNEL", nodes=letters[1:7], edgeL=edges, edgemode="directed") plot(g, main="Example for adj, acc")

adj(g, c("b", "c")) acc(g, c("b", "c"))

################################################### ### chunk number 7: ugraph ################################################### ug <- ugraph(g) plot(ug, main="Undirected Graph")

################################################### ### chunk number 8: subgraph ################################################### sg <- subGraph(c("a", "b", "c", "f"), ug) plot(sg, main="subGraph")

################################################### ### chunk number 9: boundary ################################################### bd <- boundary(sg, ug) bd

################################################### ### chunk number 10: weighted ################################################### edges <- list(a=list(edges=2:3, weights=1:2), b=list(edges=2:3, weights=c(0.5, 1)), c=list(edges=c(2,4), weights=c(2:1)), d=list(edges=1, weights=3)) g <- new("graphNEL", nodes=letters[1:4], edgeL=edges, edgemode="directed") edgeWeights(g)

################################################### ### chunk number 11: algebra ################################################### g1 <- addNode("e", g) g2 <- removeNode("d", g)

## addEdge(from, to, graph, weights) g3 <- addEdge("e", "a", g1, pi/2)

## removeEdge(from, to, graph) g4 <- removeEdge("e", "a", g3)

identical(g4, g1)

## par(mfrow=c(2,1)) ## plot(ug) ## g5 <- combineNodes(c("b", "c"), ug, "w") ## plot(g5)

################################################### ### chunk number 12: union ################################################### par(mfrow=c(2,3)) V <- letters[1:4] set.seed(4713) g1 <- randomGraph(V, 1, .55) g2 <- randomGraph(V, 1, .55) plot(g1, main="g1") plot(g2, main="g2") plot(complement(g1), main="complement(g1)") plot(intersection(g1, g2), main="intersection(g1,g2)") plot(union(g1, g2), main="union(g1,g2)") par(mfrow=c(1,1))

################################################### ### chunk number 13: tsort ################################################### library(RBGL) data(FileDep) plot(FileDep, main="Topological sort order example graph")

ts <- tsort(FileDep) nodes(FileDep)[ts+1]

################################################### ### chunk number 14: mstree1 ################################################### km <- fromGXL(file(system.file("GXL/kmstEx.gxl", package = "graph"))) ms <- mstree.kruskal(km)

################################################### ### chunk number 15: mstree2 ################################################### e <- buildEdgeList(km) n <- buildNodeList(km) for(i in 1:ncol(ms$edgeList)) e[[paste(ms$nodes[ms$edgeList[,i]], collapse="~")]]@attrs$color <- "red" z <- agopen(nodes=n, edges=e, edgeMode="directed", name="") plot(z, main="Topological sort order example graph")

################################################### ### chunk number 16: bfs ################################################### dd <- fromGXL(file(system.file("XML/bfsex.gxl", package = "RBGL"))) plot(dd, main="Breadth first search example graph")

br <- bfs(dd, "r") nodes(dd)[br]

bs <- bfs(dd, "s") nodes(dd)[bs]

################################################### ### chunk number 17: dfs ################################################### dd <- fromGXL(file(system.file("XML/dfsex.gxl", package = "RBGL"))) plot(dd, main="Depth first search example graph")

df <- dfs(dd, "u") nodes(dd)[df$discovered] nodes(dd)[df$finish]

################################################### ### chunk number 18: shortpath ################################################### g <- fromGXL(file(system.file("XML/dijkex.gxl", package = "RBGL"))) plot(g, main="Shortest path example graph")

sp.between(g, "E", "C") dijkstra.sp(g)

################################################### ### chunk number 19: connComp ################################################### g1 <- removeEdge(A, C, g) g1 <- removeEdge(D, E, g1) g1 <- removeEdge(B, E, g1) g1 <- removeEdge(E, B, g1) connectedComp(g) connectedComp(g1)

par(mfrow=c(1,2)) plot(g, main="g") plot(g1, main="g1")

################################################### ### chunk number 20: strongConnComp ################################################### km <- fromGXL(file(system.file("XML/kmstEx.gxl",package="RBGL"))) km@nodes <- c(km@nodes,"F","G","H") km@edgeL$F <- list(edges=numeric(0)) km@edgeL$G <- list(edges=8) km@edgeL$H <- list(edges=7)

strongComp(km) connectedComp(ugraph(km)) plot(km, main="km: connected components example graph")

################################################### ### chunk number 21: connectivity ################################################### g <- fromGXL(file(system.file("XML/conn.gxl",package="RBGL"))) edgeConnectivity(g) plot(g, main="g: edgeConnectivity example graph")

################################################### ### chunk number 22: threemethods ################################################### attrs <- getDefaultAttrs() attrs$node$fillcolor <- red attrs$node$height <- 1 attrs$node$label <- myplot <- function(m) plot(FileDep, m, main=m, attrs=attrs)

par(mfrow=c(1,3)) myplot("dot") myplot("neato") myplot("twopi")

News
2009-10-26

BioC 2.5, consisting of 352 packages and designed to work with R 2.10.z, was released today.

2009-01-07

R, the open source platform used by Bioconductor, featured in a series of articles in the New York Times.