SKILL.md
Version Compatibility
Reference examples tested with: R stats (base), edgeR 4.0+, ggplot2 3.5+, limma 3.58+
Before using code patterns, verify installed versions match. If versions differ:
- R:
packageVersion('<pkg>')then?function_nameto verify parameters
If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
Differential Analysis
"Compare cell populations between my conditions" → Test for significant changes in cell type frequencies (differential abundance) or marker expression levels (differential state) between experimental groups.
- R:
CATALYST::testDA_edgeR()ordiffcyt::testDA_GLMM()
Differential Abundance (DA)
Goal: Test which cell population clusters differ in frequency between experimental conditions.
Approach: Create a design matrix and contrast from sample metadata, then run edgeR-based differential abundance testing on cluster counts per sample using testDA_edgeR from the diffcyt framework.
library(CATALYST)
library(diffcyt)
# Load clustered data
sce <- readRDS('sce_clustered.rds')
# Create design matrix
design <- createDesignMatrix(ei(sce), cols_design = 'condition')
# Create contrast
contrast <- createContrast(c(0, 1)) # Treatment vs Control
# Differential abundance test
res_DA <- testDA_edgeR(sce, design, contrast, cluster_id = 'meta20')
# View results
rowData(res_DA)$cluster_id
rowData(res_DA)$p_adj
# Significant clusters
sig_DA <- rowData(res_DA)$p_adj < 0.05
table(sig_DA)
Differential State (DS)
# Test for marker expression differences within clusters
res_DS <- testDS_limma(sce, design, contrast,
cluster_id = 'meta20',
markers_include = rownames(sce)[rowData(sce)$marker_class == 'state'])
# Results per marker per cluster
ds_results <- rowData(res_DS)
