|
| 1 | +--- |
| 2 | +name: decoupler |
| 3 | +description: Use for any task involving the decoupler library — inferring biological activity/enrichment scores from omics data (bulk, single-cell, spatial). Triggers on estimating transcription factor (TF) activity, pathway activity, or gene-set enrichment from an AnnData/DataFrame; running ulm, mlm, ora, gsea, gsva, aucell, viper, zscore, waggr, mdt, udt; multi-method consensus; fetching prior knowledge (CollecTRI, DoRothEA, PROGENy, MSigDB hallmarks, OmniPath); pseudobulk and expression filtering; using bundled example datasets (pbmc3k, covid5k, erygast1k, hsctgfb, msvisium, knocktf, toy) and whether they are raw counts or normalized; ranking/plotting activity scores; or benchmarking methods against ground truth. This is a router skill — read the relevant file under references/ before writing decoupler code, because outputs land in different places and several defaults are non-obvious. |
| 4 | +--- |
| 5 | + |
| 6 | +# decoupler |
| 7 | + |
| 8 | +`decoupler` estimates biological activities (transcription factors, pathways, gene |
| 9 | +sets) from omics data. You give it a **data matrix** (observations × features, e.g. |
| 10 | +cells × genes) and a **prior-knowledge network** (which features belong to which |
| 11 | +biological program), and it returns an **enrichment score per observation per |
| 12 | +program** — all methods sharing one unified interface. Part of scverse; works |
| 13 | +directly on `AnnData`, `pandas.DataFrame`, or raw matrices. |
| 14 | + |
| 15 | +This skill is a **router**. Each topic below has a detailed reference file with exact |
| 16 | +signatures and footguns. **Read the relevant reference before writing code** — do not |
| 17 | +rely on memory of the API, because results are written to different places depending |
| 18 | +on the input type and several methods have non-obvious defaults. |
| 19 | + |
| 20 | +## Two cross-cutting concepts (read these first if unsure) |
| 21 | + |
| 22 | +- **[The unified method call](references/calling-convention.md)** — every method is |
| 23 | + called the same way: `dc.mt.<method>(data, net, tmin=5, ...)`. Covers the accepted |
| 24 | + input types (AnnData / DataFrame / `[matrix, obs, var]` **list**), the shared |
| 25 | + arguments (`tmin`, `raw`, `layer`, `empty`, `bsize`), and the big footguns: input |
| 26 | + must be **normalized (e.g. log1p), not raw counts**, and `net` must be a |
| 27 | + **long-format** `source`/`target`/`weight` table. |
| 28 | + |
| 29 | +- **[Where the results go](references/io-and-outputs.md)** — the return type depends |
| 30 | + on the input type. **AnnData → written in place** into `.obsm["score_<method>"]` |
| 31 | + (and `.obsm["padj_<method>"]` if the method tests), returns `None`. **DataFrame / |
| 32 | + list → returns an `(es, pv)` tuple** (`pv` is `None` for non-testing methods). Read |
| 33 | + scores back out of an AnnData with `dc.pp.get_obsm`. **This is the #1 thing agents |
| 34 | + get wrong.** |
| 35 | + |
| 36 | +## Task → reference file |
| 37 | + |
| 38 | +| If the task is… | Read | |
| 39 | +|---|---| |
| 40 | +| **starting from scratch** — set up an end-to-end run (load data → get a net → score → rank → plot) | [references/getting-started.md](references/getting-started.md) | |
| 41 | +| how to **call a method**, what data/net formats are accepted, `tmin`/`raw`/`layer` semantics | [references/calling-convention.md](references/calling-convention.md) | |
| 42 | +| **where scores land** and how to read them back (`.obsm` vs `(es, pv)` tuple, `get_obsm`) | [references/io-and-outputs.md](references/io-and-outputs.md) | |
| 43 | +| **choosing and configuring a method** — ulm/mlm/ora/gsea/gsva/aucell/viper/zscore/waggr/mdt/udt + their kwargs | [references/methods.md](references/methods.md) | |
| 44 | +| getting **prior knowledge** — TF regulons (CollecTRI, DoRothEA), pathways (PROGENy), gene sets (MSigDB hallmarks), OmniPath, `.gmt`, organism translation | [references/priors.md](references/priors.md) | |
| 45 | +| **preprocessing** — pseudobulk from single cell, expression/sample filtering, layers, spatial kNN | [references/preprocessing.md](references/preprocessing.md) | |
| 46 | +| running **many methods at once** and combining them into a **consensus** | [references/multi-method.md](references/multi-method.md) | |
| 47 | +| **ranking** activity scores by group/ordering and **plotting** them (barplot, dotplot, volcano, network) or overlaying them on a **UMAP / spatial H&E** via scanpy | [references/ranking-and-plotting.md](references/ranking-and-plotting.md) | |
| 48 | +| **benchmarking** methods/nets against a perturbation ground truth | [references/benchmarking.md](references/benchmarking.md) | |
| 49 | +| using a **bundled example dataset** (`dc.ds.*`) — and whether its `.X` is raw counts or already normalized | [references/datasets.md](references/datasets.md) | |
| 50 | + |
| 51 | +## Quick orientation (submodule map) |
| 52 | + |
| 53 | +decoupler exposes everything through namespaced submodules — canonical import is |
| 54 | +`import decoupler as dc`: |
| 55 | + |
| 56 | +- `dc.mt` — **methods**: the enrichment/activity algorithms (`ulm`, `mlm`, `ora`, |
| 57 | + `gsea`, `gsva`, `aucell`, `viper`, `zscore`, `waggr`, `mdt`, `udt`) plus |
| 58 | + `dc.mt.decouple` (run several) and `dc.mt.consensus`. `dc.mt.show()` lists them. |
| 59 | +- `dc.op` — **prior knowledge** (OmniPath): `collectri`, `dorothea`, `progeny`, |
| 60 | + `hallmark`, `resource`, `translate`. |
| 61 | +- `dc.pp` — **preprocessing**: `pseudobulk`, `filter_by_expr`, `filter_by_prop`, |
| 62 | + `filter_samples`, `get_obsm`, `extract`, `swap_layer`, `knn`, `read_gmt`. |
| 63 | +- `dc.ds` — **datasets**: `toy` (used in every example: `adata, net = dc.ds.toy()`), |
| 64 | + `pbmc3k`, `covid5k`, and other real examples. **They differ in normalization state** |
| 65 | + (some raw counts, some already log-normalized) — see |
| 66 | + [datasets.md](references/datasets.md) before scoring one. |
| 67 | +- `dc.tl` — **tools**: `rankby_group`, `rankby_obsm`, `rankby_order`. |
| 68 | +- `dc.pl` — **plotting**: `barplot`, `dotplot`, `volcano`, `network`, `obsm`, etc. |
| 69 | +- `dc.bm` — **benchmarking**: `benchmark`, `metric`, `pl`. |
| 70 | + |
| 71 | +## Conventions used throughout |
| 72 | + |
| 73 | +- **Data** = observations × features (cells/samples × genes), **normalized** (log1p), |
| 74 | + not raw counts. **Net** = long-format DataFrame: `source` (program), `target` |
| 75 | + (feature), optional signed `weight`. |
| 76 | +- Output score matrices are observations × sources. AnnData results live in `.obsm` |
| 77 | + under `score_<method>` / `padj_<method>`. |
| 78 | +- `tmin` (default 5) silently drops sources with fewer than `tmin` targets present in |
| 79 | + the data — lower it for small/toy nets (examples use `tmin=3`). |
| 80 | +- `verbose=True` on any method prints the pruning/run log — use it to see how many |
| 81 | + sources survived `tmin`. |
| 82 | +- **Plotting**: use `dc.pl.*` for summary plots and scanpy `sc.pl.umap` / `sc.pl.spatial` |
| 83 | + (on a `dc.pp.get_obsm` score AnnData) for embedding/tissue overlays. Never reimplement |
| 84 | + a plot from matplotlib primitives — see |
| 85 | + [ranking-and-plotting.md](references/ranking-and-plotting.md). |
0 commit comments