Skip to contents

Takes a count matrix and a vector of gene lengths and returns an optionally log2-transformed FPKM matrix. Modified from edgeR.

Usage

counts2fpkm(x, length, log = FALSE, prior.count = 0.25)

Arguments

x

a matrix of counts.

length

a vector of length nrow(x) giving length in bases.

log

logical, if TRUE, then log2 values are returned.

prior.count

average count to be added to each observation to avoid taking log of zero. Used only if log=TRUE.

Value

A matrix of FPKM values.

Examples

set.seed(123)
genecounts <- matrix(sample(c(rep(0, 50), 1:100), 30), nrow=10)
lengths <- sample(1000:10000, 10)
counts2fpkm(genecounts, lengths)
#>             [,1]      [,2]     [,3]
#>  [1,]      0.000 50077.649 25877.01
#>  [2,]      0.000 26843.373     0.00
#>  [3,]  15696.355  5639.880 24822.83
#>  [4,]      0.000     0.000 47068.43
#>  [5,]  22172.585     0.000 36617.45
#>  [6,] 167203.538 53056.027     0.00
#>  [7,]   9063.734  7801.286     0.00
#>  [8,]  11789.638 30977.450 13252.60
#>  [9,]  19730.653 12487.966     0.00
#> [10,]  33540.004 59421.817     0.00