|
library(devtools)
devtools::install_github(“jokergoo/circlize”) devtools::install_github(“jokergoo/ComplexHeatmap”) install.packages(‘NMF’)a devtools::install_github(“jinworks/CellChat”) BiocManager::install(“BiocNeighbors”) devtools::install_github(“immunogenomics/presto”) library(“CellChat”) seu_mix_rename <- RenameIdents(object = mix_seu, `0` = “PrE1”, `1` = “Epi1”, `2` = “Epi2”, `3` = “PrE2”, `4` = “TS1”, `5` = “TS2”, `6` = “Misc1”, `7` = “Misc2”) sub_seu <- subset(x = seu_mix_rename, idents=c(“Misc1”, “Misc2”), invert=TRUE) cellchat <- createCellChat(object = sub_seu, group.by = “ident”, assay = “RNA”) CellChatDB <- CellChatDB.mouse showDatabaseCategory(CellChatDB) cellchat_mix <- identifyOverExpressedGenes(cellchat_mix) cellchat_mix <- identifyOverExpressedInteractions(cellchat_mix) cellchat_mix <- projectData(cellchat_mix, PPI.mouse) cellchat_mix <- computeCommunProb(cellchat_mix, raw.use = TRUE) # Filter out the cell-cell communication if there are only few number of cells in certain cell groups cellchat_mix <- filterCommunication(cellchat_mix, min.cells = 10) cellchat_mix <- computeCommunProbPathway(cellchat_mix) cellchat_mix <- aggregateNet(cellchat_mix) groupSize <- as.numeric(table(cellchat_mix@idents)) par(mfrow = c(1,2), xpd=TRUE) netVisual_circle(cellchat_mix@net$count, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = “Number of interactions”) netVisual_circle(cellchat_mix@net$weight, vertex.weight = groupSize, weight.scale = T, label.edge= F, title.name = “Interaction weights/strength”) mat <- cellchat_mix@net$weight 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])} # Access all the signaling pathways showing significant communications pathways.show.all <- cellchat_mix@netP$pathways # check the order of cell identity to set suitable vertex.receiver levels(cellchat_mix@idents) vertex.receiver = seq(1,3) for (i in 1:length(pathways.show.all)) { # Visualize communication network associated with both signaling pathway and individual L-R pairs netVisual(cellchat_mix, signaling = pathways.show.all[i], vertex.receiver = vertex.receiver, layout = “hierarchy”) # Compute and visualize the contribution of each ligand-receptor pair to the overall signaling pathway gg <- netAnalysis_contribution(cellchat_mix, signaling = pathways.show.all[i]) ggsave(filename=paste0(pathways.show.all[i], “_L-R_contribution.pdf”), plot=gg, width = 3, height = 2, units = ‘in’, dpi = 300) } # Compute the network centrality scores cellchat_mix <- netAnalysis_computeCentrality(cellchat_mix, slot.name = “netP”) # the slot ‘netP’ means the inferred intercellular communication network of signaling pathways # Visualize the computed centrality scores using heatmap, allowing ready identification of major signaling roles of cell groups netAnalysis_signalingRole_network(cellchat_mix, signaling = pathways.show, width = 8, height = 2.5, font.size = 10) # infer the number of patterns. selectK(cellchat_mix, pattern =“outgoing”) nPatterns = 6 # Both Cophenetic and Silhouette values begin to drop suddenly when the number of outgoing patterns is 3. cellchat_mix <- identifyCommunicationPatterns(cellchat_mix, pattern =“outgoing”, k = nPatterns) # river plot netAnalysis_river(cellchat_mix, pattern =“outgoing”) # dot plot netAnalysis_dot(cellchat_mix, pattern =“outgoing”) selectK(cellchat_mix, pattern = “incoming”) nPatterns = 6 cellchat_mix <- identifyCommunicationPatterns(cellchat_mix, pattern = “incoming”, k = nPatterns) # river plot netAnalysis_river(cellchat_mix, pattern = “incoming”) # dot plot netAnalysis_dot(cellchat_mix, pattern = “incoming”) |