Agent skill

cellchat-pkg-local-complete

CellChat 包源码随附的本地教程 + Rd 转换的函数文档 + R 源码 HTML - 完整覆盖173个文件

Stars 0
Forks 0

Install this agent skill to your Project

npx add-skill https://github.com/Ketomihine/my_skills/tree/main/cellchat-pkg-local-complete

SKILL.md

CellChat-Pkg-Local-Complete Skill

Comprehensive assistance with CellChat package for cell-cell communication analysis, generated from official documentation and source code.

When to Use This Skill

This skill should be triggered when:

Data Preparation & Object Creation:

  • Converting single-cell data from Seurat, SingleCellExperiment, or AnnData objects to CellChat
  • Preparing normalized expression matrices and cell metadata for CellChat analysis
  • Setting up CellChat objects from different data formats (count matrices, spatial data)
  • Handling data input issues from Python/Scanpy or other single-cell tools

Cell-Cell Communication Analysis:

  • Inferring ligand-receptor interactions and signaling pathways
  • Computing communication probabilities and network analysis
  • Analyzing spatially resolved cell-cell communication
  • Performing comparative analysis across conditions or time points

Network Analysis & Visualization:

  • Visualizing communication networks using hierarchy, circle, or chord diagrams
  • Computing network centrality measures to identify key signaling players
  • Creating spatial plots of communication on tissue sections
  • Extracting and filtering specific communications of interest

Advanced Applications:

  • Integrating custom ligand-receptor databases
  • Analyzing contact-dependent signaling
  • Projecting expression data onto protein-protein interaction networks
  • Batch correction and multi-sample analysis

Troubleshooting & Optimization:

  • Debugging issues with object creation or data conversion
  • Optimizing parameters for communication inference
  • Handling spatial transcriptomics data from different platforms
  • Understanding and customizing analysis workflows

Quick Reference

Core Examples

Example 1: Create CellChat object from Seurat

r
library(CellChat)
cellchat <- createCellChat(object = seurat.obj, group.by = "ident", assay = "RNA")

Example 2: Create from expression matrix

r
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")

Example 3: Set up database and preprocess

r
cellchat@DB <- CellChatDB.human
cellchat <- subsetData(cellchat)
cellchat <- identifyOverExpressedGenes(cellchat)
cellchat <- identifyOverExpressedInteractions(cellchat)

Example 4: Infer communication network

r
cellchat <- computeCommunProb(cellchat)
cellchat <- computeCommunProbPathway(cellchat)
cellchat <- aggregateNet(cellchat)

Example 5: Extract communications

r
# All communications
df.net <- subsetCommunication(cellchat)

# Specific pathways
df.net <- subsetCommunication(cellchat, signaling = c("WNT", "TGFb"))

# Specific cell groups
df.net <- subsetCommunication(cellchat, sources.use = c(1,2), targets.use = c(4,5))

Example 6: Visualize signaling network

r
netVisual(cellchat, signaling = "TGFb", layout = "hierarchy")

Example 7: Network centrality analysis

r
cellchat <- netAnalysis_computeCentrality(cellchat, slot.name = "netP")
netAnalysis_signalingRole_network(cellchat, signaling = "TGFb")

Example 8: Spatial data setup

r
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels",
                          coordinates = coordinates, spatial.factors = spatial.factors)

Example 9: Data conversion from AnnData

r
library(anndata)
ad <- read_h5ad("scanpy_object.h5ad")
counts <- t(as.matrix(ad$X))
library.size <- Matrix::colSums(counts)
data.input <- as(log1p(Matrix::t(Matrix::t(counts)/library.size) * 10000), "dgCMatrix")
meta <- ad$obs

Example 10: Rank signaling pathways

r
rankNet(cellchat, mode = "single", measure = "weight")

Key Concepts

Core CellChat Objects:

  • cellchat@data: Normalized expression data
  • cellchat@meta: Cell metadata and group information
  • cellchat@net: Ligand-receptor level communication network
  • cellchat@netP: Pathway level communication network
  • cellchat@idents: Cell group identities

Data Requirements:

  • Expression Matrix: Genes in rows, cells in columns, normalized data required
  • Cell Metadata: Dataframe with cell labels and sample information
  • Spatial Data: Coordinates and distance factors for spatial analysis

Communication Inference:

  • Probability Calculation: Based on mass action law integrating expression and prior knowledge
  • Permutation Testing: Statistical significance assessment
  • Pathway Aggregation: Summarizing multiple L-R pairs per signaling pathway

Network Analysis Types:

  • Functional Networks: Based on inferred communication probabilities
  • Structural Networks: Based on ligand-receptor interaction structure
  • Centrality Measures: Identifying key senders, receivers, mediators, influencers

Reference Files

This skill includes comprehensive documentation in references/:

api_functions.md (134 pages)

