[Solved]Preserve metadata column for retrieving common regions from two GRanges objects
0
0
Entering edit mode
@jurat-shahidin-9488
Last seen 4.1 years ago
Chicago, IL, USA

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

granges intersect • 3.3k views
ADD COMMENT
0
Entering edit mode

How would you carry over the metadata columns? The intersect method creates entirely new ranges that might overlap multiple ranges in both a_abhit and a_achit.

ADD REPLY
0
Entering edit mode

Hi, 

I think intersect function did not create new ranges. However, this is what I got :

intersect(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.afirst, second regions of a)

I want to extract common regions from a that both had overlapped with regions from b,c respectively. Because there is case that same regions from a might be overlapped with regions from b, c. so I want to extract out these common regions with metadata.

Best regards:

Jurat

ADD REPLY
0
Entering edit mode

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 from a, then use findOverlaps to get the hits and merge the metadata through subscripting.

ADD REPLY
0
Entering edit mode

Yes, I will work on that. I think I have to come up another way to do this. Thanks

ADD REPLY

Login before adding your answer.

Traffic: 454 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6