Apply a function over mapped data.

Description

Apply a function over each element of a list containing data subsets, organized by annotation, with an additional argument for the annotation element associated with the list item.

Usage

1
applyMapped(mapped, annoData, FUN, bindAnno = FALSE)

Arguments

mapped

A list of data subsets, typically the return value of a call to splitByAnnotation. Names should correspond to names of annoData object.

annoData

A data frame which must contain the columns chr, start, end and strand which specifies annotation regions of interest.

FUN

A function of two arguments, the first being an element of mapped, the second being the corresponding element of annoData.

bindAnno

Logical indicating whether annotation information should be included in the output. If TRUE it assumes the output of FUN is conformable into a data.frame.

Value

If bindAnno is FALSE, returns a list containing the output of FUN for each element of the original mapped argument. If bindAnno is TRUE, returns a data frame, containing annotation information and output of FUN.

Author(s)

James Bullard bullard@berkeley.edu, Kasper Daniel Hansen khansen@jhsph.edu

See Also

See Genominator vignette for more information.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ed <- ExpData(system.file(package = "Genominator", "sample.db"),
              tablename = "raw")
data("yeastAnno")
s <- splitByAnnotation(ed, yeastAnno[1:100,],
                       what = getColnames(ed, all = FALSE),
                       ignoreStrand = TRUE, addOverStrand = TRUE)

## compute the per-base rate for this dataset.
applyMapped(s, yeastAnno, function(dta, anno) {
   colSums(dta, na.rm = TRUE)/(anno$end - anno$start + 1)
}, bindAnno = TRUE)[1:4,]