seqapply               package:IRanges               R Documentation

Apply function and cast to Sequence

Description:

     The 'seqapply' family of functions behaves much like the existing
     'lapply' family, except the return value is cast to a Sequence
     subclass. This facilitates constraining computation to the
     'Sequence' framework across iteration and (for 'seqsplit')
     splitting.

Usage:

     seqapply(X, FUN, ...)
     mseqapply(FUN, ..., MoreArgs = NULL, USE.NAMES = TRUE)
     tseqapply(X, INDEX, FUN = NULL, ...)
     seqsplit(x, f, drop = FALSE)

Arguments:

       X: The object over which to iterate, usually a vector or
          'Sequence' 

     FUN: The function that is applied to each element of 'X' 

MoreArgs: Additional arguments to 'FUN' that are treated like scalars 

USE.NAMES: Whether the return values should inherit names from one of
          the arguments 

   INDEX: A 'list' of factors to split 'X' into subsets, each of which
          is passed in a separate invocation of 'FUN' 

       x: Like 'X' above 

       f: A 'factor' or 'list' of factors 

    drop: Whether to drop empty elements from the returned list 

     ...: Extra arguments to pass to 'FUN' 

Details:

     These functions should be used just like their base equivalent:

     'seqapply' => 'lapply'

     'mseqapply' => 'mapply'

     'tseqapply' => 'tapply'

     'seqsplit' => 'split'

     The only difference is that the result is cast to a 'Sequence'
     object. The casting logic simply looks for a common class from
     which all returned values inherit. It then checks for the
     existence of a function of the form 'ClassList' where 'Class' is
     the name of the class. If such a function is not found, the search
     proceeds up the hierarchy of classes. An error is thrown when
     hierarchy is exhausted. If 'ClassList' is found, it is called with
     the list of return values as its only argument, under the
     assumption that a 'Sequence'-derived instance will be constructed.

Value:

     A 'Sequence' object

Author(s):

     Michael Lawrence

Examples:

     starts <- IntegerList(c(1, 5), c(2, 8))
     ends <- IntegerList(c(3, 8), c(5, 9))
     rangesList <- mseqapply(IRanges, starts, ends)
     rangeDataFrame <- stack(rangesList, "space", "ranges")
     dataFrameList <- seqsplit(rangeDataFrame, rangeDataFrame$space)
     starts <- seqapply(dataFrameList[,"ranges"], start)

