normalizeCounts {scater} | R Documentation

## Compute normalized expression values

### Description

Compute (log-)normalized expression values by dividing counts for each cell by the corresponding size factor.

### Usage

    normalizeCounts(x, ...)

    ## S4 method for signature 'ANY'
    normalizeCounts(
      x,
      size_factors = NULL,
      log = TRUE,
      pseudo_count = 1,
      center_size_factors = TRUE,
      subset_row = NULL,
      downsample = FALSE,
      down_target = NULL,
      down_prop = 0.01,
      BPPARAM = SerialParam()
    )

    ## S4 method for signature 'SummarizedExperiment'
    normalizeCounts(x, ..., exprs_values = "counts")

    ## S4 method for signature 'SingleCellExperiment'
    normalizeCounts(x, size_factors = NULL, ...)

### Arguments

`x` | A numeric matrix-like object containing counts for cells in the columns and features in the rows. Alternatively, a SingleCellExperiment or SummarizedExperiment object containing such a count matrix.
`...` | For the generic, arguments to pass to specific methods. For the SummarizedExperiment method, further arguments to pass to the ANY or DelayedMatrix methods. For the SingleCellExperiment method, further arguments to pass to the SummarizedExperiment method.
`size_factors` | A numeric vector of cell-specific size factors. Alternatively `NULL`, in which case the size factors are extracted or computed from `x`.
`log` | Logical scalar indicating whether normalized values should be log2-transformed.
`pseudo_count` | Numeric scalar specifying the pseudo_count to add when log-transforming expression values.
`center_size_factors` | Logical scalar indicating whether size factors should be centered at unity before being used.
`subset_row` | A vector specifying the subset of rows of `x` for which to return a result.
`downsample` | Logical scalar indicating whether downsampling should be performed prior to scaling and log-transformation.
`down_target` | Numeric scalar specifying the downsampling target when `downsample=TRUE`. If `NULL`, this is defined by `down_prop` and a warning is emitted.
`down_prop` | Numeric scalar between 0 and 1 indicating the quantile to use to define the downsampling target when `downsample=TRUE`.
`BPPARAM` | A BiocParallelParam object specifying how library size factor calculations should be parallelized. Only used if `size_factors` is not specified.
`exprs_values` | A string or integer scalar specifying the assay of `x` containing the count matrix.

### Details

Normalized expression values are computed by dividing the counts for each cell by the size factor for that cell. This aims to remove cell-specific scaling biases, e.g., due to differences in sequencing coverage or capture efficiency. If `log=TRUE`, log-normalized values are calculated by adding `pseudo_count` to the normalized count and performing a log2 transformation.

If no size factors are supplied, they are determined automatically from `x`:

- For count matrices and SummarizedExperiment inputs, the sum of counts for each cell is used to compute a size factor via the `librarySizeFactors` function.

- For SingleCellExperiment instances, the function searches for `sizeFactors` from `x`. If none are available, it defaults to library size-derived size factors.

If `size_factors` are supplied, they will override any size factors present in `x`.

### Value

A numeric matrix-like object of the same class as `x`, containing (log-)normalized expression values.

### Centering the size factors

If `center_size_factors=TRUE`, size factors are centred at unity prior to calculation of normalized expression values. This ensures that the computed expression values can be interpreted as being on the same scale as original counts. We can then compare abundances between features normalized with different sets of size factors; the most common use of this fact is in the comparison between spike-in and endogenous abundances when modelling technical noise (see `modelGeneVarWithSpikes` package for an example).

More generally, when `log=TRUE`, centering of the size factors ensures that the value of `pseudo_count` can be interpreted as being on the same scale as the counts, i.e., the pseudo-count can actually be thought of as a count. This is important as it implies that the pseudo-count's impact will diminish as sequencing coverage improves. Thus, if the size factors are centered, differences between log-normalized expression values will more closely approximate the true log-fold change with increasing coverage, whereas this would not be true of other metrics like log-CPMs with a fixed offset.

The disadvantage of using centered size factors is that the expression values are not directly comparable across different calls to `normalizeCounts`, typically for multiple batches. In theory, this is not a problem for metrics like the CPM, but in practice, we have to apply batch correction methods anyway to perform any joint analysis - see `multiBatchNorm` for more details.

### Downsampling instead of scaling

If `downsample=TRUE`, counts for each cell are randomly downsampled according to their size factors prior to log-transformation. This is occasionally useful for avoiding artifacts caused by scaling count data with a strong mean-variance relationship. Each cell is downsampled according to the ratio between `down_target` and that cell's size factor. (Cells with size factors below the target are not downsampled and are directly scaled by this ratio.) If `log=TRUE`, a log-transformation is also performed after adding `pseudo_count` to the downsampled counts.

Note that the normalized expression values in this mode cannot be interpreted as being on the same abundance as the original counts, but instead have abundance equivalent to counts after downsampling to the target size factor. This motivates the use of a fixed `down_target` to ensure that expression values are comparable across different `normalizeCounts` calls. We automatically set `down_target` to the 1st percentile of size factors across all cells involved in the analysis, but this is only appropriate if the resulting expression values are only compared within the same call to `normalizeCounts`. If expression values are to be compared across multiple calls (e.g., in `modelGeneVarWithSpikes` or `multiBatchNorm`), `down_target` should be manually set to a constant target value that can be considered a low size factor in every call.

### Author(s)

Aaron Lun

### See Also

`logNormCounts`, which wraps this function for convenient use with SingleCellExperiment instances.

`downsampleMatrix`, to perform the downsampling.

### Examples

    example_sce <- mockSCE()
    normed <- normalizeCounts(example_sce)
    str(normed)

[Package scater version 1.16.2 Index]