1

I have granges objects like these( showing two of the four):

> upmd_Hf3a
  GRanges object with 398117 ranges and 2 metadata columns:
       seqnames                 ranges strand |        type       nCG
          <Rle>              <IRanges>  <Rle> | <character> <integer>
   [1]     chr1       [     1, 714170]      * |         PMD       280
   [2]     chr1       [714171, 732041]      * |      notPMD       103
   [3]     chr1       [732042, 762741]      * |         PMD       109
   [4]     chr1       [762742, 796127]      * |      notPMD       264
   [5]     chr1       [796128, 859047]      * |         PMD       829
   ...      ...                    ...    ... .         ...       ...
[398113]     chr9 [140133051, 140174235]      * |      notPMD      1725
[398114]     chr9 [140174236, 140176229]      * |         PMD       187
[398115]     chr9 [140176230, 140187041]      * |      notPMD       219
[398116]     chr9 [140967724, 140973103]      * |      notPMD       152
[398117]     chr9 [140973104, 141042747]      * |         PMD      1145
 seqinfo: 93 sequences from an unspecified genome

> upmd_Hf3b
GRanges object with 334247 ranges and 2 metadata columns:
       seqnames                 ranges strand |        type       nCG
          <Rle>              <IRanges>  <Rle> | <character> <integer>
   [1]     chr1       [     1, 712661]      * |         PMD       274
   [2]     chr1       [712662, 734889]      * |      notPMD       116
   [3]     chr1       [734890, 770103]      * |         PMD       152
   [4]     chr1       [770104, 794246]      * |      notPMD       163
   [5]     chr1       [794247, 859587]      * |         PMD       855
   ...      ...                    ...    ... .         ...       ...
[334243]     chr9 [137315552, 137325053]      * |      notPMD       265
[334244]     chr9 [138776843, 138782261]      * |         PMD       119
[334245]     chr9 [138782262, 138854249]      * |      notPMD      1899
[334246]     chr9 [139633630, 139648757]      * |         PMD       391
[334247]     chr9 [140835156, 140917488]      * |         PMD      1169
-------
seqinfo: 93 sequences from an unspecified genome

I have used MethylSeekR to create (predict paritally methylated domains-PMDs) these GRanges objects. I want to plot venn diagram for the PMD (for the column "type") regions for all these GRanges objects to show the overlap. Can anyone please help me with this ? Thanks a lot in advance

zx8754
  • 52,746
  • 12
  • 114
  • 209

1 Answers1

0

It is easier if you have your GRanges separately:

library(ChIPpeakAnno)
peaks1 <- GRanges("chr1", IRanges(seq(1, 100, 5), width=2), "+")
peaks2 <- GRanges("chr1", IRanges(seq(2, 20, 3), width=2), "+")
peaks3 <- GRanges("chr1", IRanges(seq(10, 50, 4), width=2), "+")
res <- makeVennDiagram(Peaks=list(peaks1, peaks2, peaks3),
                       NameOfPeaks=c("TF1", "TF2", "TF3"))

But if you have them as a single GRanges stratified by type metadata, you could make it GRangesList and plot it like this:

peaks1$type<-"TF1"
peaks2$type<-"TF2"
peaks3$type<-"TF3"
gr <- c(peaks1, peaks2, peaks3) # like your data

grl <- splitAsList(gr, gr$type)
res <- makeVennDiagram(Peaks=grl, NameOfPeaks=names(grl))

If you want a nice and colorful Venn diagram, then check https://github.com/js229/Vennerable/blob/master/README.md to install Venerable (I could not get it from Rforge) and do it like this:

library(Vennerable)
venn_cnt2venn <- function(venn_cnt){
  n <- which(colnames(venn_cnt)=="Counts") - 1
  SetNames=colnames(venn_cnt)[1:n]
  Weight=venn_cnt[,"Counts"]
  names(Weight) <- apply(venn_cnt[,1:n], 1, paste, collapse="")
  Venn(SetNames=SetNames, Weight=Weight)
}
v <- venn_cnt2venn(res$vennCounts)
plot(v)
Daniil
  • 36
  • 2