来自GRanges的维恩图

时间:2016-06-29 09:30:05

标签: r overlap venn-diagram iranges

我有像这样的对象(显示四个中的两个):

> 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

我使用MethylSeekR来创建(预测paritally methylated domains-PMDs)这些GRanges对象。我想绘制所有这些GRanges对象的PMD(对于列“类型”)区域的维恩图,以显示重叠。有人可以帮我这个吗?非常感谢提前

1 个答案:

答案 0 :(得分:0)

如果您单独使用GRanges,则会更容易:

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"))

但如果您将它们作为单个GRangestype元数据分层,则可以将其设为GRangesList并将其绘制为:

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))

如果你想要一个漂亮而多彩的维恩图,那么检查https://github.com/js229/Vennerable/blob/master/README.md以安装尊者(我无法从Rforge那里得到它)并按照这样做:

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)