最初接触这个R包是去年年中,想做细胞间相互作用,又不会python,正好看到周老师的推文,就跟着学了学,CellChat:细胞间相互作用分析利器,当时CellChat包还是0.0.1版本,里面有不少小bug,文章放在预印版上,而今年二月份他终于见刊,发表在NC,现在R包也来到了1.1.2版本,并且在github上持续更新,今天我们来重新学习一次。
网址:https://github.com/sqjin/CellChat
首先是安装
devtools::install_github("sqjin/CellChat")
可能会出现安装失败的情况,需满足:NMF包 (>= 0.23.0)、circlize包 (>= 0.4.12)、安装ComplexHeatmap以及UMAP python。
install.packages('NMF')
devtools::install_github("jokergoo/circlize")
devtools::install_github("jokergoo/ComplexHeatmap")
#pip install umap-learn
官网有教程,建议直接打包下载到本地,tutorial挨个看吧。
加载包
library(CellChat)
library(patchwork)
options(stringsAsFactors = FALSE)##印象中新版R已经不需要这行代码了
Part 1:数据输入及预处理
load(url("https://ndownloader.figshare.com/files/25950872")) # 官方提供了一个单细胞数据集,包括对照组和疾病组
data.input = data_humanSkin$data # 均一化矩阵
meta = data_humanSkin$meta # meta data 行名为细胞名
table(meta$condition) ## 5011 LS 2552 NL
cell.use = rownames(meta)[meta$condition == "LS"] # 提取正常组织
data.input = data.input[, cell.use]
meta = meta[cell.use, ]
unique(meta$labels)####这里的labels就是已经标记好的细胞类型,后续所谓的胞间分析都是在这些标签上进行的
看一下meta的结构
CellChat的输入需要的matrix和meta我们已经准备好,下面开始创建
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")
cellchat <- addMeta(cellchat, meta = meta)##增加其他meta信息
cellchat <- setIdent(cellchat, ident.use = "labels") # 将 "labels" 设为默认细胞标记类型,这个可以根据自己的数据自定义
levels(cellchat@idents)
groupSize <- as.numeric(table(cellchat@idents)) # 每组细胞的数量
下面看一下基于配受体分析的数据库
CellChatDB <- CellChatDB.human # 包括人和老鼠的,这里我们用human
showDatabaseCategory(CellChatDB)###作者提供了可视化的代码,可以看到该数据库中“Secreted Signaling”占比过半
dplyr::glimpse(CellChatDB$interaction) ###看一下CellChatDB的基本结构
CellChatDB_interaction <- CellChatDB$interaction
CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling") # 我们这里使用“Secreted Signaling”部分做后续的细胞通讯分析
cellchat@DB <- CellChatDB.use
对表达数据做进一步预处理,节省算力
cellchat <- subsetData(cellchat)
cellchat <- identifyOverExpressedGenes(cellchat)###首先识别过表达基因(配体——受体)
cellchat <- identifyOverExpressedInteractions(cellchat)###然后识别过表达配受体之间过表达的相互作用 (绕绕绕绕绕....)
# project gene expression data onto PPI network (optional)
cellchat <- projectData(cellchat, PPI.human)
Part 2:胞间通讯网络的预测及构建
计算胞间通讯概率,预测通讯网络
cellchat <- computeCommunProb(cellchat)###这应该是核心的一行代码
cellchat <- filterCommunication(cellchat, min.cells = 10)##过滤掉小于10个细胞的胞间通讯网络
作者还贴心的提供了胞间通讯网络的输出代码
df.net <- subsetCommunication(cellchat) ###自己输出一把,很好理解
df.net <- subsetCommunication(cellchat, sources.use = c(1,2), targets.use = c(4,5))##配体细胞1群2群,受体细胞4群5群
df.net <- subsetCommunication(cellchat, signaling = c("WNT", "TGFb"))##WNT及TGFb相关网络
在信号通路的水平进一步推测胞间通讯,计算聚合网络
cellchat <- computeCommunProbPathway(cellchat)
cellchat <- aggregateNet(cellchat)
这样我们就能可视化细胞互作的结果了
groupSize <- as.numeric(table(cellchat@idents))
par(mfrow = c(1,2), xpd=TRUE)
netVisual_circle(cellchat@net$count, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Number of interactions")
netVisual_circle(cellchat@net$weight, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = "Interaction weights/strength")
分别代表相互作用的数量及权重
下面展示每个细胞亚群发出的信号,
mat <- cellchat@net$weight
par(mfrow = c(3,4), xpd=TRUE)
for (i in 1:nrow(mat)) {
mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat))
mat2[i, ] <- mat[i, ]
netVisual_circle(mat2, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(mat)[i])###通過edge.weight.max参数比较不同网络的边缘权重
}
Part 3:胞间通讯网络的进一步可视化
CellChat提供为胞间通讯后续的数据探索、分析及可视化提供了多样功能
1.多种可视化方法:层次图、圆图、弦图、气泡图
2.更容易提取和可视化通讯网络的高阶信息。例如,它允许随时预测细胞群的主要信号输入和输出,以及这些种群和信号如何为功能协调。
3.它将社会网络分析、模式识别和多种学习方法相结合,采用一种综合的方法对推断的细胞-细胞通信网络进行定量表征和比较。
未完待续.....