我用这个创建了以下GenomicRanges对象:
library(GenomicRanges)
gr <- GRanges(seqnames = "chr1", strand = c("+", "-","-", "+"),ranges = IRanges(start = c(1,3,3,5), width = 3))
gr
看起来像这样:
GRanges object with 4 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] chr1 1-3 +
[2] chr1 3-5 -
[3] chr1 3-5 -
[4] chr1 5-7 +
我想要做的是从那里获得唯一的行,产生这个(手工编码)
GRanges object with 3 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] chr1 1-3 +
[2] chr1 3-5 -
[3] chr1 5-7 +
我怎样才能做到这一点?实际上,我有大约 900 万行要处理。
我可以使用这种方法,但速度很慢:
library(tidyverse)
gr %>%
as.tibble() %>%
distinct()