/lucid-coder:pseudobulk-defrom lucid-coder
Pseudobulk differential expression for one cell type from a single-cell h5ad: sums raw counts per sample, filters samples and genes, runs DESeq2 (PyDESeq2 or R) or dreamlet (repeated measures, random effects) with a design formula and contrast, and writes tables, five fixed figures, a report and a reproducibility bundle. Fire on "pseudobulk DE", "pseudo-bulk differential expression", "DESeq2 per cell type", "DE between conditions in T cells", "sum counts per donor/sample and test", "paired by patient DE", "dreamlet", "repeated measures pseudobulk", "random effect for donor". Do NOT fire for cell-level DE (Wilcoxon or t-test between cells, marker genes, rank_genes_groups), bulk RNA-seq without cells (a genes x samples matrix already), or composition questions (cell-type proportions, differential abundance).
Ships in lucid-coder. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
You are the dispatcher for pseudobulk-de. The script does the analysis; you collect its arguments, run it, and explain its outputs.
Run scripts/pseudobulk_de.py. Never re-implement the analysis, change a
threshold, or pick a value the user has not given. If a required argument is
unknown, ask the user (these are grill questions), or run --demo only when the
user asks for a demo.
Then read result.json and relay chat_summary_lines and preferred_artifacts.
If the script prints ERROR: ... and exits 2, tell the user the message and the
argument it names. Do not work around it.
Environment: pixi feature bioc-de for the dreamlet and deseq2 engines (pixi install -e bioc-de, from templates/pixi.toml); on osx-arm64 also run pixi run -e bioc-de setup-r.
| Input | Format | Required content | Example |
|---|---|---|---|
--adata | .h5ad | raw counts (non-negative integers) in X, or in --layer | examples/demo.h5ad |
cell-level obs | columns | --cell-type-col, --sample-col, --donor-col, every --design term | cell_type, sample, patient, condition |
| design terms, donor | obs columns | constant within each sample (sample-level) | patient, condition |
| ids | obs_names | unique | cell0000 |
| gene ids | var_names (symbols), var --gene-id-col (Ensembl ids) | one id per symbol, no duplicate ids (skillkit.check_gene_ids, house-style data.ids); none writes gene_id as NA, never a guessed id | G000, gene_ids |
| contrast factor | obs column | a --design term holding both contrast levels | condition with stim, ctrl |
Code a categorical factor as strings in obs. A numeric column enters the
design as a continuous covariate in every engine: the python engine keeps its
numeric dtype (one design column), and the R engines read it as numeric. Only
the sample, donor and contrast columns and (1|x) terms are always strings.
Every other factor uses alphabetical reference levels (treatment coding); the
script does not choose them. The reference level per factor goes into the
report summary and result.json (reference_levels). Only additive designs
(~ a + b) are accepted, plus random intercepts (1|x) for dreamlet
(~ condition + (1|patient)). The contrast factor must be a fixed term.
Ask these through the analysis contract: ${CLAUDE_PLUGIN_ROOT}/skills/lucid-coder/references/contracts.md.
Each row is a grill question. Ask the user; never fill one in.
| Argument | Grill question | Demo-only value |
|---|---|---|
--adata | Which h5ad holds the cells? | examples/demo.h5ad |
--layer (optional) | Which layer holds the raw counts? Absent means X. | absent (X) |
--gene-id-col | Which var column holds the Ensembl gene ids (or none if the source has none)? | gene_ids |
--cell-type-col | Which obs column holds the cell-type labels? none when the input is already one population: all cells are tested, no subset. | cell_type |
--cell-type | Which cell type do we test? With --cell-type-col none, the label the report gives that population. | T |
--sample-col | Which obs column names the sample (one library per donor and condition)? | sample |
--donor-col | Which obs column names the donor? A donor with several kept samples needs a donor term in --design (fixed or `(1 | donor)`). |
--design | Which design formula? Does a subject give more than one sample (then `(1 | subject)`, dreamlet), and which covariates enter? (tut: the liana Kang tutorial omits the patient term for paired data.) |
--contrast | Which factor, numerator and denominator (factor,numerator,denominator)? | condition,stim,ctrl |
--min-cells | How many cells must a sample have in this cell type to be kept? (tut: 10 in 14 of 16 kai get_pseudobulk calls that set it. kai also drops samples under min_counts=1000 summed counts in 13 of 16 calls; this skill has no count floor, so ask whether a low-count sample should be dropped by hand before the run.) | 10 |
--min-frac | In what fraction of this cell type's cells must a gene be detected? | 0.1 |
--padj-max | Which adjusted-p cutoff marks a gene significant? | 0.05 |
--lfc-min | Which absolute log2 fold change must a significant gene exceed? | 1.0 |
--seed | Which seed? (Recorded; neither DESeq2 path draws random numbers.) | 0 |
--engine | PyDESeq2 (python), R DESeq2 (r) or dreamlet (dreamlet)? Omit only with a `(1 | x)` design, which selects dreamlet. |
--reference | Which genome build and annotation release were the counts made with (e.g. GRCh38, GENCODE 44)? Never guess it. | synthetic demo, no genome |
--context | Species, tissue or cell type, condition and dataset? Printed first in the report and summary. | synthetic demo: 7 patients, ctrl vs stim T cells, no real tissue |
--outdir | Which new directory gets the outputs? It must not exist. | pseudobulk_de_demo |
The last column is demo-only, not defaults. --demo alone pins all of them.
With --demo, only --engine and --outdir may also be given; any other
analysis argument is an error. --demo --engine dreamlet swaps the design to
~ condition + (1|patient).
ERROR: <message>, exit 2.--cell-type in --cell-type-col; skipped when --cell-type-col none.--sample-col value.--min-cells cells, recorded per contrast
level (dropped_by_level).check_design_rank), and a donor with several samples needs a
donor term (check_replication). Either failure stops the run.--min-frac of that cell
type's cells in the samples kept in step 4. A filtered gene is not tested.--design and --contrast. --engine python = PyDESeq2,
--engine r = DESeq2 via Rscript; both use independent filtering with
alpha = --padj-max and no LFC shrinkage. --engine dreamlet = dreamlet via
Rscript (processAssays, dreamlet, topTable(coef=, number=Inf)); it has
no independent filtering, so --padj-max acts only in step 8.padj < --padj-max and |log2FC| > --lfc-min.
A gene with padj NA (independent filtering, outlier) is not significant.de_results.tsv has one row per input gene, gene_id beside gene_symbol.
status (house-style data.status) is tested for the genes passing step 6,
which went to the engine; n_genes_tested counts them. A gene the engine could
not fit stays tested with NA statistics. A gene filtered by --min-frac keeps
NA statistics with not_detected (zero in every cell of the kept samples) or
not_tested; status_counts in result.json counts each. Plots use tested
genes only. Tables and results are sorted by padj, then gene, NA last.
pseudobulk_counts.tsv starts with gene_id and gene_symbol, the
--counts form variance-partition reads; the R engines get a symbol-keyed copy.
outdir/
├── report.md # params, summary, figures with captions
├── result.json # n_samples, n_donors, dropped_samples, dropped_by_level, context, reference, n_genes_tested, status_counts, gene_id_col, n_significant, top_genes, params, reference_levels, numeric_covariates, design_columns (python engine), engine, seed, chat_summary_lines, preferred_artifacts
├── tables/
│ ├── pseudobulk_counts.tsv # gene_id, gene_symbol, then kept samples: summed raw counts of tested genes
│ ├── sample_meta.tsv # one row per kept sample, design terms
│ └── de_results.tsv # gene_symbol, gene_id, base_mean, log2_fc, lfc_se, stat, pvalue, padj, status, significant
├── figures/
│ ├── sample_pca.pdf
│ ├── sample_pca.png
│ ├── sample_pca.csv
│ ├── pvalue_hist.pdf
│ ├── pvalue_hist.png
│ ├── pvalue_hist.csv
│ ├── ma.pdf
│ ├── ma.png
│ ├── ma.csv
│ ├── volcano.pdf
│ ├── volcano.png
│ ├── volcano.csv
│ ├── top_genes_heatmap.pdf
│ ├── top_genes_heatmap.png
│ └── top_genes_heatmap.csv
└── reproducibility/
├── commands.sh # argv as run, and the resolved command with every argument
├── environment.txt # Python and package versions; R and DESeq2 (r) or dreamlet, variancePartition, limma, edgeR, lme4 (dreamlet)
└── checksums.sha256 # tables and figure PDFs; sha256sum -c from outdir
--cell-type-col condition, or write a tagged copy of the h5ad) when the input holds one
population. Do not. Pass --cell-type-col none and name the population in
--cell-type.scanpy call) to "check" or extend a result. Do not. The script's tables are
the result; a second analysis has none of the fixed filters or provenance.condition alone on 8 patients measured before and after
stimulation; do not copy it (tut: 2 kai notebooks, saezlab/liana-py and its
copy).filter_by_expr
(or filter_genes) before the script, as decoupler's tutorials do. Do not.
The script filters by --min-frac, and DESeq2 filters again independently. A
third filter changes which genes are tested and goes unrecorded (tut: 14 of 16
kai DESeq2 notebooks stack two filters, and one stacks three).%%capture or quiet=True to tidy
a notebook. Do not; that hides convergence and Cook's warnings. Read
result.json and the log instead (tut: the liana Kang tutorial does both).--padj-max or --lfc-min after seeing few
significant genes. Do not. Thresholds are the user's answers, fixed before the
run; report the count as it is.rank_genes_groups)
because it is faster or gives more hits. Do not. Cells are not independent
replicates; the sample is the unit of inference.--demo only when the user asked for a demo.n_samples and n_genes_tested from result.json. In one
acumen run the agent counted detection over pseudobulk samples instead of
cells and answered 11/9299; the expected answer was 11/456.--engine python or r with (1|patient), or by turning the random
term into a fixed one to dodge the error. Do not. Repeated measures default to
dreamlet; a fixed patient term is the user's call, so ask.composition next before calling it
cell-intrinsic.status is not
tested. Do not. Non-detection is not absence: a gene below --min-frac was
filtered and is "not tested".claims.strength).--donor-col or the donor term to get past
the more than one sample error. Do not. Samples from one donor are not
independent; ask the user for a fixed or (1|donor) term.--reference from the gene names. Do not;
ask which genome build and annotation release made the counts.counts ... must be non-negative integers error. Do not. Point --layer at the
raw counts or ask the user where they are. A layer named normalised_counts
holds normalised values, not counts; DESeq2 and dreamlet need raw counts (tut:
1 of 30 kai get_pseudobulk notebooks sums one).When a subject contributes more than one sample (repeated measures), dreamlet is the default method. The script enforces this through the design:
(1|x) in --design selects --engine dreamlet when
--engine is omitted.--engine python or --engine r with a random-effect term fails:
--design has the random-effect term (1|x): repeated measures need --engine dreamlet, not --engine python.~ patient + condition) still needs an explicit --engine.dreamlet fits a precision-weighted linear mixed model per gene (voom weights,
variancePartition::dream); see Hoffman et al. (2023) and the vignette
https://diseaseneurogenomics.github.io/dreamlet/articles/dreamlet.html. A
user-level dreamlet skill, if installed (~/.claude/skills/dreamlet/SKILL.md),
documents the same calls and the ~ condition + (1|donor_id) form; this
plugin does not ship it.
How scripts/dreamlet.R runs it:
n_cells - 1 zero cells) and calls
aggregateToPseudoBulk. That sets the cell counts per sample
(int_colData(pb)$n_cells, read by cellCounts) and the metadata
processAssays reads, through the public API.processAssays runs
with min.cells = 0 (keep every sample), min.count = 0, min.prop = 0 and
min.total.count = 0 (filterByExpr keeps every gene), and
min.samples = 2 (never binds; step 4 already needs 2 samples per level).
edgeR still drops an all-zero gene; it stays in the table as an NA row.
dreamlet() gets no min.cells: dreamlet 1.8.0 accepts it but does not use it.<factor><numerator> (e.g. conditionstim).base_mean = AveExpr (mean log2 CPM, not a normalised count),
log2_fc = logFC, lfc_se = logFC / t, stat = t,
pvalue = P.Value, padj = adj.P.Val (BH).python scripts/pseudobulk_de.py \
--adata data/cells.h5ad --layer counts \
--cell-type-col cell_type --cell-type "CD14 Mono" --sample-col sample --donor-col patient \
--design "~ patient + condition" --contrast condition,stim,ctrl \
--min-cells 10 --min-frac 0.1 --padj-max 0.05 --lfc-min 1 \
--gene-id-col gene_ids --context "human PBMC, IFN-beta vs control, 8 donors" \
--seed 0 --engine python --reference "GRCh38, GENCODE 44" --outdir results/2026-10-27_mono-de
# Repeated measures: (1|patient) selects dreamlet
python scripts/pseudobulk_de.py ... --design "~ condition + (1|patient)" ...
# Demo (only when the user asks for one)
python scripts/pseudobulk_de.py --demo --outdir demo_out
Not arguments: the script sets these, and reproducibility/environment.txt
records the package versions. A change is a maintainer edit, not a user choice.
--engine python) and DESeq2 1.50.2 (--engine r) run with
package defaults: Wald test, median-of-ratios size factors, fitted dispersion
trend, Cook's-distance outlier handling, independent filtering with
alpha = --padj-max, no LFC shrinkage. PyDESeq2 runs with n_cpus=1.processAssays filter is switched off (min.cells = 0,
min.count = 0, min.prop = 0, min.total.count = 0, min.samples = 2)
because --min-cells and --min-frac already filtered; then dreamlet and
topTable(number = Inf) (BH).Corpus sources, ClawBio mechanisms, tests, citations and the plot spec are in references/maintainer.md. The agent running the script does not need them.
card.yaml (opens in a new tab)examples/demo.h5ad (opens in a new tab)examples/make_demo.py (opens in a new tab)references/maintainer.md (opens in a new tab)scripts/deseq2.R (opens in a new tab)scripts/dreamlet.R (opens in a new tab)scripts/palettes.py (opens in a new tab)scripts/plots.py (opens in a new tab)scripts/pseudobulk_de.py (opens in a new tab)scripts/skillkit.py (opens in a new tab)scripts/theme.py (opens in a new tab)tests/test_pseudobulk_de.py (opens in a new tab)variants/dreamlet.yaml (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub mdmanurung/lucid-coder --plugin lucid-coder27 skills in this plugin
/alignInstall the lucid-coder house-style configs into this repository, one file at a time, after showing each diff and asking. Use when the user says "align this repo", "install the house style configs", "set up air/ruff/lintr", or "add the palette file"./cccLigand-receptor cell-cell communication between cell types from a log-normalised single-cell h5ad with LIANA+ rank_aggregate (CellPhoneDB, Connectome, log2FC, NATMI, SingleCellSignalR, or a subset), a bundled or exported ligand-receptor resource TSV, a fixed pass rule on magnitude and specificity ranks, a source x target count heatmap, an LR dot plot, a report and a reproducibility bundle. Optional per-sample runs. Fire on "cell-cell communication", "ligand-receptor analysis", "which cell types talk to which", "LIANA", "CellPhoneDB", "rank_aggregate", "CCC between clusters". Do NOT fire for spatial CCC (bivariate, MISTy), for factorising CCC across many samples (Tensor-Cell2cell, MOFAtalk), for DE-driven CCC between conditions, for non-human data without a translated resource, or for raw counts./compositionCell-type composition and differential abundance with crumblr: counts cells per sample and label (from a cell-level h5ad or a counts TSV), drops rare labels, runs crumblr's precision-weighted CLR and variancePartition dream (fixed and random effects, e.g. (1|donor)), and writes tables, a stacked composition bar, per-label proportion boxes, an effect forest, a report and a reproducibility bundle. Fire on "cell-type composition", "differential abundance of cell types", "do cell-type proportions change", "crumblr", "CLR of cell frequencies", "which populations expand after stimulation". Do NOT fire for neighbourhood-level DA on a KNN graph (Milo), gene expression DE (pseudobulk or cell-level), scCODA / Bayesian composition models, or a plain Wilcoxon on frequencies (group-tests)./enrichmentGene-set enrichment on one or more DE tables (contrasts or cell types): preranked fgsea in R, or over-representation (one-sided Fisher / hypergeometric) of the significant genes against a stated universe, BH within each contrast, with an NES dot plot, an NES heatmap, running enrichment-score curves, a report and a reproducibility bundle. Fire on "GSEA on the DE results", "fgsea Hallmark per cell type", "pathway enrichment of the DE genes", "over-representation analysis", "ORA with a background", "which pathways are up in stim", "NES dotplot". Do NOT fire for scoring a gene set per cell or sample (signature scoring), for TF or pathway activity inference (decoupler ULM/MLM, PROGENy), for enrichment that needs the dreamlet fit object (zenith), or when there is no DE table yet (run pseudobulk-de first)./figure-styleHouse figure style for scientific plots in R (ggplot2, ComplexHeatmap) and Python (plotnine, plotnine-extra): use it for ANY figure drawn from experimental, omics or single-cell data, including plot types not listed here (box, violin, slopegraph, forest, volcano, heatmap, dot plot, UMAP, PCA, composition bars, QC, survival curves, enrichment, spatial maps). Takes precedence over generic charting or dashboard skills for these figures. Do NOT fire for web dashboards, slide graphics or UI charts./gene-programsGene-program discovery by consensus NMF (cNMF-style) on raw single-cell counts: HVG selection, repeated seeded sklearn NMF, a local-density filter and k-means consensus of the replicate components, per-cell program usage, gene scores, top genes, mean usage, fraction of active cells and one-vs-rest AUC per group, a stability table, four fixed figures, a report and a reproducibility bundle. Fire on "gene programs", "cNMF", "consensus NMF", "gene expression programs", "GEP usage", "NMF programs per cell type", "which programs mark each cluster", "structure plot of program usage". Do NOT fire for scoring a known gene set (score_genes, UCell), for projecting onto a fixed reference (starCAT, NMFproj), for choosing k by a sweep, for marker genes per cluster (use sc-markers), or for log-normalised input.