count转fpkm和tpm
2023-11-29 本文已影响0人
pudding815
以下列数据为例子,需要count矩阵并包含基因长度、
(没有的话从gtf提取,前面我写过教程)
count矩阵示例.png
count矩阵读入
count <- read.table('count.txt',header = T,sep = '\t',row.names = 1)
#提取基因长度信息/1000
kb <- count$Length/1000
#count表处理为仅含样本的表,去掉基因位置长度信息
count <- count[,-c(1:5)]
count处理后示例.png
count to TPM
library(dplyr)
-------------------------get TPM--------------------------------
rpk <- count/ kb
tpm <- t(t(rpk)/colSums(rpk) * 1000000)
tpm <- round(tpm,2) %>% as.data.frame()
count to FPKM
-------------------------get FPKM--------------------------------
fpkm <- t(t(rpk)/colSums(count) * 10^6)
fpkm <- round(fpkm,2) %>% as.data.frame()
FPKM to TPM
-------------------------FPKM to TPM--------------------------------
fpkm_to_tpm <- t(t(fpkm)/colSums(fpkm) * 10^6)
fpkm_to_tpm <- round(fpkm_to_tpm,2) %>% as.data.frame()