I have several RNA-seq datasets. Some of them provide RNA-seq raw counts, some provide FPKM, RPKM and some have transcripts per million (TPM) data. Non of them provide fastq files, all data is processed already. At the end I want all datasets to be normalized to TPM.
I'm using this code in order to normalize raw counts to TPM: (using R)
rpkm <- apply(X = subset(dataset),
MARGIN = 2,
FUN = function(x) {
10^9 * x / genelength / sum(as.numeric(x))
})
TPM <- apply(rpkm, 2, function(x) x / sum(as.numeric(x)) * 10^6) %>% as.data.frame()
When RPKM is provided, and no raw counts is available, I use the second line in the same code:
TPM <- apply(rpkm, 2, function(x) x / sum(as.numeric(x)) * 10^6) %>% as.data.frame()
And when FPKM is provided, I use this formula to transform the data to TPM:
TPM = FPKM*X
where X = 1e6/[sum of all FPKM of a sample]
NOTE: genelength
is obtained using the biomart
package in R, to get the transcript length directly out of ensemble.
However, because I know the steps of TPM normalization in theory, one should firstly normalize to gene length, and then to gene depth. I'm not sure this is what the code does, feeling very skiptical about it even thought this code was given to me by a Phd student.
Can you guys please help me with this question? is my code right or should I alter something?
Thank you!