[Bioc-sig-seq] `+` for GenomeData and coverage from several lanes

Simon Anders anders at ebi.ac.uk
Sun Jul 5 14:46:16 CEST 2009


Hi

Simon Anders wrote:
> following use-case here for an example of reducing with a map function.
> Assuming that 'lanes' is a list of 'AlignedRead' objects, I expect to
> get the coverage, summed over all these lanes (which are from the same
> condition), by writing something like
> 
> coverageOfAllLanes <-
>    Reduce(
>       function( gd1, gd2 ) Map( "+", gd1, gd2 ),
>       lapply( lanes, coverage, width = chromLengths ) )

Thinking about it again, it looks clumsy to have to define the addition
of GenomeData objects with 'Map( "+", gd1, gd2 )'.

What about adding a group generic as follows?

setMethod( "Arith", signature( e1 = "GenomeData", e2 = "GenomeData" ),
   function( e1, e2 )
      gdreduce(  # or: GenomeData( Map(
         function( r1, r2 ) get(.Generic)( r1, r2 ),
         e1, e2 ) )


Probably, it makes sense to put some base class of GenomeData in the
signature, to have it more general.

Also, we might allow for operations with scalars as the other argument,
as this is useful when multiplying with a normalization constant or
dividing by, say, the total number of reads. I'd suggest something like:

setMethod( "Arith", signature( e1 = "numeric", e2 = "GenomeData" ),
   function( e1, e2 ) {
      stopifnot( length(e1) == 1 )
      gdreduce(  # or: GenomeData( Map(
         function( r1, r2 ) get(.Generic)( r1, r2 ),
         e1, e2 ) } )

and the same with arguments swapped.


Cheers
  Simon



More information about the Bioc-sig-sequencing mailing list