feature R语言进行表达定量

文章介绍了如何使用R中的各种库(如Rsubread,limma,edgeR)处理bam和gtf/gff文件,进行转录本计数(featureCounts),并计算FPKM和TPM值,最后将统计结果和表达数据保存为表格。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

准备bam文件、gtf/gff文件

library(Rsubread)
library(limma)
library(edgeR)
library(tidyverse)
library(readr)
sample_name <- read_csv("sample.txt", col_names = FALSE) %>% pull(var = 1) %>% .[1:4] %>% str_sub(1,11)

for (i in 1:length(sample_name)) {
  
  sample = sample_name[i]
  bamFile = str_c("~/Program/tpm/",sample,".bam",sep = "")
  gtfFile = "~/Program/tpm/flax_trans.gtf"
  nthreads <- 16
  outFilePref <- "~/Program/tpm/"
  
  outStatsFilePath  <- str_c(outFilePref,sample, '.log',  sep = '')
  
  outCountsFilePath <- str_c(outFilePref,sample, '.count',  sep = '')
  
  fCountsList = featureCounts(bamFile,
                              annot.ext=gtfFile,
                              isGTFAnnotationFile=TRUE,
                              nthreads=nthreads,
                              isPairedEnd=F)
  dgeList = DGEList(counts=fCountsList$counts, genes=fCountsList$annotation)
  fpkm = rpkm(dgeList, dgeList$genes$Length)
  tpm = exp(log(fpkm) - log(sum(fpkm)) + log(1e6))
  
  write.table(fCountsList$stat, outStatsFilePath, sep="\t", col.names=FALSE, row.names=FALSE, quote=FALSE)
  
  featureCounts = cbind(fCountsList$annotation[,1], fCountsList$counts, fpkm, tpm)
  colnames(featureCounts) = c('gene_id', 'counts', 'fpkm','tpm')
  write.table(featureCounts, outCountsFilePath, sep="\t", col.names=TRUE, row.names=FALSE, quote=FALSE)
  
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘融晨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值