ESTIMATE R包计算TCGA免疫评分

2022-11-24  本文已影响0人  小熊_wh

文章参考生信技能树曾老师的帖子:使用ESTIMATE计算肿瘤的免疫得分 曾老师封装了个函数把ESTIMATE R包计算免疫评分和导出数据封一起了。

1. ESTIMATE R包安装

library(utils)
rforge <- "http://r-forge.r-project.org"
install.packages("estimate", repos=rforge, dependencies=TRUE)
library(estimate)

2. 计算免疫评分
这里以TCGA里面CHOL肿瘤为例,2022新版TCGA数据下载见:2022新版TCGA数据下载与整理,下载后的COUNT数据矩阵如下:

image.png
行为基因,列为样本。
dat=log2(edgeR::cpm(exp)+1) #因为下载的是count矩阵,如果是tpm这一步可以省略
library(estimate)
estimate <- function(dat,pro){
  input.f=paste0(pro,'_estimate_input.txt')
  output.f=paste0(pro,'_estimate_gene.gct')
  output.ds=paste0(pro,'_estimate_score.gct')
  write.table(dat,file = input.f,sep = '\t',quote = F)
  library(estimate)
  filterCommonGenes(input.f=input.f,
                    output.f=output.f ,
                    id="GeneSymbol")
  estimateScore(input.ds = output.f,
                output.ds=output.ds,
                platform="illumina")   ## platform
  scores=read.table(output.ds,skip = 2,header = T,check.names = F)
  rownames(scores)=scores[,1]
  scores=t(scores[,3:ncol(scores)])
 library(stringr)
  rownames(scores)=str_replace_all(rownames(scores),'[.]','-') # 这里TCGA样本名里面的-变成.了,进行恢复
  write.csv(scores,file="Stromal_Immune_ESTIMATE.Score.csv") # 这一步是我增加的
  return(scores)
}

3. 运行函数

pro='CHOL'
scores=estimate(dat,pro)

最后的scores长这样,StromalScore、ImmuneScore、ESTIMATEScore分别位于3列。这里platform选择的illumina,最后没有ESTIMATE-predicted tumor purity这一列,网友说platform = "affymetrix"时有肿瘤纯度。


image.png
上一篇 下一篇

猜你喜欢

热点阅读