所有信息可以查看github
教程有很多虽界,最基本的是Inference and analysis of cell-cell communication using CellChat
如果有分組,想做比較分析可以看這個Comparison analysis of multiple datasets using CellChat
輸入
首先需要你已經(jīng)做好了細胞分群臭家,得到了seurat object妹萨。這時谚攒,需要創(chuàng)建一個CellChat對象。
# Part I: Data input & processing and initialization of CellChat object
data.input = seuratObject[["RNA"]]@data # normalized data matrix
meta = dat.sub@meta.data # 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")
image.png
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])
}
image.png
heatmap
可以選擇展示某個pathway,可也有不選signaling參數(shù)晒旅,展示所有的pathway。
pathways.show <- c("CXCL")
par(mfrow=c(1,1))
netVisual_heatmap(cellchat, signaling = pathways.show, color.heatmap = "Reds")
image.png
數(shù)據(jù)之間做比較
這時候需要分別跑兩個組的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)
然后就可以繪制各種圖啦
相互作用數(shù)量和強度統(tǒng)計柱狀圖
gg1 <- compareInteractions(cellchat, show.legend = F, group = c(1,2))
gg2 <- compareInteractions(cellchat, show.legend = F, group = c(1,2), measure = "weight")
gg1 + gg2
相互作用數(shù)量和強度的差異網(wǎng)絡圖
par(mfrow = c(1,2), xpd=TRUE)
netVisual_diffInteraction(cellchat, weight.scale = T)
netVisual_diffInteraction(cellchat, weight.scale = T, measure = "weight")
image.png
相互作用數(shù)量、強度的差異熱圖扒寄,這個圖文章中用的比較多鱼鼓,也比較直觀
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
image.png
分別畫兩個數(shù)據(jù)集的相互作用強度
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]))
}
image.png
數(shù)據(jù)結構
待補充
總結
cellchat對象中可以獲得ligand-receptor對兒的很多信息,要好好掌握數(shù)據(jù)結構该编,靈活應用迄本。