calculateCPM {csaw} | R Documentation

## Calculate CPM

### Description

Calculate counts-per-million (CPM) values for each feature.

### Usage

    calculateCPM(object, use.norm.factors=TRUE, use.offsets=FALSE,
        log=TRUE, prior.count=1, assay.id="counts")

### Arguments

`object` | A SummarizedExperiment object containing a count matrix, as produced by `windowCounts`.
`use.norm.factors` | A logical scalar indicating whether to use normalization factors, if available.
`use.offsets` | A logical scalar indicating whether to use offsets, if available.
`log` | A logical scalar indicating whether log2-transformed CPM values should be returned.
`prior.count` | A numeric scalar specifying the prior count to add when `log=TRUE`.
`assay.id` | A string or integer scalar indicating which assay of `y` contains the counts.

### Details

CPMs are calculated in the standard manner when `log=FALSE`, `use.offsets=FALSE` and `use.norm.factors=FALSE`.

When `log=TRUE`, a library size-adjusted prior count is added to both the counts and the library sizes, see `cpm` for details.

When `use.norm.factors=TRUE`, the effective library size is used for computing CPMs, provided that normalization factors are available in `object`. This is defined as the product of the library size in `object$totals` and the normalization factor in `object$norm.factors`.

If `use.offsets=TRUE`, the offsets are converted into effective library sizes using `scaleOffset`. If `log=TRUE`, this is done after addition of a prior count to both the counts and library sizes, see `addPriorCount` for details.

### Value

A matrix of the same dimensions as `object`, containing (log-)transformed CPM values for each feature in each sample.

### Author(s)

Aaron Lun

### See Also

`cpm`, `scaleOffset`, `addPriorCount`

### Examples

    bamFiles <- system.file("exdata", c("rep1.bam", "rep2.bam"), package="csaw")
    data1 <- windowCounts(bamFiles, width=50, filter=1)
    head(calculateCPM(data1))

    data1$norm.factors <- c(0.5, 1.5)
    head(calculateCPM(data1))

    head(calculateCPM(data1, log=FALSE))

    # With offsets:
    assay(data1, "offset") <- matrix(rnorm(nrow(data1)*ncol(data1)),
        nrow=nrow(data1), ncol=ncol(data1))
    head(calculateCPM(data1, use.offsets=TRUE))

    head(calculateCPM(data1, use.offsets=FALSE))

[Package csaw version 1.21.4 Index]