CIBERSORT | 免疫浸润分析R包

该文详细介绍了如何使用R包CIBERSORT进行免疫细胞浸润分析,包括安装CIBERSORT库,准备TPM标准化后的表达矩阵数据,运行CIBERSORT算法以及通过箱线图、热图和柱状图对结果进行可视化。此外,还提供了数据预处理和结果解读的注意事项。
该文章已生成可运行项目,

1. 安装

library(devtools)
devtools::install_github("Moonerss/CIBERSORT")
library(CIBERSORT)
library(ggplot2)
library(dplyr)
library(ggthemes)
library(pheatmap)
library(tibble)
library(tidyr)
library(ggpubr)
library(ggsci)
library(ggthemes)

2. 数据准备

需要两个数据:LM22和你需要分析的表达矩阵,我的是bulkRNA的表达矩阵,tpm标准化后的

#读取LM22文件(免疫细胞特征基因文件)
sig_matrix <- system.file("extdata", "LM22.txt", package = "CIBERSORT")
#表达矩阵文件
exp <- read.table(file="tpm_exp.txt",row.names = 1)

3. 运行

res <- cibersort(sig_matrix, tpm_exp, perm = 1000, QN = F)
#QN如果是芯片设置为T,如果是测序就设置为F
write.table(res, "res.txt", 
            sep = "\t", row.names = T, col.names = T, quote = F)

4. 可视化

#1.H和D组箱线图
res1 <- data.frame(res[,1:22])%>%
  mutate(group = c(rep('H',3),rep('D',3)))%>%
  rownames_to_column("sample")%>%
  pivot_longer(cols = colnames(.)[2:23],
               names_to = "cell.type",
               values_to = 'value')

ggplot(res1,aes(cell.type,value,fill = group)) + 
  geom_boxplot(outlier.shape = 21,color = "black") + 
  theme_bw() + 
  labs(x = "Cell Type", y = "Estimated Proportion") +
  theme(legend.position = "top") + 
  theme(axis.text.x = element_text(angle=80,vjust = 0.5,size = 14,face = "italic",colour = 'black'),
        axis.text.y = element_text(face = "italic",size = 14,colour = 'black'))+
  scale_fill_nejm()+
  stat_compare_means(aes(group = group),label = "p.format",size=3,method = "kruskal.test")

#2.热图
#展示所有的免疫细胞
normalize <- function(x) {
  if((max(x) - min(x)) == 0){
    return(mean(x))
  }else{
    return((x - min(x)) / (max(x) - min(x)))
  }
}
res1 <- res[,-(23:25)]
res2 <- apply(res1, 2,normalize)
res2 <- t(as.data.frame(res2))
pheatmap(res2,
         angle_col = "45",
         show_colnames = T,
         cluster_cols = F,
         color = colorRampPalette(c("navy", "white", "firebrick3"))(50))

#展示在一半以上样本里丰度大于0的免疫细胞
k <- apply(res1,2,function(x) {sum(x == 0) < nrow(exp)/2})
table(k)
#FALSE  TRUE 
#11    11 
res3 <- as.data.frame(t(res1[,k]))
pheatmap(res3,scale = "row",
         angle_col = "45",
         show_colnames = T,
         cluster_cols = F,
         color = colorRampPalette(c("navy", "white", "firebrick3"))(50))

#3.柱状图
res4 <- exp %>%
  as.data.frame() %>%
  rownames_to_column("sample") %>%
  pivot_longer(cols = 2:23,
               names_to = "CellType",
               values_to = "Composition")
ggbarplot(
  res4,
  x = "sample",
  y = "Composition",
  size = 0.5,
  fill = "CellType",
  color = "CellType") +
  theme_base() +
  theme(axis.text.x = element_text(
      angle = 45,
      hjust = 1,
      vjust = 1,
      size = 20),
    legend.position = "bottom",
    legend.key.size = unit(10,"pt")
  )

参考:量化免疫浸润时CIBERSORT的注意事项。 · Issue #694 · gege-circle/home · GitHub

肿瘤免疫浸润分析:CIBERSORT包(超简单的使用方法) - 知乎 (zhihu.com)

CIBERSORT 学习笔记_菠萝西斯的博客-优快云博客

CIBERSORT 免疫浸润(2023.1.2更新版) - 简书 (jianshu.com)

本文章已经生成可运行项目
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值