#预处理用于细胞通信分析的表达数据
cellchat <- subsetData(cellchat)
#future::plan("multiprocess", workers = 4) #可以不运行
cellchat <- identifyOverExpressedGenes(cellchat)#分析差异基因
cellchat <- identifyOverExpressedInteractions(cellchat)#
cellchat <- projectData(cellchat, )
#进行细胞通信网络的推断
cellchat <- computeCommunProb(cellchat, raw.use = TRUE)#计算通信概率并推断cellchat网络
cellchat <- filterCommunication(cellchat, = 10)#过滤
#信号通路级别推断细胞-细胞通信
cellchat <- computeCommunProbPathway(cellchat)
#计算整合的细胞通信网络
cellchat <- aggregateNet(cellchat)
#进行可视化
groupSize <- as.numeric(table(cellchat@idents))
par(mfrow = c(1,2), xpd=TRUE)
netVisual_circle(cellchat@net$count, = groupSize,
= T, = F, = "Number of interactions")
netVisual_circle(cellchat@net$weight, = groupSize,
= T, = F, = "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, = groupSize, = T, = max(mat), = rownames(mat)[i])
}
dev.off()
#细胞通信网络的可视化######################################
<- c("CXCL")
= seq(1,4) # a numeric vector.
netVisual_aggregate(cellchat, signaling = ,
= )
# Circle plot
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = ,
layout = "circle")
# 弦图
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = , layout = "chord")
#热图
par(mfrow=c(1,1))
netVisual_heatmap(cellchat, signaling = , = "Reds")
# Chord diagram
group.cellType <- c(rep("FIB", 4), rep("DC", 4), rep("TC", 4)) # grouping cell clusters into fibroblast, DC and TC cells
names(group.cellType) <- levels(cellchat@idents)
netVisual_chord_cell(cellchat, signaling = ,group = group.cellType,
= paste0(, " signaling network"))
#计算每个配体受体对整体信号通路的贡献,并可视化由单个配体受体对调节的细胞通信
netAnalysis_contribution(cellchat, signaling = )
#视化由单个配体受体对调节的细胞-细胞通信
<- extractEnrichedLR(cellchat, signaling = , geneLR.return = FALSE)
<- [1,] # show one ligand-receptor pair
= seq(1,4) # # Hierarchy plot a numeric vector
netVisual_individual(cellchat, signaling = ,
pairLR.use = , = )
# Circle plot
netVisual_individual(cellchat, signaling = ,
pairLR.use = , layout = "circle")
#相关保存
.all <- cellchat@netP$pathways
# check the order of cell identity to set suitable
levels(cellchat@idents)
= seq(1,4)
for (i in 1:length(.all)) {
# Visualize communication network associated with both signaling pathway and individual L-R pairs
netVisual(cellchat, signaling = .all[i], = , layout = "hierarchy")
# Compute and visualize the contribution of each ligand-receptor pair to the overall signaling pathway
gg <- netAnalysis_contribution(cellchat, signaling = .all[i])
ggsave(filename=paste0(.all[i], "_L-R_contribution.pdf"), plot=gg, width = 3, height = 2, units = 'in', dpi = 300)
}
#可视化由多个配体受体或信号通路调节的细胞通信
netVisual_bubble(cellchat, sources.use = 4, targets.use = c(5:11),
= FALSE)
netVisual_bubble(cellchat, sources.use = 4, targets.use = c(5:11),
signaling = c("CCL","CXCL"), = FALSE)
netVisual_chord_gene(cellchat, sources.use = 4, targets.use = c(5:11),
= 0.5, = 30)
# show all the interactions received by
netVisual_chord_gene(cellchat, sources.use = c(1,2,3,4),
targets.use = 8, = 15)
#使用小提琴/点图绘制信号基因表达分布
plotGeneExpression(cellchat, signaling = "CXCL")
plotGeneExpression(cellchat, signaling = "CXCL",
= FALSE)#提取与推断的L-R对或信号通路相关的信号基因
#细胞通信网络系统分析############################
cellchat <- netAnalysis_computeCentrality(cellchat, = "netP") # the slot 'netP' means the inferred intercellular communication network of signaling pathways
netAnalysis_signalingRole_network(cellchat, signaling = ,
width = 8, height = 2.5, font.size = 10)
#使用散点图在 2D 空间中可视化占主导地位的发射器(源)和接收器(目标)
gg1 <- netAnalysis_signalingRole_scatter(cellchat)
gg2 <- netAnalysis_signalingRole_scatter(cellchat, signaling = c("CXCL", "CCL"))
gg1 + gg2
#哪些信号对某些细胞组的传出或传入信号贡献最大
ht1 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "outgoing")
ht2 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "incoming")
ht1 + ht2
ht <- netAnalysis_signalingRole_heatmap(cellchat, signaling = c("CXCL", "CCL"))
#识别和可视化分泌细胞的传出通信模式##############################
selectK(cellchat, pattern = "outgoing")#selectK推断模式的数量。
#当传出模式数为 3 时,Cophenetic 和Silhouette值都开始突然下降。
nPatterns = 3
cellchat <- identifyCommunicationPatterns(cellchat,
pattern = "outgoing", k = nPatterns)
netAnalysis_dot(cellchat, pattern = "outgoing")#绘制点图
selectK(cellchat, pattern = "incoming")#识别和可视化目标细胞的传入通信模式
nPatterns = 4
cellchat <- identifyCommunicationPatterns(cellchat, pattern = "incoming", k = nPatterns)
# river plot桑基图
library(ggalluvial)
netAnalysis_river(cellchat, pattern = "incoming")
# dot plot
netAnalysis_dot(cellchat, pattern = "outgoing")
#信号网络的流形和分类学习分析
cellchat <- computeNetSimilarity(cellchat, type = "functional")
cellchat <- netEmbedding(cellchat, type = "functional")
#> Manifold learning of the signaling networks for a single dataset
cellchat <- netClustering(cellchat, type = "functional")
#> Classification learning of the signaling networks for a single dataset
# Visualization in 2D-space
netVisual_embedding(cellchat, type = "functional", label.size = 3.5)
#最后保存
saveRDS(cellchat, file = "cellchat_humanSkin_LS.rds")