我使用findOverlaps(bed.1,bed.2)来获取重叠区域,现在我想将结果导出到新的床文件中,例如“xx.bed”。我怎么能在R?
overlapped GRanges object with 6 ranges and 3 metadata columns: (example)
seqnames ranges strand | name score pvalue
<Rle> <IRanges> <Rle> | <character> <numeric> <numeric>
[1] chr1 [ 32726, 32784] * | MACS_peak_7 2.06 0.3138672
[2] chr1 [ 52473, 52531] * | MACS_peak_11 2.06 0.3138672
[3] chr1 [136387, 136469] * | MACS_peak_32 3.40 0.5314789
[4] chr1 [235352, 235410] * | MACS_peak_41 2.06 0.3138672
[5] chr1 [540756, 540833] * | MACS_peak_71 6.42 0.8075350
[6] chr1 [636637, 636718] * | MACS_peak_90 4.86 0.6866363
现在我想将这些导出到新的床文件中。哪个R功能可以做到这一点?有没有简单的R代码可以做到这一点?感谢
答案 0 :(得分:0)
让我们在上面的例子中生成适当的可重现的例子:
foo <- GRanges(
seqnames=Rle(c("chr1", "chr2", "chr3", "chr4"), c(5, 6, 4, 3)),
ranges=IRanges(seq(1, by=9, len=18), seq(6, by=9, len=18)),
rangeName=letters[seq(1:18)], score=sample(1:25, 18, replace = FALSE))
然后,foo是将作为床格式文件导出的对象:
write.table(foo, "res.bed", append = TRUE, sep = "")
或者使用来自rtracklayer软件包的export.bed,两者都会产生相同的结果:
rtracklayer::export.bed(foo, "~/res.bed")