跳转至

CellChat 细胞通讯 — 配体受体介导的细胞间通讯推断工具


一句话说明

CellChat v2 是 R 语言中最权威的细胞通讯分析工具,通过整合超过 1000 种配体-受体对数据库,从单细胞转录组数据推断细胞类型之间的信号通讯网络,并支持多样本比较和空间转录组分析。


安装与配置

# 安装 devtools(用于从 GitHub 安装)
if (!require("devtools", quietly = TRUE))
  install.packages("devtools")

# 安装 CellChat v2(注意:已迁移到 jinworks 账号)
devtools::install_github("jinworks/CellChat")

# 安装必要依赖
install.packages(c('BiocManager', 'NMF', 'ggalluvial', 'igraph', 'ggplot2'))
BiocManager::install(c("ComplexHeatmap", "BiocNeighbors"))

# 安装可选依赖(空间转录组分析)
install.packages(c('Seurat', 'SeuratData'))

# 验证安装
library(CellChat)
packageVersion("CellChat")    # 应显示 2.x.x

核心用法

library(CellChat)              # 加载 CellChat
library(ggplot2)               # 可视化
library(patchwork)             # 图片拼图

# ── 创建 CellChat 对象 ───────────────────────────────
# 从 Seurat 对象创建(最常用)
library(Seurat)
seurat_obj <- readRDS('annotated_seurat.rds')

# 提取数据(规范化后的表达矩阵)
data_input <- GetAssayData(
  seurat_obj,
  assay = "RNA",
  slot = "data"               # 使用标准化后的数据(不是原始counts)
)

# 提取细胞元数据(必须包含细胞类型列)
meta <- seurat_obj@meta.data   # 包含 cell_type 等信息

# 创建 CellChat 对象
cellchat <- createCellChat(
  object = data_input,         # 表达矩阵
  meta = meta,                 # 细胞元数据
  group.by = "cell_type"       # 按哪一列分组(细胞类型列名)
)

# ── 设置配体受体数据库 ────────────────────────────────
# CellChatDB:人类或小鼠的配体受体互作数据库
CellChatDB <- CellChatDB.human    # 使用人类数据库
# CellChatDB <- CellChatDB.mouse  # 小鼠数据库

# 选择数据库子集(加速分析)
CellChatDB.use <- subsetDB(
  CellChatDB,
  search = "Secreted Signaling"   # 只分析分泌信号(还有 ECM-Receptor 等)
)
cellchat@DB <- CellChatDB.use     # 将数据库注入对象

参数详解

参数函数说明
group.bycreateCellChat细胞分组列名(必须是元数据中的列)
threshfilterCommunication显著性阈值(通常 0.05)
min.cellssubsetData每个 cluster 最少细胞数
nbootcomputeCommunProb置换检验次数(越多越慢越准)
population.sizecomputeCommunProb是否考虑细胞群体大小
typenetAnalysis_signalingRole网络分析类型(functional/structural

实战案例

library(CellChat)
library(ggplot2)

# ── 完整 CellChat v2 分析流程 ─────────────────────────

# 1. 准备数据(从上面的 createCellChat 继续)
# 预处理:提取和过滤信号通路基因
cellchat <- subsetData(cellchat)               # 只保留数据库中的基因
future::plan("multisession", workers = 4)       # 设置 4 个并行 worker

# 2. 推断细胞通讯
cellchat <- identifyOverExpressedGenes(cellchat)    # 识别过表达基因
cellchat <- identifyOverExpressedInteractions(cellchat)  # 识别过表达互作

# 计算通讯概率(核心步骤,较耗时)
cellchat <- computeCommunProb(
  cellchat,
  type = "triMean",            # 表达量聚合方式(triMean 更稳健)
  population.size = TRUE       # 考虑细胞群体大小
)

# 过滤低置信度的通讯(每个 cluster 至少 10 个细胞)
cellchat <- filterCommunication(cellchat, min.cells = 10)

# 3. 计算信号通路水平的通讯概率
cellchat <- computeCommunProbPathway(cellchat)  # 汇总到通路级别

# 计算聚合通讯网络(计算总通讯数量和强度)
cellchat <- aggregateNet(cellchat)

# 4. 全局网络可视化
groupSize <- as.numeric(table(cellchat@idents))  # 各 cluster 细胞数

# 气泡图:显示所有通讯链接
par(mfrow = c(1,2), xpd=TRUE)                   # 并排显示两个图
netVisual_circle(
  cellchat@net$count,                           # 通讯数量
  vertex.weight = groupSize,                    # 节点大小代表细胞数量
  weight.scale = TRUE,
  label.edge = FALSE,
  title.name = "Number of interactions"
)
netVisual_circle(
  cellchat@net$weight,                          # 通讯强度
  vertex.weight = groupSize,
  weight.scale = TRUE,
  label.edge = FALSE,
  title.name = "Interaction weights"
)

# 5. 分析特定信号通路
# 查看所有显著信号通路
cellchat@netP$pathways

# 可视化 MHC-II 信号通路(示例)
pathways.show <- c("MHC-II")
netVisual_aggregate(
  cellchat,
  signaling = pathways.show,   # 指定信号通路
  layout = "circle"            # 圆形布局
)

# 弦图(Chord diagram)展示通讯
netVisual_chord_gene(
  cellchat,
  sources.use = 4,             # 发送信号的细胞类型编号
  targets.use = c(1,3),        # 接受信号的细胞类型编号
  lab.cex = 0.5,               # 标签字体大小
  legend.pos.y = 30
)

# 6. 气泡图:展示配体-受体对
netVisual_bubble(
  cellchat,
  sources.use = 4,             # 发送信号细胞
  targets.use = c(1,2,3,5),   # 接受信号细胞
  remove.isolate = FALSE
)

# 7. 计算中心性/信号角色
cellchat <- netAnalysis_computeCentrality(
  cellchat,
  slot.name = "netP"           # 使用信号通路级别的网络
)

# 可视化各类型在信号中的发出/接受角色
netAnalysis_signalingRole_scatter(cellchat)    # 散点图

# 8. 保存结果
saveRDS(cellchat, 'cellchat_result.rds')

# 后续加载
# cellchat <- readRDS('cellchat_result.rds')

常见报错与解决

报错原因解决方法
CellChatDB not found数据库未正确加载data("CellChatDB.human")
Error: group.by not in meta列名不匹配检查 colnames(meta)
结果全部 NAmin.cells 设置太高降低 min.cells 到 5
并行计算报错future 包版本问题options(future.globals.maxSize = 2000*1024^2)
安装时 compilation 失败缺少系统库conda install -c conda-forge r-base

速查表

# 完整流程(7步)
cellchat <- subsetData(cellchat)
cellchat <- identifyOverExpressedGenes(cellchat)
cellchat <- identifyOverExpressedInteractions(cellchat)
cellchat <- computeCommunProb(cellchat)
cellchat <- filterCommunication(cellchat, min.cells=10)
cellchat <- computeCommunProbPathway(cellchat)
cellchat <- aggregateNet(cellchat)

# 关键可视化
netVisual_circle(cellchat@net$count)                # 通讯网络圈图
netVisual_bubble(cellchat, sources.use=1)           # 配体受体气泡图
netAnalysis_signalingRole_scatter(cellchat)         # 信号角色散点图