[BioC] Is a number within a set of ranges?

Joern Toedling toedling at ebi.ac.uk
Mon Oct 29 18:29:11 CET 2007


Hi Daniel,

I think you could do something smarter using the "outer" function here.
Let's say, your matrix of intervals be "ints" and the Position column of
your genes-position matrix be pos,
then something like this, should give you only the positions of those
genes inside those intervals:

pos[which(rowSums(outer(pos,ints[,"Stop"],"<=") &
outer(pos,ints[,"Start"],">=") )>0)]

Maybe there's even a smarter way that I do not know of.

Regards,
Joern

Daniel Brewer wrote:
> I have a table with a start and stop column which defines a set of
> ranges.  I have another table with a list of genes with associated
> position.  What I would like to do is subset the gene table so it only
> contains genes whose position is within any of the ranges.  What is the
> best way to do this?  The only way I can think of is to construct a long
> list of conditions linked by ORs but I am sure there must be a better way.
>
> Simple example:
>
> Start	Stop
> 1	3
> 5	9
> 13	15
>
> Gene	Position
> 1	14
> 2	4
> 3	10
> 4	6
>
> I would like to get out:
> Gene	Position
> 1	14
> 4	6
>
> Any ideas?
>
> Thanks
>
> Dan
>
>



More information about the Bioconductor mailing list