granges - overlap percentage
2
0
Entering edit mode
2.8 years ago
ab2063 ▴ 10

Hello everyone,

I have 2 granges object, x,y. I want to find overlap between them. Say in first row of x there are "n" of y overlapping, i want to get percentage of such overlap and then filter them on the basis of percentages, say 0-25%, 25-50%, 50-75%, 75-100%. Can you please help me doing it in R

R • 1.4k views
0
Entering edit mode

What have you tried? Have you looked through GRanges posts here and on http://support.bioconductor.org/?

0
Entering edit mode

I used the GenomicRanges R package, using countoverlaps, to find overlaps between two sets of genomic ranges. I want to add a column to x indicating the percentage of overlap with y for each row of x. But I do not get what I want as output

1
Entering edit mode
2.8 years ago

GRanges admit direct overlapping indexing. That is to say, you can use %over% to index them. For example, we have a the dataframe X that contains some information, including its associated coordinate ranges (stored as GRanges in X@coordinates). Given GRanges object coordinates (e.g. as("X:71223192-71525892:+", Class = "GRanges")) I can do the following:

coordinates <- as("X:71223192-71525892:+", Class = "GRanges")
X@coordinates[X@coordinates %over% coordinates]


This will retrieve the overlapping coordinates, which you can use to calculate the percentage of overlaping, or to index the metadata object X.

0
Entering edit mode

thanks, i did get overlaps using countoverlaps and converted it into percentage. what i want is it separated in quantile as i mentioned in original question, 0-25%, 25-50%, 50-75%, 75-100%, total 4 groups. I am unable to do this.

0
Entering edit mode

If you already have the raw percentage and only wish to bin it to quantiles, it doesn't have anything to do with GRanges as such - the operation you're looking for can be performed on any vector of numbers. Please search online (especially on StackOverflow) on how to bin a vector into quantiles.

0
Entering edit mode
2.8 years ago
ab2063 ▴ 10

I figured out how to do it. Thanks all

0
Entering edit mode

If you did it is a different way than what was suggested in answer by @maqquimeded21 then please post the correct solution by editing this answer to provide closure to this thread. If you used that answer then please accept that answer (green check) mark to provide closure to this thread.