載入數(shù)據(jù)
mycounts<-read.csv("2020武漢加油.csv")
head(mycounts)
rownames(mycounts)<-mycounts[,1]
mycounts<-mycounts[,-1]
head(mycounts)
TPM計(jì)算
kb <- mycounts$Length / 1000
kb
countdata <- mycounts[,1:9]
rpk <- countdata / kb
rpk
tpm <- t(t(rpk)/colSums(rpk) * 1000000)
head(tpm)
write.table(tpm,file="2020武漢加油_tpm.xls",sep="\t",quote=F)
FPKM計(jì)算
fpkm <- t(t(rpk)/colSums(countdata) * 10^6) (之前這里寫成了10^9砌烁,多謝@不愛說話的生物狗 提醒纪他,現(xiàn)在已經(jīng)修改)
head(fpkm)
write.table(fpkm,file="2020武漢加油_fpkm.xls",sep="\t",quote=F)
FPKM轉(zhuǎn)化為TPM
fpkm_to_tpm = t(t(fpkm)/colSums(fpkm))*10^6
head(fpkm_to_tpm)
當(dāng)然寥茫,已知所有基因的FPKM情況下,可以通過上述公式直接在excel里計(jì)算相應(yīng)基因的TPM值。