granges - overlap percentage
2
0
Entering edit mode
19 months 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 • 938 views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
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

ADD REPLY
1
Entering edit mode
19 months 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.

ADD COMMENT
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.

ADD REPLY
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.

ADD REPLY
0
Entering edit mode
19 months ago
ab2063 ▴ 10

I figured out how to do it. Thanks all

ADD COMMENT
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.

ADD REPLY

Login before adding your answer.

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