/lucid-coder:sc-defrom lucid-coder
Per-feature differential expression in two modes: a MAST hurdle model on the log-normalised cells of one cell type (seeded per-donor downsampling, optional cellular detection rate covariate, optional (1|donor) random effect), or a per-feature linear model with covariates on sample-level values such as Olink NPX. Writes one sorted DE table, a volcano and a top-feature figure, a report and a reproducibility bundle. Fire on "MAST DE", "single-cell DE with MAST", "zlm hurdle model", "cell-level DE with CDR", "Olink NPX lm with covariates", "linear model per protein adjusted for age and sex". Do NOT fire for pseudobulk DE from raw counts (use pseudobulk-de), marker genes per cluster (use sc-markers), covariate-free two-group tests or correlations (use group-tests), or composition questions.
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 sc-de. The script does the analysis; you collect its arguments, run it, and explain its outputs.
Run scripts/sc_de.py. Never re-implement the model, 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.
In mast mode, state the unit of inference: the p-values treat cells as
replicates, so they overstate the evidence when donors are the replication unit.
Point the user to pseudobulk-de for a donor-level test. If the script prints
ERROR: ... and exits 2, tell the user the message and the argument it names.
Do not work around it.
Fire this skill when the user says any of:
Do NOT fire when: the data are raw counts to sum per sample (pseudobulk-de);
the user wants cluster markers (sc-markers); the test has no covariates
(group-tests); the question is about cell-type proportions.
Environment: pixi feature bioc-de for the mast engine (pixi install -e bioc-de, from templates/pixi.toml).
| Input | Format | Required content | Example |
|---|---|---|---|
--adata (mast) | .h5ad | log-normalised expression (normalize_total + log1p, or log2) in X or --layer; non-negative, not all integers | examples/demo.h5ad |
--gene-id-col (mast) | var column | Ensembl gene ids (versioned as the source gives them); var_names are the symbols | gene_ids; none when the source has no ids |
cell obs (mast) | columns | --cell-type-col, --donor-col, every --formula column | cell_type, donor, condition |
--input (lm) | TSV, long | columns sample, feature, value (numeric) and every --formula column | examples/demo_npx.tsv |
Raw counts and scaled (negative) data are refused. A categorical column must
hold non-numeric labels; a numeric column enters as a continuous covariate.
In lm mode a row with a missing value is dropped and counted; one row per
(feature, sample). Mast: each symbol must map to one gene id
(skillkit.check_gene_ids, house-style data.ids), checked before anything
else; --gene-id-col none writes gene_id as NA, never a guessed id. Lm
features are proteins or assays named by the input, so lm takes no gene ids.
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 (mast / lm) |
|---|---|---|
--mode | Cells with MAST (mast) or samples with a linear model (lm)? | mast / lm |
--formula | Which right-hand side, e.g. ~ condition or ~ status + age + sex? A (1|donor) term (mast) fits a glmer random effect: correct for donors but slow (minutes per hundred genes). | ~ condition / ~ status + age + sex |
--contrast-term (mast), --term (lm) | Which term do we test: column,level,reference for a factor, or a numeric column? | condition,stim,ctrl / status,disease,healthy |
--padj-max | Which BH-adjusted p cutoff marks a feature significant? | 0.05 |
--lfc-min | Which absolute effect (log2FC, or NPX for lm) must a significant feature exceed? | 0.5 |
--seed | Which seed fixes downsampling and plot jitter? | 0 |
--context | Species, tissue or cell type, condition and dataset? Printed first in the report and summary. | synthetic demo: 6 donors, ctrl vs stim T cells, no real tissue / synthetic demo: 40 samples, disease vs healthy NPX, no real cohort |
--reference | Which genome build and annotation release name the features, e.g. GRCh38, GENCODE 44 (or the Olink panel version)? Recorded in result.json; never guessed. | synthetic demo, no genome |
--adata (mast) | Which h5ad holds the cells? | examples/demo.h5ad |
--gene-id-col (mast) | Which var column holds the Ensembl gene ids (or none if the source has none)? | gene_ids |
--layer (mast, optional) | Which layer holds the log-normalised values? Absent means X. | absent |
--log-base (mast) | Is the expression natural log (e, scanpy log1p) or 2? | e |
--cell-type-col, --cell-type (mast) | Which obs column and which cell type? | cell_type, T |
--donor-col (mast) | Which obs column names the donor? | donor |
--n-cells-per-donor (mast) | Downsample to how many cells per donor (per term level), or all? (tut: 15 kai notebooks sample a data frame with no seed, and 58 call np.random.choice with no seed; this script always seeds with --seed.) | 50 |
--min-frac (mast) | In what fraction of the kept cells must a gene be detected? (tut: kai's MAST tutorials drop only all-zero genes; the fraction is yours.) | 0.1 |
--cdr (mast) | Add the cellular detection rate (cngeneson) as a covariate, yes or no? (tut: kai's only MAST tutorials, 3 notebooks in one repo, include it: ~treatment + ngeneson.) | yes |
--input, (lm) | Which long TSV holds the values? | examples/demo_npx.tsv |
--outdir | Which new directory gets the outputs? It must not exist. | given by the user |
Reference levels: every non-tested factor in --formula uses R's alphabetical
levels (the first level is the reference); the script does not choose them. The
tested factor's reference is the --contrast-term / --term reference. The
level chosen for each factor goes into the report summary and result.json
(reference_levels), so a covariate coefficient is never read against a level
nobody named.
The last column is demo-only, not defaults. --demo alone pins the mast
values; --demo --mode lm pins the lm values. Beside --demo only --mode and
--outdir may be given.
--mode decides which arguments it needs; an extra
one is an error. The term column must appear in --formula.--cell-type and refuse raw counts or negative
values; divide by ln 2 when --log-base e, so every logFC is log2.--donor-col value (and per term level when the
term is a factor), keep --n-cells-per-donor cells drawn with
numpy.random.default_rng(--seed); groups at or below the size keep all.--cdr yes): cngeneson = genes detected per kept cell over
all genes, centred and scaled; + cngeneson is appended to the formula.--min-frac
of the kept cells.zlm (bayesglm with empirical Bayes; or
method = "glmer", ebayes = FALSE when the formula has |), then
lrTest(fit, CoefficientHypothesis(term)): stat and p are the hurdle
(discrete + continuous) likelihood-ratio test, log2_fc and se come from
getLogFC. Lm: lm(value ~ formula) per feature; estimate, se, t and p of
the term coefficient. A factor term is relevelled so the reference is the
given one. An unestimable term gives NA. Before the fit, cell ids must be
unique and each gene symbol must map to one gene id (mast), and skillkit.check_design_rank runs on the
fixed-effect columns of the fitted rows (the formula without (1|x), plus
cngeneson); an aliased design stops the run.padj < --padj-max and |effect| > --lfc-min.
Sort by padj, then feature, NA last.Lm mode runs in R lm, not Python statsmodels: R builds the design matrix
from the formula (factor contrasts, relevel) exactly as the corpus did, R is
already needed for MAST, and lm is a deterministic QR fit with no new Python
dependency.
de_results.tsv has one row per input feature: mast gene_symbol, gene_id, log2_fc, se, stat, pvalue, padj, significant, status; lm
feature, estimate, se, stat, pvalue, padj, significant, status. Sorted by padj,
then feature, NA last. status (house-style data.status) is tested for a
feature with a p-value; an untested feature keeps NA statistics and says why:
not_detected (mast: zero in every kept cell), not_tested (mast: under
--min-frac; lm: every row dropped or the term not estimable).
outdir/
├── report.md # params, summary, figures with captions
├── result.json # mode, formula_fitted, n_cells + n_donors (mast) or n_samples (lm), dropped_by_level (lm rows lost to a missing value, per term level), context, reference, n_features, n_tested, status_counts, gene_id_col (mast), n_significant, significant_features, reference_levels, params, seed, chat_summary_lines, preferred_artifacts
├── tables/
│ └── de_results.tsv
├── figures/
│ ├── volcano.pdf
│ ├── volcano.png
│ ├── volcano.csv
│ ├── top_feature.pdf
│ ├── top_feature.png
│ └── top_feature.csv
└── reproducibility/
├── commands.sh # argv as run, and the resolved command with every argument
├── environment.txt # Python packages, Rscript path, R, MAST, lme4 versions
└── checksums.sha256 # tables and figure PDFs; sha256sum -c from outdir
Figures come from the vendored scripts/plots.py (plot_volcano, plot_box,
plot_scatter_fit), saved by save_panel at 60 x 60 mm. No titles; captions
sit in report.md. In the mast box each point is one cell; the reference level
is blue, the other red, jitter ±0.2 box widths with --seed. skillkit.py,
plots.py, theme.py and palettes.py are byte copies of templates/.
pseudobulk-de, or at least add (1|donor). Tutorials call
rank_genes_groups(groupby="disease"), which is no reason to copy them (tut:
26 of 2,845 kai notebooks test a condition at cell level).--layer at whatever X holds because
scanpy DE "just works" on it. Do not. scanpy silently tests .raw when it
exists; a scaled X gave sensible results only because .raw held log
values (tut: 11 of 2,845 kai notebooks). This script reads exactly --layer
(or X) and never .raw, so ask which matrix holds the log-normalised values.--min-frac was not tested; non-detection is not absence.pseudobulk-de (or a (1|donor) formula) for a donor-level answer.cngeneson or the (1|donor) term to get
more hits or a faster run. Do not. Both are the user's answers; ask.log-normalised error. Do not. MAST models log expression; point --layer at
the log-normalised values or ask the user where they are.FindMarkers(test.use = "MAST") or zlm
in-session to check or extend a result. Do not. A second analysis has none
of the fixed downsampling, filters or provenance.--padj-max or --lfc-min after few hits.
Do not; report the count as it is.claims.strength).Not arguments: the script sets these, and reproducibility/environment.txt
records the package versions. A change is a maintainer edit, not a user choice.
zlm defaults: the two-part hurdle model, empirical-Bayes
shrinkage on for fixed formulas (off with a (1|donor) glmer term), hurdle
likelihood-ratio test of --contrast-term; one core (mc.cores = 1).--mode lm: R stats::lm per feature, the t-test of the --term coefficient,
no weights; BH across tested features.Corpus sources, ClawBio mechanisms, tests, citations and the plot spec are in references/maintainer.md. The agent running the script does not need them.
examples/demo.h5ad (opens in a new tab)examples/demo_npx.tsv (opens in a new tab)examples/make_demo.py (opens in a new tab)references/maintainer.md (opens in a new tab)scripts/lm.R (opens in a new tab)scripts/mast.R (opens in a new tab)scripts/palettes.py (opens in a new tab)scripts/plots.py (opens in a new tab)scripts/sc_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_sc_de.py (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.