sc-de
Differential expression for single-cell RNA-seq using exploratory Scanpy ranking, R-backed MAST, or replicate-aware pseudobulk DESeq2. The wrapper separates cluster/group marker ranking from sample-aw
SKILL.mdSkills/singlecell/scrna/sc-de/SKILL.md
GitHubSingle-Cell Differential Expression
Why This Exists
- Without it: users mix exploratory marker tests with replicate-aware inference and misread the results.
- With it: the wrapper makes the statistical path explicit and preserves the public DE contract.
- Why OmicsClaw: one interface covers quick Scanpy ranking and the heavier pseudobulk route.
Core Capabilities
- Five DE paths: Wilcoxon, t-test, logistic regression, MAST, and DESeq2 pseudobulk.
- Separation of statistical questions: exploratory single-cell ranking versus replicate-aware pseudobulk inference.
- Matrix-aware contract: normalized expression for ranking paths, raw counts for DESeq2 pseudobulk.
- Direct DE figure exports: marker dotplot and rank-gene summary where supported.
- Downstream-ready export: processed AnnData, DE tables, report, structured result JSON, README, and notebook artifacts.
Scope Boundary
Implemented methods:
wilcoxont-testlogregmastfor R-backed hurdle-model DEdeseq2_rfor pseudobulk DE
Input Formats
| Format | Extension / form | Current wrapper support | Notes |
|---|---|---|---|
| AnnData | .h5ad |
yes | current direct input path |
| Demo | --demo |
yes | bundled fallback |
Input Expectations
- Accepted input: processed
.h5ad wilcoxon,t-test,logreg, andmastexpectX = normalized_expressiondeseq2_rexpects raw counts, preferably inlayers["counts"], otherwise aligned raw counts inadata.raw, otherwise count-likeadata.X- All methods require a grouping column in
obs - If you want cluster markers, this skill usually comes after
sc-clustering - If you want replicate-aware treated-vs-control DE, this skill usually comes after
sc-cell-annotationor another step that definescelltype_key
Workflow
- Load the AnnData object and inspect the matrix contract.
- Preflight the statistical question: exploratory ranking vs replicate-aware condition DE.
- Validate matrix state and required metadata for the requested method.
- Run Scanpy ranking, MAST, or pseudobulk DESeq2.
- Export tables, figures,
figure_data, andprocessed.h5ad. - Record method metadata for downstream traceability.
CLI Reference
python skills/singlecell/scrna/sc-de/sc_de.py \
--input <processed.h5ad> --groupby leiden --method wilcoxon --output <dir>
python skills/singlecell/scrna/sc-de/sc_de.py \
--input <processed.h5ad> --groupby condition \
--group1 treated --group2 control --method t-test --output <dir>
python skills/singlecell/scrna/sc-de/sc_de.py \
--input <processed.h5ad> --groupby leiden --method logreg \
--logreg-solver saga --output <dir>
python skills/singlecell/scrna/sc-de/sc_de.py \
--input <processed.h5ad> --method deseq2_r \
--groupby condition --group1 treated --group2 control \
--sample-key sample_id --celltype-key cell_type \
--pseudobulk-min-cells 10 --pseudobulk-min-counts 1000 --output <dir>
Public Parameters
| Parameter | Role | Notes |
|---|---|---|
--method |
DE backend | wilcoxon, t-test, logreg, mast, or deseq2_r |
--groupby |
grouping column | core comparison axis |
--group1 / --group2 |
comparison levels | especially important for mast and deseq2_r |
--n-top-genes |
compact export size | ranking-output control |
--logreg-solver |
logistic-regression optimizer | logreg only |
--sample-key |
replicate/sample column | required by deseq2_r |
--celltype-key |
pseudobulk aggregation label | used by deseq2_r |
--pseudobulk-min-cells |
minimum cells per pseudobulk bin | deseq2_r only |
--pseudobulk-min-counts |
minimum counts per pseudobulk bin | deseq2_r only |
--padj-threshold / --log2fc-threshold |
figure summary thresholds | mostly affects exported volcano/summary figures |
Algorithm / Methodology
Exploratory ranking paths
Current OmicsClaw exploratory DE includes:
wilcoxont-testlogregmast
These paths answer the cluster-marker or group-ranking question on normalized expression from adata.X.
Replicate-aware pseudobulk path
Current OmicsClaw deseq2_r:
- expects raw counts, ideally from
layers["counts"] - aggregates counts to pseudobulk using
sample_keyandcelltype_key - runs DESeq2 through the shared R bridge
Important implementation note:
deseq2_ris the only path here that is explicitly replicate-aware in the current wrapper.
Output Contract
Successful runs write:
processed.h5adreport.mdresult.jsontables/de_full.csvtables/markers_top.csvfigure_data/manifest.jsonreproducibility/commands.sh
Visualization Contract
The current wrapper writes direct figure outputs rather than a recipe-driven gallery:
- exploratory methods:
figures/marker_dotplot.pngfigures/rank_genes_groups.pngfigures/de_effect_summary.pngfigures/de_group_summary.png
- pseudobulk paths:
figures/pseudobulk_group_summary.png- per-celltype
*_volcano.png - per-celltype
*_ma.png
What Users Should Inspect First
report.mdtables/de_full.csvtables/markers_top.csvfigures/de_group_summary.pngor pseudobulk summary figuresprocessed.h5ad
Current Limitations
mastrequires an R environment withMAST,SingleCellExperiment, andzellkonverter.deseq2_rrequires an R environment withDESeq2,SingleCellExperiment, andzellkonverter.- This skill writes
README.mdand notebook-style reproducibility artifacts when notebook export dependencies are available.
Safety And Guardrails
- Distinguish exploratory marker-style DE from replicate-aware pseudobulk inference before running.
- If the user only has a base-preprocessed object and wants cluster markers, point them to
sc-clusteringfirst. - If the user wants treated-vs-control inference without replicates, warn that exploratory DE is not replicate-aware.
mastanddeseq2_rare real public methods but require their R stacks up front in the current wrapper.- Treat
sample_keyandcelltype_keyas part of the statistical design fordeseq2_r, not as cosmetic metadata. - For short execution guardrails, see
knowledge_base/knowhows/KH-sc-de-guardrails.md. - For longer method and interpretation guidance, see
knowledge_base/skill-guides/singlecell/sc-de.md.
CLI Parameters
| Flag | Type | Default | Description | Validation |
|---|---|---|---|---|
--input |
str | — | Input .h5ad file |
required unless --demo |
--output |
str | — | Output directory | required |
--demo |
flag | off | Run with bundled PBMC3k data | — |
--groupby |
str | leiden |
Group/condition column in obs |
must exist in obs |
--method |
str | wilcoxon |
DE backend: wilcoxon, t-test, logreg, mast, deseq2_r |
validated against METHOD_REGISTRY |
--n-top-genes |
int | 10 | Number of top genes to export per group | min 1 |
--logreg-solver |
str | lbfgs |
Logistic-regression optimizer | choices: lbfgs, liblinear, newton-cg, sag, saga |
--group1 |
str | None | Comparison group (vs --group2) |
— |
--group2 |
str | None | Reference group (vs --group1) |
— |
--sample-key |
str | None | Sample/replicate column for pseudobulk | used by deseq2_r |
--celltype-key |
str | cell_type |
Cell type column for pseudobulk aggregation | used by deseq2_r |
--pseudobulk-min-cells |
int | 10 | Minimum cells per pseudobulk bin | non-negative |
--pseudobulk-min-counts |
int | 1000 | Minimum total counts per pseudobulk bin | non-negative |
--padj-threshold |
float | 0.05 | Adjusted p-value cutoff for summary figures | 0.0–1.0 |
--log2fc-threshold |
float | 1.0 | log2FC cutoff for volcano/summary figures | non-negative |
--r-enhanced |
flag | off | Also render R Enhanced ggplot2 figures | — |
R Enhanced Plots
Activated by --r-enhanced. Files written to figures/r_enhanced/.
| Renderer | Output file | figure_data CSV | Plot description | Required R packages |
|---|---|---|---|---|
plot_de_volcano |
r_de_volcano.png |
de_top_markers.csv |
Volcano plot with up/down/NS coloring and gene labels | ggplot2, ggrepel |
plot_de_heatmap |
r_de_heatmap.png |
de_top_markers.csv |
Expression heatmap of top DE genes across groups | ggplot2, ComplexHeatmap |
plot_feature_violin |
r_feature_violin.png |
feature_expression.csv |
Violin plots of top DE gene expression per group | ggplot2 |
plot_feature_cor |
r_feature_cor.png |
feature_correlation.csv |
Gene-gene expression correlation scatter | ggplot2 |
plot_de_manhattan |
r_de_manhattan.png |
de_top_markers.csv |
Manhattan-style plot of DE significance by gene rank | ggplot2 |
Workflow Position
Upstream: sc-clustering, sc-cell-annotation, or sc-markers Downstream: sc-enrichment (pathway enrichment on DE results)