Skip to contents

Applies one or more transformations in the order given. The genes and samples stay the same. A message reports what was done.

Usage

rsem_transform(x, method, pseudocount = 1)

Arguments

x

The gene by sample table, as returned by rsem_read(), rsem_filter() or rsem_normalize().

method

One or more of "log2", "zscore", "center" and "rank", applied in this order. Required.

pseudocount

For "log2": the value added before the logarithm. Default 1.

Value

A data frame of transformed values in the same layout as x. The attribute "transform" lists the methods applied.

Methods

  • "log2": log2(value + pseudocount), with pseudocount = 1 by default. Compresses the range of TPM, CPM or normalized counts so that highly expressed genes do not dominate plots, distances and PCA. Needs values that are not negative.

  • "zscore": for each gene, subtracts its mean over samples and divides by its standard deviation, so every gene has mean 0 and standard deviation

    1. Used for heatmaps and for comparing genes on one scale. Apply it after "log2". A gene with the same value in every sample gets 0. Needs at least two samples.

  • "center": subtracts each gene's mean over samples, without dividing by the standard deviation.

  • "rank": within each sample, the rank of each gene divided by the number of genes, from near 0 (lowest) to 1 (highest); tied values share their average rank. It does not depend on the scale of the values, so samples measured or normalized differently can be compared. Rank-based scores such as singscore start from this.

For example, rsem_transform(tpm, c("log2", "zscore")) gives the usual heatmap scale.

Examples

if (requireNamespace("org.Hs.eg.db", quietly = TRUE)) {
  ex <- system.file("extdata", "example", package = "rsemverse")
  tpm <- rsem_read(file.path(ex, "data"), file.path(ex, "metadata.csv"),
                   species = "human", expr = "tpm")
  log_tpm <- rsem_transform(tpm, "log2")               # log2(TPM + 1)
  heat <- rsem_transform(tpm, c("log2", "zscore"))     # heatmap scale
  ranks <- rsem_transform(tpm, "rank")
}
#> rsem_read: 3 samples, 44 genes -> 43 rows (species = human, expr = tpm, org.Hs.eg.db 3.23.1)
#>   with symbol: 42 genes (1 symbols merged from several IDs); kept as original IDs: 2 genes
#> rsem_transform: 43 genes x 3 samples; log2(value + 1)
#> rsem_transform: 43 genes x 3 samples; log2(value + 1), then z-score per gene (0 constant genes set to 0)
#> rsem_transform: 43 genes x 3 samples; rank within sample / number of genes