Entering edit mode
2.3 years ago
octpus616
▴
120
Hi,
If I have two Granges:
library(rtracklayer)
library(dplyr)
library(Granges)
gr1 <- makeGRangesFromDataFrame(
data.frame(
chr=rep('6',3),
start=c(1,200,1000),
end=c(100,300,2000),
gene=paste0('ENSG', c('A', 'B', 'C')),
keep.extra.columns=TRUE))
gr1
seqnames ranges strand | ensembl_gene_id
<Rle> <IRanges> <Rle> | <character>
[1] 6 [1, 100] * | ENSGA
[2] 6 [200, 300] * | ENSGB
[3] 6 [1000, 2000] * | ENSGC
gr2 <- makeGRangesFromDataFrame(
data.frame(
chr=rep('6',3),
start=c(70,100,1900),
end=c(100,300,2000),
gene=paste0('ENSG', c('A', 'B', 'C')),
keep.extra.columns=TRUE))
gr2
seqnames ranges strand | ensembl_gene_id
<Rle> <IRanges> <Rle> | <character>
[1] 6 [70, 100] * | ENSGA
[2] 6 [100, 300] * | ENSGB
[3] 6 [1900, 2000] * | ENSGC
I want to subtract gr1 to gr2 like this
gr
seqnames ranges strand | ensembl_gene_id
<Rle> <IRanges> <Rle> | <character>
[1] 6 [1, 30] * | ENSGA
[3] 6 [1000, 1900] * | ENSGC
I know some function such as findoverlap
and queryHits
or setdiff
may can do like this, but their output is similar with bedtools subtract
(may with -A also), so them may cant keep extra columns, Is there any way to keep extra columns?
Best
Zhang
If you share your example data here with the
dput
function it makes it easier for people to answer the question since they can just copy/paste it into R.Hi rpolicastro,
Thanks for you advices, I have add some code can be using for make example, I also got a new function
dput
, Its seem awesome. I will try it next time.