Is there a way to convert rpkm data to raw counts
1
0
Entering edit mode
18 months ago
rishav513 • 0

Hello, I have normalized rpkm data of RNA seq and I want to convert this data to raw counts so that I could use it for differential expression analysis. Is there any way to do that in R?

Any help would be appreciated.

rna • 903 views
2
Entering edit mode
18 months ago

There is a timeless post titled:

What the FPKM? A review of RNA-Seq expression units

https://haroldpimentel.wordpress.com/2014/05/08/what-the-fpkm-a-review-rna-seq-expression-units/

the blog provides formulas that can be inverted (note that you will need to know the length of each feature as it was applied during the RPKM computation):

countToTpm <- function(counts, effLen)
{
rate <- log(counts) - log(effLen)
denom <- log(sum(exp(rate)))
exp(rate - denom + log(1e6))
}

countToFpkm <- function(counts, effLen)
{
N <- sum(counts)
exp( log(counts) + log(1e9) - log(effLen) - log(N) )
}

fpkmToTpm <- function(fpkm)
{
exp(log(fpkm) - log(sum(fpkm)) + log(1e6))
}

countToEffCounts <- function(counts, len, effLen)
{
counts * (len / effLen)
}

################################################################################
# An example
################################################################################
cnts <- c(4250, 3300, 200, 1750, 50, 0)
lens <- c(900, 1020, 2000, 770, 3000, 1777)
countDf <- data.frame(count = cnts, length = lens)

# assume a mean(FLD) = 203.7
countDf$effLength <- countDf$length - 203.7 + 1
countDf$tpm <- with(countDf, countToTpm(count, effLength)) countDf$fpkm <- with(countDf, countToFpkm(count, effLength))
with(countDf, all.equal(tpm, fpkmToTpm(fpkm)))
countDf\$effCounts <- with(countDf, countToEffCounts(count, length, effLength))

0
Entering edit mode

Could you please further elaborate as I am new to R, it's a bit hard for me to understand. Actually, I have rpkm data which I downloaded from GEO, and the file downloaded is the "GSE94660_RPKM_normalized.txt" file and I am unable to understand how to convert this data to Tpm. Please explain it in detail, I will be always obeyed to you for this help.

0
Entering edit mode

Thanks for your help. Now, I understood