高分生信文章最受欢迎的免疫浸润分析算法-CIBERSORT

今天小果带来的分享内容是利用CIBERSORT算法进行免疫浸润分析,因为该算法是在生信文章中引用次数最多的免疫浸润分析的算法,所以小果今天想通过实例数据来进行演示,有需要的小伙伴可以跟着小果一起开始今天的分享学习。
1.CIBERSORT算法介绍
小果来为小伙伴们简单介绍一下CIBERSORT算法,CIBERSORT利用线性支持向量回归的原理对免疫细胞亚型的表达矩阵进行去卷积,来估计免疫细胞的丰度。CIBERSORT提供了22种常见的免疫浸润细胞表达数据LM22,包括不同的细胞类型和功能状态的免疫细胞,这就是小果对该算法的介绍,小伙伴们有没有理解呀!利用CIBERSORT算法进行免疫分析,需要在官网下载22种常见的免疫浸润细胞表达数据LM22文件,以及准备基因表达矩阵文件就可以进行免疫浸润分析,非常简单,很适合小白学习,接下来跟着小果开始今天的实操吧!
公众号后台回复“111”领取代码,代码编号:231007
2.准备需要的R包
#安装需要的R包install.packages("ggplot2")install.packages("reshape2")install.packages("ggpubr")install.packages("dplyr")install.packages("ggsci")BiocManager::install("RcolorBrewer")#加载需要的R包library(ggplot2)library(reshape2)library(ggpubr)library(dplyr)library(RcolorBrewer)source('Cibersort.R')
3.读取文件
#LM22.txt,22种免疫细胞表达量文件,第一列为Gene symbol,其他列为22种免疫细胞。
LM22.file <- "LM22.txt"

#combined.expr.txt,表达矩阵文件,行名为基因名,列名为样本信息。GEO_exp.file <- "combined.expr.txt"

4.CIBERSORT算法进行免疫浸润分析
GEO_cibersort.results <- CIBERSORT(LM22.file ,GEO_exp.file, perm = 50, QN = T)write.table(GEO_cibersort.results, "GEO_CIBERSORT.txt")

cibersort_data <- as.data.frame(GEO_cibersort.results[,1:22])cibersort_data<-rownames_to_column(cibersort_data,var="Sample")Group<-read.table(“group.txt”,header=T,sep=”t”)

cibersort<-left_join(cibersort_data,Group,by="Sample")cibersort<- melt(cibersort,id.vars=c("Sample","group"))colnames(cibersort)<-c("Sample","Group","celltype","composition")boxplot_cibersort<- ggplot(cibersort, aes(x = celltype, y = composition))+labs(y="Cell composition",x= "")+geom_boxplot(aes(fill = Group),position=position_dodge(0.5),width=0.5)+scale_fill_npg()+theme_bw() +theme(axis.title = element_text(size = 12,color ="black"),axis.text = element_text(size= 12,color = "black"),panel.grid.minor.y = element_blank(),panel.grid.minor.x = element_blank(),axis.text.x = element_text(angle = 45, hjust = 1 ),panel.grid=element_blank(),legend.position = "top",legend.text = element_text(size= 12),legend.title= element_text(size= 12)) +stat_compare_means(aes(group = Group),label = "p.signif",method = "wilcox.test",hide.ns = T)ggsave(file="cibersort.pdf",boxplot_cibersort,height=10,width=15)


5.绘制免疫细胞含量柱状图
#长宽数据转换cibersort_plot<-melt(cibersort_data,id.vars=”Sample”)#修改列名colnames(cibersort_plot)<-c("Sample",""celltype","composition")#绘制免疫细胞含量堆叠柱状图##自定义颜色设置colour = c(brewer.pal(12, "Paired"),brewer.pal(8, "Dark2"),brewer.pal(12, "Set3"))ggplot(data=cibersort_plot,aes(x=Sample,y=composition,fill=celltype))+geom_bar(position="stack",stat="identity")+ #绘制柱状图scale_fill_manual(values = colour)+ #添加自定义颜色labs(x="",y="",title="cell proportion")+ #设置坐标轴scale_y_continuous(expand=c(0,0))+ #设置与y轴的间距为0guides(fill = guide_legend(ncol = 1))+ #设置图例排列成一列#修改主题theme_bw()+theme(legend.key = element_blank(),legend.title = element_blank(),panel.grid=element_blank(),axis.text.x=element_blank(),axis.ticks.x=element_blank(),plot.title=element_text(hjust=0.5))#保存图片ggsave("cibersort_barplot.pdf",width=8,height=8)

最终小果成功的利用CIBERSORT算法进行了免疫浸润分析,绘制了免疫细胞丰度堆叠柱状图和分组差异分析箱线图,看起来图片效果非常不错,欢迎大家和小果一起讨论学习呀!今天小果的分享就到这里,下期在见奥。


往期推荐