I would like to know if is possible to filter out ranges by the number of probes within the range.
thank you very much
I would like to know if is possible to filter out ranges by the number of probes within the range.
thank you very much
I have a set of ranges with this format
chr | Start | End |
---|---|---|
1 | 55085885 | 55208800 |
2 | 39149784 | 39290200 |
3 | 39242892 | 39359065 |
And a list of thousands of probes with positions
x | 100177980 |
x1 | 1001754212 |
x2 | 352175422 |
I would like to select just the ranges that contain at least ten probes within them
You can use the function countOverlaps()
to do this. Here we'll create some dummy data - a set of two ranges and then a set of four points (these are ranges of width 1). In this example we're going to be interested in finding the ranges that have more than one point inside them. Only the first of our ranges meets this criteria.
library(IRanges) ranges <- IRanges(start = c(50,200), end = c(100,300)) points <- IRanges(start = c(75,80,150,250), width = 1)
We can then ask how many time each range overlaps with the set of points. The output from this is a vector, with the number of hits for each range
n_hits <- countOverlaps(query = ranges, subject = points)
> n_hits [1] 2 1
We can then select the ranges where there is more than one hit, and use this to subset. We're now left with only the one range.
keep_idx <- which(n_hits > 1) ranges_kept <- ranges[keep_idx]
> ranges_kept IRanges object with 1 range and 0 metadata columns: start end width <integer> <integer> <integer> [1] 50 100 51
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
The answer is probably yes, but it's not clear exactly what you are asking. Can you explain exactly what you want to do?
Ok, I will try