Filter out ranges by number of probes
2
0
Entering edit mode
julrodr80 ▴ 30
@julrodr80-11991
Last seen 6.4 years ago

I would like to know if is possible to filter out ranges by the number of probes within the range.

 

thank you very much

probe ranges • 1.1k views
ADD COMMENT
1
Entering edit mode

The answer is probably yes, but it's not clear exactly what you are asking. Can you explain exactly what you want to do?

ADD REPLY
0
Entering edit mode

Ok, I will try

ADD REPLY
0
Entering edit mode
julrodr80 ▴ 30
@julrodr80-11991
Last seen 6.4 years ago

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

ADD COMMENT
0
Entering edit mode
Mike Smith ★ 6.5k
@mike-smith
Last seen 7 minutes ago
EMBL Heidelberg

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
ADD COMMENT
0
Entering edit mode

Thank you very much! I will try

ADD REPLY

Login before adding your answer.

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