Complete API documentation for all CellChat functions:

  • subsetCommunication: Extract specific cell-cell communications
  • computeAveExpr: Calculate average expression per cell group
  • netVisual_embedding: 2D visualization of signaling manifolds
  • rankNet: Rank signaling networks by information flow
  • netAnalysis_computeCentrality: Network centrality analysis
  • computeExpr_antagonist: Model antagonist effects

cpp_source.md (2 pages)

C++ source code for performance-critical operations:

  • ComputeSNN: Shared nearest neighbor computation
  • Rcpp bindings for high-performance calculations

r_source.md (10 pages)

R source code for core functionality:

  • visualization: Network visualization functions and themes
  • Color palettes and plotting utilities
  • Core analysis algorithms

tutorials.md (27 pages)

Comprehensive tutorials covering:

  • Spatial transcriptomics analysis: Complete workflow for spatial data
  • Data preparation: From various single-cell formats
  • Network inference: Step-by-step communication analysis
  • Visualization: Multiple plotting options and customization
  • Advanced applications: Custom databases and comparative analysis

Working with This Skill

For Beginners

  1. Start with Data Preparation: Use the tutorials to understand data input requirements
  2. Basic Workflow: Follow the spatial transcriptomics tutorial for a complete example
  3. Simple Visualizations: Begin with circle plots and hierarchy diagrams
  4. Reference Functions: Use api_functions.md for detailed parameter explanations

For Intermediate Users

  1. Custom Analyses: Explore different type parameters in computeAveExpr
  2. Advanced Visualizations: Try chord diagrams and spatial plots
  3. Network Analysis: Use centrality measures to identify key regulators
  4. Multi-sample Analysis: Learn comparative analysis across conditions

For Advanced Users

  1. Custom Databases: Update CellChatDB with domain-specific interactions
  2. Spatial Applications: Adapt parameters for different spatial technologies
  3. Performance Optimization: Use C++ functions for large datasets
  4. Integration Workflows: Combine with other single-cell analysis tools

Navigation Tips

  • Function Lookup: Search api_functions.md for specific function names
  • Parameter Details: Each function entry includes complete parameter descriptions
  • Code Examples: All tutorials include reproducible R code
  • Troubleshooting: Check the tutorials section for common issues and solutions

Resources

references/

Organized documentation extracted from official sources:

  • Detailed explanations of all parameters and return values
  • Code examples with proper language annotations
  • Links to original documentation for deeper exploration
  • Table of contents for quick navigation

scripts/

Add helper scripts here for common automation tasks:

  • Data conversion utilities
  • Custom visualization functions
  • Batch processing workflows

assets/

Store templates and examples:

  • Example datasets in proper format
  • Custom ligand-receptor databases
  • Configuration files for different analysis types

Common Workflows

Basic CellChat Analysis

r
# 1. Create object
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")

# 2. Set database and preprocess
cellchat@DB <- CellChatDB.human
cellchat <- subsetData(cellchat)
cellchat <- normalizeData(cellchat)

# 3. Identify over-expressed genes/interactions
cellchat <- identifyOverExpressedGenes(cellchat)
cellchat <- identifyOverExpressedInteractions(cellchat)

# 4. Infer communication
cellchat <- computeCommunProb(cellchat)
cellchat <- computeCommunProbPathway(cellchat)
cellchat <- aggregateNet(cellchat)

# 5. Visualize
netVisual(cellchat, signaling = "TGFb")

Spatial Transcriptomics Analysis

r
# 1. Create with spatial information
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels",
                          coordinates = coordinates, spatial.factors = spatial.factors)

# 2. Spatial communication inference
cellchat <- computeCommunProb(cellchat, contact.dependent = FALSE,
                             interaction.range = 250, scale.distance = 1)

# 3. Spatial visualization
netVisual_spatial(cellchat, signaling = "WNT")

Comparative Analysis

r
# 1. Create separate objects for each condition
cellchat1 <- createCellChat(object = data.input1, meta = meta1, group.by = "labels")
cellchat2 <- createCellChat(object = data.input2, meta = meta2, group.by = "labels")

# 2. Process each object
# ... (preprocessing steps for each)

# 3. Merge for comparison
cellchat <- mergeCellChat(cellchat1, cellchat2, add.names = c("LS", "NL"))

# 4. Compare signaling
rankNet(cellchat, mode = "comparison", comparison = c(1, 2))

Notes

  • Coverage: This skill covers 173 files including tutorials, API docs, and source code
  • Languages: Primarily R with some C++ components
  • Data Types: Supports scRNA-seq, spatial transcriptomics, and bulk data
  • Integration: Works with Seurat, SingleCellExperiment, AnnData objects
  • Documentation: Preserves original structure and examples from official sources

Updating

To refresh this skill with updated documentation:

  1. Restart the local CellChat documentation server
  2. Re-run the documentation scraper with the same configuration
  3. The skill will be rebuilt with the latest information and examples

Didn't find tool you were looking for?

Be as detailed as possible for better results