/lucid-coder:milo-dafrom lucid-coder
Milo differential abundance on a kNN graph with pertpy (pt.tl.Milo, pydeseq2 solver): seeded index-cell sampling, counts per sample per neighbourhood, NB GLM per neighbourhood, SpatialFDR, annotation with a Mixed label. Writes data/milo.h5mu, a neighbourhood table, significant counts per annotation, three fixed figures, a report and a reproducibility bundle. Fire on "Milo", "differential abundance on the kNN graph", "neighbourhood DA", "which cell states expand in disease", "milopy", "nhood graph", "DA beeswarm". Do NOT fire for cell-type proportion tests on labels (scCODA, crumblr, CLR tests), differential expression, or when cells still need embedding (sc-embed first).
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 milo-da. The script does the analysis; you collect its arguments, run it, and explain its outputs.
Run scripts/milo_da.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 pertpy (pixi install -e pertpy, from templates/pixi.toml).
| Input | Format | Required content | Example |
|---|---|---|---|
--adata | .h5ad | unique cell ids; obsm[--use-rep], obsm["X_umap"]; a kNN graph in obsp (rebuilt if absent or different) | sc-embed data/embedded.h5ad, examples/demo.h5ad |
| sample column | obs column | --sample-col, one level per biological replicate, no missing values | sample with A1-B3 |
| donor column | obs column | --donor-col, the donor of each sample, no missing values | donor with D1-D6 |
| design columns | obs columns | every column in --design, constant within a sample, no missing values | condition with A, B |
| annotation column | obs column | --annotation-col, cell labels, no missing values | cell_type |
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 embedded h5ad holds the cells and graph? | examples/demo.h5ad |
--context | Species, tissue or cell type, condition and dataset? | synthetic demo: 6 samples, condition B vs A, 4 Gaussian-blob cell types, no real tissue |
--sample-col | Which obs column is the replicate (sample, donor)? | sample |
--donor-col | Which obs column is the donor? A donor with several samples needs it in --design. | donor |
--design | Which design formula, with the test variable last (~batch + condition)? | ~condition |
--model-contrasts | Which contrast, naming both levels (conditionB-conditionA)? | conditionB-conditionA |
--solver | Which da_nhoods solver: pydeseq2 (NB-GLM Wald test, no R) or edger (R, rpy2 and edgeR; reproduces the R milo implementation)? No default. Recommended: pydeseq2, the solver this skill used before it became an argument (pertpy 1.4.0, pydeseq2 0.5.4). edger fails with an error when rpy2 is missing. | pydeseq2 |
--prop | What fraction of cells to sample as index cells (0.05-0.2 is usual)? | 0.1 |
--use-rep | Which obsm embedding defines neighbourhoods (X_pca, X_pca_harmony, X_scVI)? | X_pca |
--n-neighbors | Which k for the graph? A different k from the input graph rebuilds it. | 30 |
--spatial-fdr-max | Which SpatialFDR cutoff calls a neighbourhood significant? | 0.1 |
--annotation-col | Which obs column labels the neighbourhoods? | cell_type |
--min-annotation-frac | Under what top-label fraction is a neighbourhood Mixed? | 0.6 |
--seed | Which seed for index-cell sampling, a rebuilt graph and the plot jitter? | 0 |
--outdir | Which new directory gets the outputs? It must not exist. | milo_da_demo |
The last column is demo-only, not defaults. --demo alone pins all of them.
With --demo, only --n-neighbors and --outdir may also be given; any other
analysis argument is an error.
ERROR: <message>, exit 2.
Cell ids must be unique. Every design column must take one value per
--sample-col level. On the per-sample rows, the design terms must not be
aliased (check_design_rank), and a donor with several samples needs the
donor column as a design term (check_replication).connectivities and distances
are in obsp, uns["neighbors"]["params"] has the same use_rep,
n_neighbors and metric (euclidean, what the rebuild uses), its n_pcs
is absent or equals the columns of --use-rep, the graph is n x n cells, and
every cell has k - 1 stored neighbours (a graph made on a larger cell set and
then subset has fewer, so it counts as a different cell set). Otherwise
rebuild it with
sc.pp.neighbors(n_neighbors=--n-neighbors, use_rep=--use-rep) on all
columns of the representation, seeded. The summary and result.json
(graph_rebuilt, graph_rebuilt_reason) say which, and why.make_nhoods(prop=--prop, seed=--seed) samples
round(prop * n_cells) index cells, then refines each to the cell nearest
its neighbours' median in --use-rep.count_nhoods(sample_col=).da_nhoods(design=--design, model_contrasts=--model-contrasts, solver=--solver). With a contrast the design drops its intercept, so the
contrast names both levels (conditionB-conditionA). SpatialFDR is the
Benjamini-Hochberg adjustment weighted by 1 / distance to the k-th neighbour.annotate_nhoods(anno_col=--annotation-col) gives each
neighbourhood its most frequent label; a neighbourhood whose top label is
under --min-annotation-frac of its cells becomes Mixed. Then
build_nhood_graph(basis="X_umap").BLAS runs on one thread (threadpoolctl). pydeseq2 fans its dispersion fits out
over all CPUs; each neighbourhood is fitted alone, so results do not change.
nhoods.tsv is sorted by SpatialFDR, then PValue, then nhood;
da_by_annotation.tsv by annotation. The data file is h5mu (MuData).
outdir/
├── report.md # params, summary, figures with captions
├── result.json # n_cells, n_samples, n_donors, n_nhoods, n_significant, n_up, n_down, dominant_annotation, significant_by_annotation, graph_rebuilt, graph_rebuilt_reason, solver, seed, params, context, chat_summary_lines (first: "Context: ..."), preferred_artifacts
├── data/
│ └── milo.h5mu # "rna": cells, obsm nhoods, obs nhood_ixs_*; "milo": samples x nhoods counts, var logFC, PValue, SpatialFDR, nhood_annotation(_frac), Nhood_size
├── tables/
│ ├── nhoods.tsv # nhood, index_cell, size, logFC, PValue, SpatialFDR, annotation, annotation_frac
│ └── da_by_annotation.tsv # annotation, n_nhoods, n_up, n_down (SpatialFDR < cutoff)
├── figures/
│ ├── nhood_graph.pdf
│ ├── nhood_graph.png
│ ├── nhood_graph.csv
│ ├── da_beeswarm.pdf
│ ├── da_beeswarm.png
│ ├── da_beeswarm.csv
│ ├── nhood_size.pdf
│ ├── nhood_size.png
│ └── nhood_size.csv
└── 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
--seed or call make_nhoods again in-session
to "try another sample". Do not. The index cells are a seeded random draw;
rerun the script into a new outdir so each draw has provenance.--sample-col must be the biological replicate; with one sample per
condition the dispersion is not estimable and pertpy refuses the model.--design has the
donor column as a fixed term (the pydeseq2 solver has no (1|donor)). With
one sample per donor, leave the donor out: ~donor + condition is then
rank-deficient and stops the run.claims.strength).--spatial-fdr-max or switch to raw
PValue when nothing is significant. Do not. The cutoff is the user's call;
report zero hits as zero.--prop or --n-neighbors to speed things
up. Do not change them silently: they set the neighbourhood size
(nhood_size.png), which the miloR workflow says should peak around 50-100
cells. Ask the user.Mixed neighbourhoods a new cell type. Do
not. Mixed means no label reaches --min-annotation-frac.pertpy pt.tl.Milo with solver="pydeseq2" (pertpy 1.4.0, pydeseq2 0.5.4):
pure Python, no R. It normalises with TMM like miloR, fits dispersions with
pydeseq2 and tests the contrast with a likelihood ratio test. This comes close
to miloR's edgeR quasi-likelihood F-test but does not reproduce it exactly
(pertpy docstring). The edgeR solver needs rpy2 and R edgeR, and R miloR does
not build on this host (beachmat needs a newer C++ compiler), so both are out
of scope. Random-effect designs ((1|donor)) and de_nhoods (miloDE) are
also out of scope.
python scripts/milo_da.py \
--adata results/2026-10-27_embed/data/embedded.h5ad \
--sample-col sample --donor-col donor --design "~donor + condition" \
--model-contrasts conditiondisease-conditionhealthy \
--prop 0.1 --use-rep X_pca_harmony --n-neighbors 30 \
--spatial-fdr-max 0.1 --annotation-col cell_type --min-annotation-frac 0.6 \
--seed 0 --outdir results/2026-10-27_milo
# Demo (only when the user asks for one); add --n-neighbors 20 to see a rebuild
python scripts/milo_da.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.
make_nhoods(prop = --prop, seed = --seed) with its
default refinement of index cells; da_nhoods with its default k-distance
SpatialFDR weighting; annotate_nhoods takes the most frequent label.sc.pp.neighbors (scanpy 1.12.4) with the euclidean
metric, all columns of --use-rep and random_state = --seed.Mixed label and the X_umap layout basis are fixed.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/milo_da.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_milo_da.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