Retrieving overlaps inside a single dataset using foverlaps
1
0
Entering edit mode
8.2 years ago

1 chr1 58710367 58719391

2 chr1 58710476 58716325

Got a data as above in a single dataset. How to use foverlaps to perform Union ?

This should return 1 chr1 58710367 58719391.

How would I do that?

if it was

1 chr1 58710367 58719391

2 chr1 58719390 58719999

This should return 1 chr1 58710367 58719999

foverlaps RNA-Seq • 1.9k views
ADD COMMENT
2
Entering edit mode
8.2 years ago
Amirosein ▴ 70

you can use reduce() to perform union, for example we first make a GRanges object with your coordinates:

sep = GRanges( seqnames = "chr1", ranges = IRanges(start=c(58710367,58710476),end=c(58719391, 58716325)), strand = "+")

resulting:

GRanges object with 2 ranges and 0 metadata columns:
  seqnames               ranges strand
     <Rle>            <IRanges>  <Rle>
[1]     chr1 [58710367, 58719391]      +
[2]     chr1 [58710476, 58716325]      +

and then using reduce() to perform union:

U = reduce( sep )

resulting:

GRanges object with 1 range and 0 metadata columns:
  seqnames               ranges strand
     <Rle>            <IRanges>  <Rle>
[1]     chr1 [58710367, 58719391]      +

Remember that this function is sensitive to strand direction and won't union intervals from "+" and "-" strands, but if strand sets to "*" it works

ADD COMMENT

Login before adding your answer.

Traffic: 3153 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