deeenes

some little help for you, lovely bioinformatics students :)

Jan 2nd, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.48 KB | None | 0 0
  1. # loading the package
  2. require(igraph)
  3.  
  4. # some little modification on the graph merging functions
  5. source("merge_functions.r")
  6.  
  7. # reading input files
  8. notch <- read.graph("notch1.xml",format="graphml")
  9. smad <- read.graph("smad2.xml",format="graphml")
  10. axin <- read.graph("axin.xml",format="graphml")
  11.  
  12. # those graph's vertices do have `name' attribute:
  13. # V(axin)$name
  14. # that's required for graph.intersect.by.name()
  15. # and graph.union.by.name() functions to work
  16.  
  17. # merge just two:
  18. ns <- graph.union.by.name(notch,smad)
  19. # and then the union of two with the third:
  20. nsa <- graph.union.by.name(axin,ns)
  21.  
  22. # let's make membership matrix
  23. # iterating on the common graph's vertices:
  24. i <- 1
  25. n <- a <- s <- m <- q <- NULL
  26. for(v in V(nsa)$name){
  27.     ifelse(length(which(V(axin)$name==v))==0,aa <- FALSE,aa <- TRUE)
  28.     ifelse(length(which(V(smad)$name==v))==0,ss <- FALSE,ss <- TRUE)   
  29.     ifelse(length(which(V(notch)$name==v))==0,nn <- FALSE,nn <- TRUE)
  30.     a <- c(a,aa)
  31.     s <- c(s,ss)
  32.     n <- c(n,nn)
  33. }
  34.  
  35. m <- cbind(a,s,n)
  36.  
  37. # this is a little trick,
  38. # we can do it only because we have not more than three networks
  39. # this is how it works:
  40. # if the node is member of the axin network, we add 1 to it's value
  41. # if it is in the smad2 network, then we add 2
  42. # if in case of notch1 network membership, then the increment is 4
  43. # so all the 7 possibilities gonna be represented by an individual number
  44. # e.g. 7 means the node is member in all the three networks
  45. # or 6 means it's member of smad2 and notch1, but missing from the axin network
  46. # yeah, this is the same how unix file privilege notation works, btw :)
  47. for(v in V(nsa)$name){
  48.     ifelse(length(which(V(axin)$name==v))==0,aa <- 0,aa <- 1)
  49.     ifelse(length(which(V(smad)$name==v))==0,ss <- 0,ss <- 2)  
  50.     ifelse(length(which(V(notch)$name==v))==0,nn <- 0,nn <- 4)
  51.     q <- c(q,sum(aa,ss,nn))
  52. }
  53.  
  54. colnames(m) <- c("axin1","smad2","notch1")
  55.  
  56. # as palettes are vectors with integer indexes,
  57. # this integer vector `q' gives an easy way to  
  58. # select different colors for the 7 groups:
  59. rcol <- rainbow(7)
  60. V(nsa)$color <-rcol[q]
  61. V(nsa)$label <- V(nsa)$name
  62. nsa$layout <- layout.kamada.kawai
  63. E(nsa)$curved <- TRUE
  64. cairo_pdf(filename="merged.pdf",
  65.     onefile=TRUE,width=12,height=12,pointsize=12)
  66.     plot(nsa)
  67. dev.off()
  68.  
  69. # you should add some legend with the legend() function
  70. # of course before devoff()
  71. # please read the manual: ?legend or help(legend)
  72. # and don't copy, please understand well every bit of R functions u use!
  73. # denes »» [email protected] »»
Advertisement
Add Comment
Please, Sign In to add comment