// CellChat cell-cell communication analysis toolkit - complete documentation with precise file name-based categorization
| name | cellchat-pkg-local-fixed |
| description | CellChat cell-cell communication analysis toolkit - complete documentation with precise file name-based categorization |
Comprehensive assistance with CellChat development and cell-cell communication analysis, generated from official documentation.
This skill should be triggered when:
Pattern 1: Basic CellChat Setup
library(CellChat)
library(patchwork)
options(stringsAsFactors = FALSE)
Pattern 2: Create CellChat from Data Matrix
# Load normalized data matrix and metadata
data.input = data_humanSkin$data # normalized data matrix
meta = data_humanSkin$meta # dataframe with cell metadata
# Create CellChat object
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")
Pattern 3: Create from Seurat Object
# Extract normalized data from Seurat
data.input <- seurat_object[["RNA"]]@data # or seurat_object[["RNA"]]$data for v5+
labels <- Idents(seurat_object)
meta <- data.frame(group = labels, row.names = names(labels))
# Create CellChat object
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")
Pattern 4: Create from SingleCellExperiment
# Extract data from SCE
data.input <- SingleCellExperiment::logcounts(object)
meta <- as.data.frame(SingleCellExperiment::colData(object))
meta$labels <- meta[["sce.clusters"]]
# Create CellChat object
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")
Pattern 5: Create from AnnData (Python)
library(anndata)
ad <- read_h5ad("scanpy_object.h5ad")
counts <- t(as.matrix(ad$X))
# Normalize if needed
library.size <- Matrix::colSums(counts)
data.input <- as(log1p(Matrix::t(Matrix::t(counts)/library.size) * 10000), "dgCMatrix")
meta <- ad$obs
meta$labels <- meta[["ad_clusters"]]
Pattern 6: Set Up Database and Preprocess
# Load CellChat database
CellChatDB <- CellChatDB.human
cellchat@DB <- CellChatDB
# Subset expression data to signaling genes
cellchat <- subsetData(cellchat)
# Normalize data if using raw counts
cellchat <- normalizeData(cellchat)
Pattern 7: Infer Cell-Cell Communication
# Compute communication probability
cellchat <- computeCommunProb(cellchat)
# Compute pathway-level communication
cellchat <- computeCommunProbPathway(cellchat)
# Filter significant communications
cellchat <- filterCommunication(cellchat, min.cells = 10)
Pattern 8: Aggregate Network for Visualization
# Calculate aggregated network
cellchat <- aggregateNet(cellchat)
# Extract interaction matrix
net <- cellchat@net$count # number of interactions
weight <- cellchat@net$weight # interaction weights
Pattern 9: Compare Multiple Datasets
# Load multiple CellChat objects
object.list <- list(E13 = cellchat.E13, E14 = cellchat.E14)
# Merge objects
cellchat <- mergeCellChat(object.list, add.names = names(object.list), cell.prefix = TRUE)
# Compare interaction strength
netVisual_diffInteraction(object.list, slot.name = "netP")
Pattern 10: Lift Cell Groups for Comparison
# Define unified cell labels
group.new = levels(cellchat.E14@idents)
cellchat.E13 <- liftCellChat(cellchat.E13, group.new)
# Merge lifted objects
object.list <- list(E13 = cellchat.E13, E14 = cellchat.E14)
cellchat <- mergeCellChat(object.list, add.names = names(object.list))
Pattern 11: Circle Plot for Signaling Pathways
# Circle plot of specific pathway
pathways.show <- c("WNT")
weight.max <- getMaxWeight(object.list, slot.name = "netP", attribute = pathways.show)
par(mfrow = c(1,2), xpd=TRUE)
for (i in 1:length(object.list)) {
netVisual_aggregate(object.list[[i]], signaling = pathways.show,
layout = "circle", edge.weight.max = weight.max[1],
edge.width.max = 10, signaling.name = paste(pathways.show, names(object.list)[i]))
}
Pattern 12: Hierarchy Plot
# Hierarchy plot with specific receiver cells
vertex.receiver = seq(1,10) # Left portion for dermal cells
par(mfrow = c(1,2), xpd=TRUE)
for (i in 1:length(object.list)) {
netVisual_aggregate(object.list[[i]], signaling = pathways.show,
vertex.receiver = vertex.receiver, edge.weight.max = weight.max[1])
}
Pattern 13: Chord Diagram
# Group cells for chord diagram
group.merged <- c(rep("Dermal", 10), rep("Epidermal", 3))
names(group.merged) <- levels(object.list[[1]]@idents)
# Create chord diagram
for (i in 1:length(object.list)) {
netVisual_chord_cell(object.list[[i]], signaling = pathways.show,
group = group.merged, title.name = paste0(pathways.show, " signaling - ", names(object.list)[i]))
}
Pattern 14: Identify Communication Patterns
# Select optimal number of patterns
selectK(cellchat, slot.name = "netP", pattern = "outgoing", k.range = seq(2, 10))
# Identify patterns
cellchat <- identifyCommunicationPatterns(cellchat, slot.name = "netP",
pattern = c("outgoing", "incoming"), k = 4)
Pattern 15: Compute Centrality Measures
# Compute centrality for signaling networks
cellchat <- computeCentrality(cellchat, slot.name = "netP")
# Access centrality measures
centrality_outgoing <- cellchat@netP$centrality_outgoing
centrality_incoming <- cellchat@netP$centrality_incoming
Pattern 16: Data Smoothing for Shallow Sequencing
# Smooth data to reduce dropout effects
cellchat <- smoothData(cellchat, method = "netSmooth", alpha = 0.5)
# Use smoothed data for communication inference
cellchat <- computeCommunProb(cellchat, raw.use = FALSE)
This skill includes comprehensive documentation organized by topic:
getting_started.md for basic CellChat setupdata_preprocessing.md and tool_integration.mdvisualization_tools.mdcomparison_analysis.mdadvanced_methods.md and network_analysis.mdtool_integration.mddatabase_management.mdspatial_functions.mdcpp_source_code.md insightsmathematical_functions.mdcomputeCommunProbAll code examples in this skill are:
To refresh this skill with updated documentation: