【原创】R语言实战:read counts如何转化为TPM和FP
2020-01-29 本文已影响0人
酷睿_1991
载入数据
mycounts<-read.csv("2020武汉加油.csv")
head(mycounts)
rownames(mycounts)<-mycounts[,1]
mycounts<-mycounts[,-1]
head(mycounts)
TPM计算
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计算
fpkm <- t(t(rpk)/colSums(countdata) * 10^9)
head(fpkm)
write.table(fpkm,file="2020武汉加油_fpkm.xls",sep="\t",quote=F)
FPKM转化为TPM
fpkm_to_tpm = t(t(fpkm)/colSums(fpkm))*10^6
head(fpkm_to_tpm)
当然,已知所有基因的FPKM情况下,可以通过上述公式直接在excel里计算相应基因的TPM值。