[BioC] Using precede()/follow() to find two ranges

Steve Lianoglou lianoglou.steve at gene.com
Wed Aug 21 18:10:08 CEST 2013


Hi,

On Wed, Aug 21, 2013 at 7:25 AM, d r <dolevrahat at gmail.com> wrote:
> Hello
>
> I am looking for a way to find the two preceiding/folliwng ranges in one
> GRanges object to each range in a second GRanges object.
>
> In other words, I am looking for a variation on precede() or follow() that
> will return for each range in x two ranges in subject instead of one: the
> nearest preceidng(following) range and the second nearest preceding
> (following) range.
>
> Is there a way to do this? (sorry for not giving any more constructive
> suggestions, I know relativily  little on how GRanges works any therefore
> am at a loss as to how to proceed)

A first draft way of doing that would be to simply use the results
from the first precede to remove those elements from the second call?

For instance, if you have two ranges you are querying, gr1 and gr2:

To get the immediately preceding ranges:

R> p1 <- precede(gr1, gr2)

Then to get the ones immediately after that:

R> gr2.less <- gr2[-p1]
R> p2 <- precede(gr1, gr2.less)

Then you can see who is who with `gr2[p1]` and the who-who is who with
`gr2.less[p2]` ... that should get you pretty close -- will likely
have to handle edge cases, for instance when there are no preceding
ranges, I think you get an NA (if I recall) so think about what you
want to do with those.

-steve

-- 
Steve Lianoglou
Computational Biologist
Bioinformatics and Computational Biology
Genentech



More information about the Bioconductor mailing list