/lucid-coder:sc-normalizefrom lucid-coder
Normalise a single-cell count h5ad one of three fixed ways: log1p of library-size-scaled counts, analytic Pearson residuals (the model SCTransform v2 approximates), or dsb for ADT counts using empty droplets and isotype controls. Writes data/normalized.h5ad with the input counts kept, per-cell and per-feature tables, mean-variance, depth-vs-PC1 and value-distribution figures, a report and a reproducibility bundle. Fire on "normalise my counts", "Pearson residuals", "SCTransform-style normalisation", "dsb normalise the ADT", "denoise CITE-seq protein with empty droplets", "does depth still drive PC1". Do NOT fire for QC filtering (sc-qc), embedding and clustering (sc-embed, which does its own log1p), pseudobulk voom (pseudobulk-de), or R SCTransform itself.
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-normalize. The script does the analysis; you collect its arguments, run it, and explain its outputs.
Run scripts/sc_normalize.py. Never re-implement the analysis, change a
parameter, 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.
Fire this skill when the user says any of:
Do NOT fire when:
SCTransform() with vars.to.regress (out of scope).log1p: scanpy normalize_total then log1p, the sc-embed baseline.pearson: scanpy.experimental.pp.normalize_pearson_residuals, the analytic
Pearson residuals of Lause, Berens and Kobak (2021) with one fixed overdispersion
theta for all genes. SCTransform v2 (Choudhary and Satija 2022) fits a
regularised NB GLM per gene and is close to this model; this skill does not
run SCTransform. The corpus "port" (single_cell_aging/.../sctransform.py,
from sctoolkit) is an rpy2 wrapper around R sctransform, not a Python
re-implementation, and also regresses out other covariates; neither is here.dsb: muon's mu.prot.pp.dsb (muon 0.2.0), the method of Mulè, Martins and
Tsang (2022): log(x + 10), standardise each protein by the mean and SD of the
empty droplets, then per cell take the background mean from a 2-component GMM,
combine it with the isotype values into one technical component (first PC)
and regress it out of every protein. The corpus (ALTRA TEA-seq) calls the
same function.| Input | Format | Required content | Example |
|---|---|---|---|
--adata | .h5ad | raw counts (non-negative integers) in X; no cell with zero counts. RNA for log1p/pearson, ADT of cells for dsb | sc-qc data/qc_filtered.h5ad, examples/demo.h5ad |
--empty-droplets | .h5ad | ADT counts of empty droplets in X, the same features in the same order as --adata, no barcode shared with --adata | examples/demo_empty.h5ad |
| gene ids | var[--gene-id-col] | log1p/pearson: Ensembl gene ids, one per symbol in var_names; no id shared by two symbols | gene_ids in examples/demo.h5ad |
| isotypes | var_names | every --isotype-controls name is a feature of --adata | IgG1,IgG2a,IgG2b |
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. Method rows are required for that method and refused for the others.
| Argument | Grill question | Demo-only value |
|---|---|---|
--adata | Which h5ad holds the raw counts (ADT of cells for dsb)? | examples/demo.h5ad; dsb: examples/demo_adt.h5ad |
--method | Normalise by log1p, pearson residuals or ADT dsb? | pearson |
--layer-out | Which layer name gets the normalised values (not counts)? | normalized |
--seed | Which seed for the dsb GMM and the diagnostic PCA? | 0 |
--reference | Which genome build and annotation release named the genes (e.g. GRCh38, GENCODE 44)? For dsb, which antibody panel and release? Recorded in result.json. | synthetic demo features, no genome build |
--context | Species, tissue or cell type, condition and dataset? | synthetic demo: 3 groups x 200 cells, RNA and ADT, no real tissue |
--target-sum | log1p: to what total is each cell scaled first? (tut: 1e4 in 195 of 376 kai normalize_total notebooks, 1e6 in 19, unset (median) in 128.) | 10000 |
--theta | pearson: which NB overdispersion theta (100 in Lause et al.)? (tut: both kai Pearson notebooks keep scanpy's defaults for theta and clip; the choice is still yours.) | 100 |
--gene-id-col | log1p/pearson: which var column holds the Ensembl gene ids (var_names are the symbols)? none if the source has no ids; gene_id is then NA. | gene_ids |
--clip | pearson: clip residuals to +-what (scanpy suggests sqrt(n cells))? | 25 |
--empty-droplets | dsb: which h5ad holds the ADT counts of empty droplets, and how were they chosen? | examples/demo_empty.h5ad |
--isotype-controls | dsb: which features are isotype controls (comma list)? | IgG1,IgG2a,IgG2b |
--dsb-pseudocount | dsb: which pseudocount is added before the log? Recommended 10 (muon 0.2.0 mu.prot.pp.dsb default; Mulè et al. 2022). | 10 |
--outdir | Which new directory gets the outputs? It must not exist. | sc_normalize_demo |
The last column is demo-only, not defaults. --demo alone pins all of them.
With --demo, only --method and --outdir may also be given; --demo --method dsb switches to the ADT demo files.
ERROR: <message>, exit 2.
Nothing is written before every check passes. Feature names and cell ids
must be unique in --adata and --empty-droplets (skillkit.check_unique).
For log1p/pearson, skillkit.check_gene_ids stops on a gene id shared by
two symbols.result.json and the summary, and each stays in gene_mean_variance.tsv
with status not_detected and NA statistics. Pearson residuals are 0/0 for them.layers["counts"].--method:
log1p: normalize_total(target_sum=--target-sum), log1p;pearson: normalize_pearson_residuals(theta=--theta, clip=--clip);dsb: mu.prot.pp.dsb(cells, empty, pseudocount=--dsb-pseudocount, denoise_counts=True, isotype_controls=..., scale_factor="standardize", random_state=--seed).layers[--layer-out]: sparse for log1p
(from sparse counts), dense for pearson and dsb.BLAS runs on one thread (threadpoolctl).
X; layers are not read.data/normalized.h5ad: X holds the normalised values (log1p, Pearson
residuals or dsb), layers["counts"] the raw counts, layers[--layer-out] a
copy of X. Only log1p output is log-normalised: sc-markers, ccc,
signature-scoring and tf-activity refuse Pearson residuals (negative values)
and dsb values.Not asked, recorded here. dsb (muon 0.2.0): denoise_counts=True,
scale_factor="standardize", background from --empty-droplets with no
empty_counts_range. pearson (scanpy 1.12.4
sc.experimental.pp.normalize_pearson_residuals): all genes, no batch key.
Diagnostics only, no effect on X: PC1 from 2 arpack PCs, 6 features in the
value plot, 20 quantile bins for the trend line.
per_cell_summary.tsv is sorted by cell; gene_mean_variance.tsv by feature.
gene_mean_variance.tsv keeps every input feature: status is tested, or
not_detected for an all-zero feature (NA statistics, left out of the
figures). gene_id (log1p/pearson only) is NA under --gene-id-col none.
outdir/
├── report.md # params, summary, figures with captions
├── result.json # method, n_cells, n_features, n_features_dropped, status_counts, gene_id_col, pc1_depth_abs_spearman, layer_out, seed, params, reference, context, chat_summary_lines (first: "Context: ..."), preferred_artifacts
├── data/
│ └── normalized.h5ad # X normalised (log1p sparse; pearson, dsb dense), layers["counts"] input, layers[--layer-out] = X
├── tables/
│ ├── per_cell_summary.tsv # cell, library_size, normalised_total, n_detected, pc1
│ └── gene_mean_variance.tsv # feature, gene_id (not dsb), mean_counts, var_counts, mean_normalised, var_normalised, status
├── figures/
│ ├── mean_variance.pdf
│ ├── mean_variance.png
│ ├── mean_variance.csv
│ ├── depth_pc1.pdf
│ ├── depth_pc1.png
│ ├── depth_pc1.csv
│ ├── top_variable_values.pdf
│ ├── top_variable_values.png
│ ├── top_variable_values.csv
│ ├── isotype_vs_background.pdf # dsb only
│ ├── isotype_vs_background.png # dsb only
│ └── isotype_vs_background.csv # dsb only
└── 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 plots.py (plot_scatter_fit) and matplotlib in
the same theme, saved by save_panel; captions sit in report.md.
mean_variance (E-pl-04, voom-like): log10 variance against log10 mean count
per feature, counts (left, Poisson line) and normalised (right), binned-median
trend.depth_pc1: PC1 against log10 library size, linear fit and 95% CI.top_variable_values: box plots of normalised values for the 6 features with
the highest normalised variance.isotype_vs_background (dsb): per-cell median protein log(count + --dsb-pseudocount)
against mean isotype log(count + --dsb-pseudocount). The median stands in for dsb's GMM
background mean, which muon does not return.scripts/skillkit.py, plots.py, theme.py and palettes.py are byte copies
of templates/; a test fails when they drift.
--theta or --clip itself ("scanpy uses
100"). Do not. They are grill questions; quote Lause et al. and scanpy's
sqrt(n) suggestion, then ask.empty_counts_range=(1.2, 2.8); a kai muon tutorial uses
(1.5, 2.8), tut: 1 of 2 kai dsb notebooks). Do not. Two sources give two
ranges. Which barcodes are empty is the user's call; ask for the file and how
it was made.--isotype-controls when the panel has none.
Do not. Stop and tell the user; dsb without isotypes is a different
correction and is not offered here.counts in X ... must be non-negative integers. Do not. Ask where the raw
counts are; this skill normalises them itself..raw and .X to "restore" counts
or stash a normalised copy. Do not. Raw counts live in layers["counts"]
only; a log-normalised X cannot give counts back without its size factors.
np.expm1(X) or np.exp(X) - 1 gives size-normalised values, not counts; one
kai tutorial even adds 1 instead of subtracting it (tut: 2 of 2,845 kai
notebooks write such values where counts belong). Ask for the raw counts.layers["counts"] = adata.X
before normalising an input by hand. Do not. Without .copy(), the layer and
X are one object. normalize_total and log1p then rewrite both when X
is float, as read_10x_h5 gives. The script keeps its own copy, so pass the
raw file as it is (tut: 53 of 2,845 kai notebooks).sc.pp.scale(max_value=10) as part of
"normalising". Do not. Scaling is a separate, dense step for PCA. This
skill's output is normalised, not scaled, and the DE skills refuse scaled
data (tut: 87 of 530 kai log1p notebooks scale).np.expm1(X[:5]).sum(1) near one total
means log1p-normalised; negative values mean residuals or scaled data. Then
ask for the raw counts if X is not counts (source: kai,
davidfischerlab/kai prompt_manager.py).--reference from the gene names. Do not.
Ask for the build and annotation release (or the ADT panel); it is recorded,
never inferred.claims.strength).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_adt.h5ad (opens in a new tab)examples/demo_empty.h5ad (opens in a new tab)examples/make_demo.py (opens in a new tab)references/maintainer.md (opens in a new tab)scripts/palettes.py (opens in a new tab)scripts/plots.py (opens in a new tab)scripts/sc_normalize.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_normalize.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.Other plugins' skills for the same job
/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).