/lucid-coder:gene-programsfrom lucid-coder
Gene-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.
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 gene-programs. The script does the analysis; you collect its arguments, run it, and explain its outputs.
Run scripts/gene_programs.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.
| Input | Format | Required content | Example |
|---|---|---|---|
--adata | .h5ad | raw integer counts in X, or in --layer; QC-filtered cells; no cell with zero counts over the HVGs; var_names are gene symbols, --gene-id-col names the Ensembl id column | sc-qc's filtered h5ad; examples/demo.h5ad |
--groupby | obs column | at least 2 groups, for the program-by-group summary | leiden, cell_type; demo group |
The script refuses negative or non-integer values (log-normalised data). A
categorical --groupby keeps its category order; any other column is cast to
strings and sorted.
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 | Meaning | Grill question | Demo-only value |
|---|---|---|---|
--adata | input h5ad | Which h5ad holds the raw counts? | examples/demo.h5ad |
--layer (optional) | count matrix | Which layer holds the raw counts? Absent means X. | absent (X) |
--context | species, tissue or cell type, condition, dataset | Species, tissue or cell type, condition and dataset? | synthetic demo: 3 groups x 60 cells, 300 genes, 3 planted programs, no real tissue |
--gene-id-col | var column of Ensembl gene ids, or none | Which var column holds the Ensembl gene ids? (none if the source has symbols only; gene_id is then NA, never guessed.) | gene_ids |
--groupby | obs column of groups | Which obs column holds the clusters or labels to summarise programs by? | group |
--reference | genome build and annotation | Which genome build and annotation release name the genes (for example GRCh38, GENCODE 44)? | synthetic demo, no genome build |
--k | number of programs | How many programs (k)? Choose it before the run; this skill does not sweep k. | 3 |
--n-hvg | genes factorised | How many highly variable genes go into NMF? | 200 |
--hvg-flavor | HVG ranking | Which HVG flavor: seurat or cell_ranger (both rank genes on the log-normalised copy)? Recommended seurat (scanpy 1.12.4 default). | seurat |
--target-sum | scaling before the HVG log1p | To what total count is each cell scaled for HVG selection? Recommended 10000 (scanpy 1.12.4 normalize_total corpus value; its own default is the median depth). | 10000 |
--n-replicates | NMF runs | How many NMF replicates (at least 4)? cNMF uses 100-200 for real data. | 20 |
--neighbour-fraction | local-density neighbours | Which fraction of --n-replicates sets the neighbour count int(fraction x n-replicates) for the density filter? Recommended 0.3 (cNMF local_neighborhood_size default). | 0.3 |
--nmf-max-iter | NMF iterations | How many NMF iterations at most, for replicates and the usage fit? Recommended 1000 (cNMF, scikit-learn 1.x NMF; its own default is 200). | 1000 |
--kmeans-n-init | k-means starts | How many k-means starts for the consensus? Recommended 10 (scikit-learn KMeans(n_init=10), as in cNMF). | 10 |
--density-threshold | outlier filter | Above which mean distance to its nearest replicate components is a component dropped? 2 keeps all. | 0.5 |
--active-threshold | active-cell rule | Above which fraction of the program's maximum usage does a cell count as active? | 0.1 |
--n-top-genes | top genes per program | How many top genes per program go in the table and heatmap? | 10 |
--seed | seed | Which seed? It derives the replicate seeds and fixes k-means and the jitter. | 0 |
--outdir | new output directory | Which new directory gets the outputs? It must not exist. | gene_programs_demo |
The last column is demo-only, not defaults. --demo alone pins all of them.
With --demo, only --outdir may also be given; any other argument is an error.
python scripts/gene_programs.py \
--adata results/2026-10-27_qc/data/filtered.h5ad --layer counts --groupby leiden \
--reference "GRCh38, GENCODE 44" \
--k 12 --n-hvg 2000 --hvg-flavor seurat --target-sum 10000 --n-replicates 100 \
--neighbour-fraction 0.3 --nmf-max-iter 1000 --kmeans-n-init 10 --density-threshold 0.1 \
--active-threshold 0.1 --n-top-genes 20 --seed 0 \
--outdir results/2026-10-27_programs
# Demo (only when the user asks for one)
python scripts/gene_programs.py --demo --outdir demo_out
X, or in --layer. After sc-embed, X is
log-normalised and the counts sit in layers["counts"]: pass --layer counts.data/programs.h5ad: X and layers as in the input, plus obsm["usage"],
varm["gene_scores"] and var["highly_variable"].Not asked, recorded here. scikit-learn NMF: Frobenius loss, solver="cd",
init="random"; non_negative_factorization(update_H=False) for usage;
TPM scale 1e6 (it cancels in the z-scored gene scores); cNMF input scaled to unit
variance per gene, not centred; per-cell usage scaled to sum 1; replicate seeds
from numpy.random.default_rng(--seed).
ERROR: <message>, exit 2.
Gene names and cell ids must be unique (skillkit.check_unique). The matrix
must be non-negative integers and --groupby must have 2+ groups.--n-hvg expressed genes by --hvg-flavor on a
normalize_total(target_sum=--target-sum) + log1p copy. The NMF input is the HVG counts scaled to
unit variance per gene, not centred (cNMF prepare).--n-replicates times with sklearn NMF (Frobenius, cd
solver, random init, --nmf-max-iter iterations); replicate seeds are drawn from
numpy.random.default_rng(--seed).k × n-replicates components; drop each
whose mean Euclidean distance to its int(--neighbour-fraction × n-replicates) nearest
components is not below --density-threshold; k-means (k, --kmeans-n-init starts,
random_state=--seed); the median of each cluster, scaled to sum 1, is a
consensus spectrum. Fewer than k kept components stops the run.non_negative_factorization,
update_H=False), then scale each cell's usage to sum 1 (cNMF load_results).GP1..GPk by total usage across cells, largest first.gene_spectra_score). Top genes are the highest scores.--active-threshold
(immgenT Figure2.R); and one-vs-rest AUC of usage (roc_auc_score, fixed
direction: above 0.5 means higher in the group, below 0.5 lower).Sort keys: usage.tsv by program then cell; gene_loadings.tsv by program,
score descending, gene, then one row per gene with no counts (status
not_detected, NA program and score; scored rows are tested);
top_genes.tsv likewise with a 1-based rank, scored genes only;
program_by_group.tsv and stability.tsv by program then group order.
outdir/
├── report.md # params, summary, figures with captions
├── result.json # n_cells, n_genes, n_hvg, n_genes_scored, status_counts (per gene), gene_id_col, k, n_components_kept, n_components_total, mean_silhouette, top_genes, seed, params, context, reference, chat_summary_lines (first: "Context: ..."), preferred_artifacts
├── tables/
│ ├── usage.tsv # cell, <groupby>, program, usage (cell sums to 1), usage_max_scaled, active
│ ├── gene_loadings.tsv # program, gene, gene_id, score (z-score units), hvg, status
│ ├── top_genes.tsv # program, rank, gene, gene_id, score
│ ├── program_by_group.tsv # program, <groupby>, n_cells, mean_usage, frac_active, auc
│ └── stability.tsv # program, n_components, n_replicates, silhouette (mean over its components)
├── figures/
│ ├── usage_heatmap.pdf
│ ├── usage_heatmap.png
│ ├── usage_heatmap.csv
│ ├── usage_structure.pdf
│ ├── usage_structure.png
│ ├── usage_structure.csv
│ ├── top_gene_heatmap.pdf
│ ├── top_gene_heatmap.png
│ ├── top_gene_heatmap.csv
│ ├── auc_by_group.pdf
│ ├── auc_by_group.png
│ └── auc_by_group.csv
├── data/
│ └── programs.h5ad # input object + obsm["usage"], varm["gene_scores"], var["highly_variable"]
└── reproducibility/
├── commands.sh # argv as run, and the resolved command with every argument
├── environment.txt # Python and package versions
└── checksums.sha256 # tables and figure PDFs; sha256sum -c from outdir
Figures come from the vendored scripts/plots.py (heatmaps, box) or matplotlib
in the same theme (structure plot), saved by save_panel as PDF, PNG and source
CSV. No titles; captions sit in report.md.
usage_heatmap (plot_heatmap, D-pl-28, D-pl-34): program × group mean
usage, centred and scaled per program across groups.usage_structure (D-pl-29): one stacked column per cell (stackplot, so the
PDF stays small), cells ordered by group, then dominant program, then its usage.top_gene_heatmap (plot_heatmap): program × top-gene scores, scaled per
gene across programs.auc_by_group (plot_box, D-pl-30): one point per program per group, dashed
line at AUC 0.5. Under 10 programs (FEW_POINTS) it draws points and a
median, no box.Every caption names k, the HVG count, the replicate count and the seed. Both
heatmaps are fixed by label, not clustered: programs by name (GP1 has the
largest total usage), groups by --groupby order, genes by program then rank.
Display constants, not analysis parameters: heatmaps saturate at ±2
(HEATMAP_LIMIT, house-style fig.heatmap); jitter ±0.2 box widths
(JITTER_WIDTH). scripts/skillkit.py, plots.py, theme.py and
palettes.py are byte copies of templates/; a test fails when they drift.
does not look like raw counts error. Do not. NMF here models counts; point
--layer at the raw counts or ask the user where they are.--k after seeing the programs, or run
several k and keep the nicest. Do not. k is the user's answer; a k sweep with
a stability-versus-error plot is a separate task the user asks for.--density-threshold after too_few_kept.
Do not. Report the message; the threshold is the user's choice.GP1..GPk stay; any
naming is the user's interpretation, stated as such.tables/usage.tsv.status in gene_loadings.tsv is not_detected, which
says nothing about it.claims.strength).--reference from the gene names. Do not.
The build and annotation release are the user's answer.cnmf package or another NMF library. Do
not. The engine is fixed: sklearn NMF plus the consensus steps above.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/make_demo.py (opens in a new tab)references/maintainer.md (opens in a new tab)scripts/gene_programs.py (opens in a new tab)scripts/palettes.py (opens in a new tab)scripts/plots.py (opens in a new tab)scripts/skillkit.py (opens in a new tab)scripts/theme.py (opens in a new tab)tests/test_gene_programs.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
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).Other plugins' skills for the same job