Re: [Bioc-devel] is.unsorted method for GRanges objects

2015-11-03 Thread Michael Lawrence
Great. My point was that the "integer quad" algorithm could be generalized to any number of vectors and made part of base R. But maybe that's too much work for now. Michael On Tue, Nov 3, 2015 at 3:50 AM, Peter Hickey wrote: > Hi Michael, > > Sorry, I took this off-list with Hervé. I've written

Re: [Bioc-devel] is.unsorted method for GRanges objects

2015-11-03 Thread Peter Hickey
Hi Michael, Sorry, I took this off-list with Hervé. I've written a prototype is.unsorted,GenomicRanges-method. I structured it following the lead of order,GenomicRanges-method, so there's an outer R-level that "translates" the GenomicRanges object to 4 integer vectors (actually the slowest part o

Re: [Bioc-devel] is.unsorted method for GRanges objects

2015-11-03 Thread Michael Lawrence
If we're going to do that, it brings up the question of whether is.unsorted() could be made to handle multiple vectors like order(). It would be nice to implement that logic only once. Suggestions for the API? New function? Additional argument? Patches welcome ;) Michael On Mon, Nov 2, 2015 at 10

Re: [Bioc-devel] is.unsorted method for GRanges objects

2015-11-02 Thread Hervé Pagès
OK. Thanks Pete for the timings. The fact that the relative difference in speed is larger for small n in your brief tests is because one performs roughly in n*log(n) (quicksort-based) and the other one is linear in time. Which is why I assumed (but without doing any testing) that the latter was go

Re: [Bioc-devel] is.unsorted method for GRanges objects

2015-11-02 Thread Peter Hickey
Thanks for everyones' input. @Hervé FWIW, the below benchmark suggests that unfortunately this is a fair bit slower than is.unsorted(order(gr)) when the length of the GRanges object is < 10,000,000 (the relative difference in speed is larger for small n in my brief tests; I didn't check above n >

Re: [Bioc-devel] is.unsorted method for GRanges objects

2015-11-02 Thread Michael Lawrence
On Mon, Nov 2, 2015 at 6:39 PM, Hervé Pagès wrote: > Hi, > > @Pete: > > 2a- I would just compare pairs of adjacent elements, taking > advantage of the fact that <= is vectorized and cheap. So something > like: > > setMethod("is.unsorted", "Vector", > function(x, na.rm=FALSE, strictly=FALSE)

Re: [Bioc-devel] is.unsorted method for GRanges objects

2015-11-02 Thread Hervé Pagès
Hi, @Pete: 2a- I would just compare pairs of adjacent elements, taking advantage of the fact that <= is vectorized and cheap. So something like: setMethod("is.unsorted", "Vector", function(x, na.rm=FALSE, strictly=FALSE) { if (length(x) <= 1L) return(FALSE)

Re: [Bioc-devel] is.unsorted method for GRanges objects

2015-11-02 Thread Peter Haverty
genoset has an is.unsorted for GenomicRanges. I profiled a bit and found a pretty quick way to do it. My version ignores strand, so it is only proper in some cases. But, maybe it's a head start on a fully general function. Pete Peter M. Haverty, Ph.D. Genentech, Inc. phave.

Re: [Bioc-devel] is.unsorted method for GRanges objects

2015-11-02 Thread Michael Lawrence
The notion of sortedness is already formally defined, which is why we have an order method, etc. The base is.unsorted implementation for "objects" ends up calling base::.gt() for each adjacent pair of elements, which is likely too slow to be practical, so we probably should add a custom method. T

Re: [Bioc-devel] is.unsorted method for GRanges objects

2015-11-02 Thread Gabe Becker
Pete, What does sorted mean for granges? If the starts are sorted but the ends aren't does that count? What if only the ends are but the ranges are on the negative strand? Do we consider seqlevels to be ordinal in the order the levels are returned from seqlevels ()? That usually makes sense, but

[Bioc-devel] is.unsorted method for GRanges objects

2015-11-02 Thread Peter Hickey
Hi all, I sometimes want to test whether a GRanges object (or some object with a GRanges slot, e.g., a SummarizedExperiment object) is (un)sorted. There is no is.unsorted,GRanges-method or, rather, it defers to is.unsorted,ANY-method. I'm unsure that deferring to the is.unsorted,ANY-method is what