Hi,
I would like to retrieve common ranges from two GRanges
objects with metadata column (preserve metadata column is crucial). Yes, I used intersect
function from GenomicRanges
packages, but it can't return metadata together. Is there any function can retrieve common ranges from two GRanges objects with keeping metadata column ? Thanks a lot.
I have this reproducible example:
a <- GRanges(
seqnames=Rle(c("chr1", "chr2", "chr3", "chr4"), c(3, 2, 1, 2)),
ranges=IRanges(seq(1, by=5, len=8), seq(4, by=5, len=8)),
rangeName=letters[seq(1:8)],
score=sample(1:20, 8, replace = FALSE))
b <- GRanges(
seqnames=Rle(c("chr1", "chr2", "chr3","chr4"), c(4, 1, 2, 1)),
ranges=IRanges(seq(2, by=6, len=8), seq(5, by=6, len=8)),
rangeName=letters[seq(1:8)],
score=sample(1:20, 8, replace = FALSE))
c <- GRanges(
seqnames=Rle(c("chr1", "chr2", "chr3","chr4"), c(2, 4, 1,1)),
ranges=IRanges(seq(4, by=4, len=8), seq(5, by=4, len=8)),
rangeName=letters[seq(1:8)],
score=sample(1:15, 8, replace = FALSE))
And, I did like this but couldn't keep metadata column:
a_abhit <- subsetByOverlaps(a, b)
a_achit <- subsetByOverlaps(a, c)
commonRegion <- intersect(a_abhit, a_achit)
# but I want to keep metadata column as well
How can I keep metadata column when I am gonna extract common regions from a_abhit, a_achit ?
Thanks a lot
Best regards:
Jurat
How would you carry over the metadata columns? The
intersect
method creates entirely new ranges that might overlap multiple ranges in botha_abhit
anda_achit
.Hi,
I think
did not create new ranges. However, this is what I got :
intersect
functionintersect(a_abhit, a_achit)
GRanges object with 2 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] chr1 [1, 4] *
[2] chr1 [6, 9] *
And, result are certainly from sample
a (
a.k.a,
first, second regions ofa)
.I want to extract common regions from
a
that both had overlapped with regions fromb,c
respectively. Because there is case that same regions froma
might be overlapped with regions fromb, c.
so I want to extract out these common regions with metadata.Best regards:
Jurat
This is something you will have to work out in the context of your particular problem. For example, if you can assume that each intersected range only overlaps a single range in
a
, and that you always want to carry over the metadata froma
, then usefindOverlaps
to get the hits and merge the metadata through subscripting.Yes, I will work on that. I think I have to come up another way to do this. Thanks