To my knowledge, the function of splitting one GRanges by another is not
offered.  (We can split a GRanges by
a conforming factor).  I have a use case for sorting SNPloc GRanges into
ranges defined by transcripts.  I _think_
split() is a reasonable interface for this task but maybe there are angles
I am not seeing.

The following code seems to accomplish this.  Names on the splitting g2 are
needed to organize the results, and
will typically be gene or transcript IDs in the use case to which this is
addressed.

.splitGR2GRL = function(g1, g2, ...) {
   if (is.null(names(g2))) names(g2) = as.character(1:length(g2))
   fo = findOverlaps(g1, g2, ...)
   mm = matchMatrix(fo)
   if (prod(dim(mm))==0) stop("no matchMatrix generated in findOverlaps")
   mmo = mm[order(mm[,2]), ]
   GN = names(g2)[mmo[,2]]
   fac = split(mmo[,1], GN) #mmo[,2])  # no further reordering
   fac = factor(rep(names(fac), sapply(fac,length)))
   g1 = g1[mmo[,1]]
   split(g1, fac)  # may need to qualify
}

If this is too idiosyncratic I can leave it in one of my packages -- or
perhaps there is some high-level solution that
I have missed.

another point --

It seems unfortunate to me that the list elements are accessible only by
order or by name.  It is also desirable
to be able to get list elements or sublists by location.  Should this
always be left to detailed programming, or would
some general facility for selecting from GRangesList instances via
"["("GRangesList", "GRanges", ...) be useful?

	[[alternative HTML version deleted]]

