最近学习了生信菜鸟团的纯R代码实现ssGSEA算法评估肿瘤免疫浸润程度,想复制作者的流程,但是发现了几个不一样的地方,所以重新整理流程,代码主要来自原作者Juan_NF。
文章来源:Local mutational diversity drives intratumoral immune heterogeneity in non-small cell lung cancer
方法来源:
Pan-cancer Immunogenomic Analyses Reveal Genotype-Immunophenotype Relationships and Predictors of Response to Checkpoint Blockade
研究背景:方法基于使用metagenes,即代表特定免疫细胞亚群的非重叠基因组,并且既不在CRC细胞系中也不在正常组织中表达。然后使用这些组的metagenes的表达来使用基因集富集分析(GSEA)分析统计富集。优点是该方法的稳健性,这是由于两个特征:
(1)使用一组基因而不是代表一个免疫亚群的单个基因,因为使用单个基因作为免疫亚群的标记可以是误导因为许多基因在不同的细胞类型中表达;
(2)评估一组基因相对于样品中所有其他基因表达的相对表达变化。
为28个免疫细胞亚群定义了一组泛癌症,并将分析扩展到实体癌症。对具有> 8,000个肿瘤样品的20个实体癌症的TCGA数据进行了免疫原性表征,并提供了肿瘤内免疫浸润的细胞组成的全面视图。此外,还得出了癌症抗原以及个体样本的遗传特征(肿瘤异质性和克隆性),以便能够对免疫特征以及肿瘤的遗传特征进行综合分析。开发了数据库TCIA(癌症免疫组图谱)。基于反卷积方法识别免疫亚群的分数(CIBERSORT;
纽曼等人,2015年)在TCIA网站上提供了GSEA和反卷积数据。
1.提取矩阵和表型信息,需要手动从GEO下载
下载GSE112996_merged_fpkm_table.txt.gz
GSE112996_series_matrix.txt.gz,这两个文件,对
GSE112996_series_matrix.txt.gz进行解压,把这两个文件放到Rproject创建的文件夹。
rm(list=ls())
a <- read.table('GSE112996_merged_fpkm_table.txt.gz',
header = T,
row.names=1)
raw_data<- a[,-1]
###表型信息提取
pheno <- read.csv(file = 'GSE112996_series_matrix.txt')
pheno <- data.frame(num1 = strsplit(as.character(pheno[42,]),split='\t')[[1]][-1],
num2 = gsub('patient: No.','P',strsplit(as.character(pheno[51,]),split='\t')[[1]][-1]))
{
####数据过滤
data<- a[!apply(raw_data,1,sum)==0,]
####去除重复基因名的行,归一化
data$median=apply(data[,-1],1,median)
data=data[order(data$GeneName,data$median,decreasing = T),]
data=data[!duplicated(data$GeneName),]
rownames(data)=data$GeneName
uni_matrix <- data[,grep('\\d+',colnames(data))]
uni_matrix <- log2(uni_matrix+1)
colnames(uni_matrix)<- gsub('X','',gsub('\\.','\\-',colnames(uni_matrix)))
uni_matrix<- uni_matrix[,order(colnames(uni_matrix))]
}
save(uni_matrix,pheno,file = 'uni_matrix.Rdata')
2.进行ssGSEA分析
只是用到了处理后的矩阵和基因集两个内容;对score结果归一化后进行热图绘制。
获取免疫细胞的metagenes基因集,得到一个名为mmc3.xlsx的文件,删除前两行,保存为mmc3.csv。
##加载包
{
library(genefilter)
library(GSVA)
library(Biobase)
library(stringr)
}
##载入数据
load('uni_matrix.Rdata')
gene_set<-read.csv("mmc3.csv")[, 1:2]
head(gene_set)
list<- split(as.matrix(gene_set)[,1], gene_set[,2])
gsva_matrix<- gsva(as.matrix(uni_matrix), list,method='ssgsea',kcdf='Gaussian',abs.ranking=TRUE)
library(pheatmap)
gsva_matrix1<- t(scale(t(gsva_matrix)))
gsva_matrix1[gsva_matrix1< -2] <- -2
gsva_matrix1[gsva_matrix1>2] <- 2
anti_tumor <- c('Activated CD4 T cell', 'Activated CD8 T cell', 'Central memory CD4 T cell', 'Central memory CD8 T cell', 'Effector memeory CD4 T cell', 'Effector memeory CD8 T cell', 'Type 1 T helper cell', 'Type 17 T helper cell', 'Activated dendritic cell', 'CD56bright natural killer cell', 'Natural killer cell', 'Natural killer T cell')
pro_tumor <- c('Regulatory T cell', 'Type 2 T helper cell', 'CD56dim natural killer cell', 'Immature dendritic cell', 'Macrophage', 'MDSC', 'Neutrophil', 'Plasmacytoid dendritic cell')
anti<- gsub('^ ','',rownames(gsva_matrix1))%in%anti_tumor
pro<- gsub('^ ','',rownames(gsva_matrix1))%in%pro_tumor
non <- !(anti|pro)
gsva_matrix1<- rbind(gsva_matrix1[anti,],gsva_matrix1[pro,],gsva_matrix1[non,])
normalization<-function(x){
return((x-min(x))/(max(x)-min(x)))}
nor_gsva_matrix1 <- normalization(gsva_matrix1)
annotation_col = data.frame(patient=pheno$num2)
rownames(annotation_col)<-colnames(uni_matrix)
bk = unique(c(seq(0,1, length=100)))
pheatmap(nor_gsva_matrix1,
show_colnames = F,
cluster_rows = F,cluster_cols = F,
annotation_col = annotation_col,
breaks=bk,cellwidth=5,cellheight=5,
fontsize=5,gaps_row = c(12,20),
filename = 'ssgsea.pdf',width = 8)
save(gsva_matrix,gsva_matrix1,pheno,file = 'score.Rdata')
3.计算score加和后,ggplot2进行绘图
rm(list=ls())
anti_tumor <- c('Activated CD4 T cell', 'Activated CD8 T cell', 'Central memory CD4 T cell', 'Central memory CD8 T cell', 'Effector memeory CD4 T cell', 'Effector memeory CD8 T cell', 'Type 1 T helper cell', 'Type 17 T helper cell', 'Activated dendritic cell', 'CD56bright natural killer cell', 'Natural killer cell', 'Natural killer T cell')
pro_tumor <- c('Regulatory T cell', 'Type 2 T helper cell', 'CD56dim natural killer cell', 'Immature dendritic cell', 'Macrophage', 'MDSC', 'Neutrophil', 'Plasmacytoid dendritic cell')
load('score.Rdata')
anti<- as.data.frame(gsva_matrix1[gsub('^ ','',rownames(gsva_matrix1))%in%anti_tumor,])
pro<- as.data.frame(gsva_matrix1[gsub('^ ','',rownames(gsva_matrix1))%in%pro_tumor,])
anti_n<- apply(anti,2,sum)
pro_n<- apply(pro,2,sum)
patient <- pheno$num2[match(colnames(gsva_matrix1),pheno$num1)]
library(ggplot2)
data <- data.frame(anti=anti_n,pro=pro_n,patient=patient)
anti_pro<- cor.test(anti_n,pro_n,method='pearson')
gg<- ggplot(data,aes(x = anti, y = pro),color=patient) +
xlim(-20,15)+ylim(-15,10)+
labs(x="Anti-tumor immunity", y="Pro-tumor suppression") +
geom_point(aes(color=patient),size=3)+geom_smooth(method='lm')+
annotate("text", x = -5, y =7.5,label=paste0('R=',round(anti_pro$estimate,4),'\n','p<0.001'))
ggsave(gg,filename = 'cor.pdf', height = 6, width = 8)
基本一致,但是细节之处需要调节,不当之处请指正!
参考文献:
- 纯R代码实现ssGSEA算法评估肿瘤免疫浸润程度
- Pan-cancer Immunogenomic Analyses Reveal Genotype-Immunophenotype Relationships and Predictors of Response to Checkpoint Blockade
- Local mutational diversity drives intratumoral immune heterogeneity in non-small cell lung cancer
生信技能树公益视频合辑:学习顺序是linux,r,软件安装,geo,小技巧,ngs组学!
B站链接
YouTube链接
生信工程师入门最佳指南
学徒培养