/lucid-coder:mashr-sharingfrom lucid-coder
Cross-cell-type effect sharing with mashr: takes one DE table per cell type (gene_id, gene_symbol, logFC, SE), checks the ids are compatible, aligns genes, fits mashr with canonical or canonical plus data-driven (ED) covariances, and writes posterior means, posterior SDs and lfsr per gene and cell type, counts of genes significant in 1..K cell types, mashr pairwise sharing, raw-logFC Spearman per pair, three figures, a report and a reproducibility bundle. Fire on "mashr across cell types", "run_mash", "which DE genes are shared between cell types", "cell-type-specific vs shared effects", "effect sharing heatmap", "replicate logFC across cell types", "borrow strength across cell types". Do NOT fire for running the per-cell-type DE itself (pseudobulk-de), meta-analysis of the same cell type across cohorts, gene-set enrichment on the posterior (zenith/enrichment skill), or cell-type 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 mashr-sharing. The script does the analysis; you collect its arguments, run it, and explain its outputs.
Run scripts/mashr_sharing.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 (pixi install -e bioc-de, from templates/pixi.toml).
| Input | Format | Required content | Example |
|---|---|---|---|
--de name=path | TSV, one per cell type, at least 2 | one row per gene; name labels the cell type | CD4T=out_cd4/tables/de_results.tsv |
| gene columns | gene_id, gene_symbol (fixed names) | gene_id unique within a table (Ensembl, as the source gives it), or NA in every row when the source has no ids | ENSG00000111640.15, GAPDH |
| effect column | --effect-col | numeric, no NA (logFC, same contrast in every table) | log2_fc |
| SE column | --se-col | numeric, no NA, > 0 | lfc_se |
A pseudobulk-de tables/de_results.tsv carries gene_id, gene_symbol,
log2_fc, lfc_se. Drop its NA rows first (genes the engine could not fit). A limma or
dreamlet table has no SE column: add se = logFC / t, as dreamlet's run_mash
does.
Required checks (docs/pipeline-skills.md, adopted 2026-10-27):
duplicate_gene), as
does a repeated cell-type name (duplicate_name).gene_id. A table with
gene_id NA in some rows stops (partial_ids); NA in every row (a source with
symbols only) joins on gene_symbol, writes gene_id as NA and records
joined_on: gene_symbol. A symbol with several ids stops the run
(skillkit.check_gene_ids).skillkit.check_compatible stops
when the tables use different id types (versioned vs unversioned Ensembl, ids vs
symbols) or share no gene; result.json reports n_shared_ids.--reference (genome build and annotation release) is
required and written to result.json; every table must use the same one.--align intersect are
reported per cell type (genes_dropped_by_align; all 0 for union).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 |
|---|---|---|
--context | Species, tissue or cell type, condition and dataset? It opens the report and the chat summary. | synthetic demo: 4 cell types x 800 genes, no real tissue |
--de (repeat) | Which DE table belongs to which cell type? Do all tables test the same contrast? | B=, CD4T=, CD8T=, Mono= examples/demo_*.tsv |
--effect-col | Which column holds the effect (logFC)? | log2_fc |
--se-col | Which column holds its standard error? | lfc_se |
--align | Keep only genes tested in every cell type (intersect), or every gene with the missing cells treated as unmeasured (union)? | intersect |
--covariances | Canonical covariances only (canonical, as dreamlet's run_mash), or canonical plus data-driven ED (canonical+ed)? | canonical+ed |
--null-corr | Do these DE tables come from the same donors? Then em (null correlation V by EM, as dreamlet's run_mash); identity only for independent cells and samples. | identity |
--fit-subset | On which genes are the mixture weights fitted? all: one mash() fit on every gene. random: fit on a random subset, then fix the weights and compute every gene's posterior (the mashr eQTL vignette workflow; needs --fit-n). strong: fit on the strong genes (lfsr < --strong-lfsr in mash_1by1), then the same fixed-weight posterior. No default. Recommended: all (the mashr 0.2.79 mash(data, Ulist) call this skill used before it became an argument). | all |
--fit-n | Only with --fit-subset random: how many random genes (an integer >= 2, at most the aligned genes)? No recommended value; the vignette's subset size belongs to its data. The draw uses --seed. | not asked |
--strong-lfsr | Which lfsr in a one-by-one ash fit picks the strong signals that train the ED covariances? Used with canonical+ed and with --fit-subset strong. | 0.05 |
--lfsr-max | Which lfsr marks a gene significant in a cell type (also the sharing threshold)? | 0.05 |
--sharing-factor | Within what factor must two posterior means agree to count as shared (mashr's factor)? | 0.5 |
--reference | Which genome build and annotation release are the genes from (e.g. GRCh38, GENCODE 44)? | synthetic demo genes, no genome build |
--seed | Which seed? (Passed to set.seed and mash(seed=).) | 0 |
--outdir | Which new directory gets the outputs? It must not exist. | mashr_sharing_demo |
The last column is demo-only, not defaults. --demo alone pins all of them;
only --outdir may be given beside it.
python scripts/mashr_sharing.py \
--context "human PBMC, IFN-beta vs control, Kang 2018" \
--de B=b/tables/de_results.tsv --de CD4T=cd4/tables/de_results.tsv \
--de Mono=mono/tables/de_results.tsv \
--effect-col log2_fc --se-col lfc_se --align intersect \
--covariances canonical+ed --fit-subset all --strong-lfsr 0.05 --lfsr-max 0.05 \
--sharing-factor 0.5 --reference "GRCh38, GENCODE 44" --seed 0 \
--outdir results/2026-10-27_mash
# Demo (only when the user asks for one)
python scripts/mashr_sharing.py --demo --outdir demo_out
ERROR: <message>, exit 2.--align: intersect keeps genes in every
table; union keeps all, with NA where a table lacks the gene. Genes and cell
types are sorted by name.mash_set_data(Bhat, Shat). It sets a missing cell to Bhat = 0,
Shat = 1e6, so it carries no information. With --null-corr em, the null
correlation V is estimated by mash_estimate_corr_em over the canonical
covariances and set with mash_update_data, before any ED step; with
identity it stays at identity (see "Null correlation V" below).cov_canonical. With canonical+ed, also: strong genes are
those with lfsr < --strong-lfsr in any cell type in mash_1by1;
cov_pca(npc = K) on them seeds cov_ed. K is the number of cell types, so
no PC is dropped and npc is no choice. Fewer strong genes than K is an error (also with --fit-subset strong).mash(data, U, seed = --seed) (--fit-subset all; for random or strong,
a mash fit on that subset with outputlevel = 1, then mash(data, g = get_fitted_g(fit), fixg = TRUE) for all genes), then get_pm, get_psd, get_lfsr. As in
dreamlet's run_mash, a cell the gene was not measured in is set to NA.get_pairwise_sharing(factor = --sharing-factor, lfsr_thresh = --lfsr-max) on the genes measured in both.--lfsr-max.posterior.tsv is long, sorted by gene symbol then cell type. Every gene of
every input table has a row: status is tested, or not_tested with NA
statistics when --align intersect dropped it. A gene a table never held has
no row for that cell type. Counts, figures and sharing use tested rows only;
result.json counts rows per status (status_counts). The pair tables are sorted by cell_type_a, cell_type_b.
outdir/
├── report.md # params, summary, figures with captions
├── result.json # context, n_genes, cell_types, genes_dropped_by_align, n_shared_ids, joined_on, status_counts, n_strong, null_corr, fit_subset, fit_n, n_significant_any, n_shared_all, n_specific, significant_per_cell_type, scatter_pair, params, seed, reference, chat_summary_lines, preferred_artifacts
├── tables/
│ ├── posterior.tsv # gene_id, gene_symbol, cell_type, raw_effect, raw_se, pm, psd, lfsr, significant, status
│ ├── significant_counts.tsv # n_cell_types (1..K), n_genes
│ ├── pairwise_sharing.tsv # cell_type_a, cell_type_b, sharing
│ ├── raw_spearman.tsv # cell_type_a, cell_type_b, n_genes, rho, pvalue
│ └── null_corr.tsv # cell_type_a, cell_type_b, v (0 everywhere with identity)
├── figures/
│ ├── sharing_heatmap.pdf
│ ├── sharing_heatmap.png
│ ├── sharing_heatmap.csv
│ ├── significant_hist.pdf
│ ├── significant_hist.png
│ ├── significant_hist.csv
│ ├── raw_vs_posterior.pdf
│ ├── raw_vs_posterior.png
│ └── raw_vs_posterior.csv
└── reproducibility/
├── commands.sh # argv as run, and the resolved command with every --de
├── environment.txt # Python packages, Rscript path, R, mashr, ashr versions
└── checksums.sha256 # tables and figure PDFs; sha256sum -c from outdir
get_pairwise_sharing(m) with its defaults.
Do not. Its lfsr_thresh = 0.05 and factor = 0.5 are hidden thresholds; the
script passes --lfsr-max and --sharing-factor.--align union marks it unmeasured (SE 1e6) and reports NA there.--sharing-factor; it is not a probability that any gene
is shared.claims.strength).not_tested as no effect. Do not. The gene
was missing from another table; it was not tested in this run.canonical when canonical+ed stops on
too few strong signals, or to relax --strong-lfsr. Do not. Ask the user;
both change the prior.run_mash estimates V with mash_estimate_corr_em. Do not patch it in.
This skill keeps V at identity; if the cell types share donors, say so in
the report and raise it with the user (see "Null correlation V").--reference from gene symbols. Do not. Ask
the user for the genome build and annotation release.mash.R keeps the null correlation V at identity (mash_set_data(Bhat, Shat)
with no V). Identity assumes the per-cell-type DE tables come from independent
cells and samples, so their null errors do not correlate. dreamlet's run_mash
instead estimates V with mash_estimate_corr_em(data, U.c) (checked in
dreamlet 1.8.0 source); cell types measured in the
same donors usually have correlated errors, and identity then overstates
sharing evidence. --null-corr is required and has no default: em when the
tables share donors (dreamlet's choice), identity only when they come from
independent cells and samples. Its grill question: do these DE tables come from
the same donors?
Not arguments: the script sets these, and reproducibility/environment.txt
records the package versions. A change is a maintainer edit, not a user choice.
mash() defaults: grid gridmult = sqrt(2), usepointmass = TRUE,
normalizeU = TRUE; canonical covariances from cov_canonical (identity,
singletons, equal effects, simple heterogeneity); cov_pca(npc = K) feeding
cov_ed for canonical+ed; strong genes from mash_1by1 (ashr 2.2.63
defaults).get_pairwise_sharing(factor = --sharing-factor, lfsr_thresh = --lfsr-max) on the genes measured in both cell types.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_B.tsv (opens in a new tab)examples/demo_CD4T.tsv (opens in a new tab)examples/demo_CD8T.tsv (opens in a new tab)examples/demo_Mono.tsv (opens in a new tab)examples/make_demo.py (opens in a new tab)references/maintainer.md (opens in a new tab)scripts/mash.R (opens in a new tab)scripts/mashr_sharing.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_mashr_sharing.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).