所有信息可以查看github
教程有很多,最基本的是Inference and analysis of cell-cell communication using CellChat
如果有分组,想做比较分析可以看这个Comparison analysis of multiple datasets using CellChat
输入
首先需要你已经做好了细胞分群,得到了seurat object。这时,需要创建一个CellChat对象。
# Part I: Data input & processing and initialization of CellChat object
data.input = seuratObject[["RNA"]]@data # normalized data matrix
meta = [email protected] # a dataframe with rownames containing cell mata data
meta$labels <- meta$celltype # celltype interaction analysis
cellchat <- CellChat::createCellChat(object = data.input, meta = meta, group.by = "labels")
cellchat <- setIdent(cellchat, ident.use = "labels") # set "labels" as default cell identity
分析
groupSize <- as.numeric(table(cellchat@idents)) # number of cells in each cell group
# use CellChatDB.mouse if running on mouse data
# simply use the default CellChatDB
# set the used database in the object
cellchat@DB <- CellChatDB.mouse
# subset the expression data of signaling genes for saving computation cost
cellchat <- subsetData(cellchat) # This step is necessary even if using the whole database
future::plan("multiprocess", workers = 4) # do parallel
cellchat <- identifyOverExpressedGenes(cellchat)
cellchat <- identifyOverExpressedInteractions(cellchat)
# project gene expression data onto PPI network (optional)
cellchat <- projectData(cellchat, PPI.human)
# Part2: Inference of cell-cell conmmunication network
cellchat <- computeCommunProb(cellchat)
# Filter out the cell-cell communication if there are only few number of cells in certain cell groups
cellchat <- filterCommunication(cellchat, min.cells = 10)
cellchat <- computeCommunProbPathway(cellchat)
cellchat <- aggregateNet(cellchat)
可视化
aggregated cell-cell communication network
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])
}
heatmap
可以选择展示某个pathway,可也有不选signaling参数,展示所有的pathway。
pathways.show <- c("CXCL")
par(mfrow=c(1,1))
netVisual_heatmap(cellchat, signaling = pathways.show, color.heatmap = "Reds")
数据之间做比较
这时候需要分别跑两个组的CellChat分析,然后进行对比分析。
dir.create("Comparison")
cellchat.Control <- readRDS("Control.cellchat.result.ImmuneCell.rds")
cellchat.Treatment <- readRDS("Treatment.cellchat.result.ImmuneCell.rds")
object.list <- list(Control= cellchat.Control, MC = cellchat.Treatment)
cellchat <- mergeCellChat(object.list, add.names = names(object.list),cell.prefix = TRUE)
# define a positive dataset, i.e., the dataset with positive fold change against the other dataset
pos.dataset = "Treatment"
# define a char name used for storing the results of differential expression analysis
features.name = pos.dataset
# perform differential expression analysis
cellchat <- identifyOverExpressedGenes(cellchat, group.dataset = "datasets", pos.dataset = pos.dataset, features.name = features.name, only.pos = TRUE)
#> Use the joint cell labels from the merged CellChat object
# map the results of differential expression analysis onto the inferred cell-cell communications to easily manage/subset the ligand-receptor pairs of interest
net <- netMappingDEG(cellchat, features.name = features.name)
然后就可以绘制各种图啦
相互作用数量和强度统计柱状图
gg1 <- compareInteractions(cellchat, show.legend = F, group = c(1,2))
gg2 <- compareInteractions(cellchat, show.legend = F, group = c(1,2), measure = "weight")
gg1 + gg2
相互作用数量和强度的差异网络图
par(mfrow = c(1,2), xpd=TRUE)
netVisual_diffInteraction(cellchat, weight.scale = T)
netVisual_diffInteraction(cellchat, weight.scale = T, measure = "weight")
相互作用数量、强度的差异热图,这个图文章中用的比较多,也比较直观
gg1 <- netVisual_heatmap(cellchat)
#> Do heatmap based on a merged object
gg2 <- netVisual_heatmap(cellchat, measure = "weight")
#> Do heatmap based on a merged object
gg1 + gg2
分别画两个数据集的相互作用强度
weight.max <- getMaxWeight(object.list, attribute = c("idents","count"))
par(mfrow = c(1,2), xpd=TRUE)
for (i in 1:length(object.list)) {
netVisual_circle(object.list[[i]]@net$count, weight.scale = T, label.edge= F, edge.weight.max = weight.max[2], edge.width.max = 12, title.name = paste0("Number of interactions - ", names(object.list)[I]))
}
数据结构
待补充
总结
cellchat对象中可以获得ligand-receptor对儿的很多信息,要好好掌握数据结构,灵活应用。