Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # loading the package
- require(igraph)
- # some little modification on the graph merging functions
- # can be found here: http://pastebin.com/hiu9dbEH
- source("merge_functions.r")
- # reading input files
- notch <- read.graph("notch1.xml",format="graphml")
- smad <- read.graph("smad2.xml",format="graphml")
- axin <- read.graph("axin.xml",format="graphml")
- # those graph's vertices do have `name' attribute:
- # V(axin)$name
- # that's required for graph.intersect.by.name()
- # and graph.union.by.name() functions to work
- # merge just two:
- ns <- graph.union.by.name(notch,smad)
- # and then the union of two with the third:
- nsa <- graph.union.by.name(axin,ns)
- # let's make membership matrix
- # iterating on the common graph's vertices:
- i <- 1
- n <- a <- s <- m <- q <- NULL
- for(v in V(nsa)$name){
- ifelse(length(which(V(axin)$name==v))==0,aa <- FALSE,aa <- TRUE)
- ifelse(length(which(V(smad)$name==v))==0,ss <- FALSE,ss <- TRUE)
- ifelse(length(which(V(notch)$name==v))==0,nn <- FALSE,nn <- TRUE)
- a <- c(a,aa)
- s <- c(s,ss)
- n <- c(n,nn)
- }
- m <- cbind(a,s,n)
- # this is a little trick,
- # we can do it only because we have not more than three networks
- # this is how it works:
- # if the node is member of the axin network, we add 1 to it's value
- # if it is in the smad2 network, then we add 2
- # if in case of notch1 network membership, then the increment is 4
- # so all the 7 possibilities gonna be represented by an individual number
- # e.g. 7 means the node is member in all the three networks
- # or 6 means it's member of smad2 and notch1, but missing from the axin network
- # yeah, this is the same how unix file privilege notation works, btw :)
- for(v in V(nsa)$name){
- ifelse(length(which(V(axin)$name==v))==0,aa <- 0,aa <- 1)
- ifelse(length(which(V(smad)$name==v))==0,ss <- 0,ss <- 2)
- ifelse(length(which(V(notch)$name==v))==0,nn <- 0,nn <- 4)
- q <- c(q,sum(aa,ss,nn))
- }
- colnames(m) <- c("axin1","smad2","notch1")
- # as palettes are vectors with integer indexes,
- # this integer vector `q' gives an easy way to
- # select different colors for the 7 groups:
- rcol <- rainbow(7)
- V(nsa)$color <-rcol[q]
- V(nsa)$label <- V(nsa)$name
- nsa$layout <- layout.kamada.kawai
- E(nsa)$curved <- TRUE
- cairo_pdf(filename="merged.pdf",
- onefile=TRUE,width=12,height=12,pointsize=12)
- plot(nsa)
- dev.off()
- # you should add some legend with the legend() function
- # of course before devoff()
- # please read the manual: ?legend or help(legend)
- # and don't copy, please understand well every bit of R functions u use!
- # denes »» [email protected] »»
Advertisement
Add Comment
Please, Sign In to add comment