Enrichment (ORA and GSEA)¶
The Enrichment tool asks which annotated gene sets a result points at. Overlap (ORA) tests whether a gene list, such as a cluster's markers, shares more genes with each library set than chance would give. GSEA (preranked) ranks every gene by a contrast and asks whether each set's genes sit at the top or bottom of that ranking.
Where to find it
Analyze → Genes → Gene-set Enrichment, Genes panel → ⋯ → Enrichment analysis…, or a gene set's ⋯ → Enrichment (overlap)… (which opens with that set as the query).
The Enrichment… button in Compare Cells, Find Marker Genes and Diff Exp opens it preset to the groups you checked.
Both tests run against the libraries already in the local cache of the Gene set library (MSigDB, GO and its slims, Enrichr, OmniPath, MGI GXD) and, optionally, one folder of your own gene sets. Nothing is downloaded during a run: fetch the libraries you want first.
Overlap (ORA)¶
How it works¶
For each library set, Skopia counts how many query genes it contains (k) and computes the hypergeometric probability of seeing at least that many by chance, given the set's size in the universe (K), the query size and the universe size. P-values are adjusted across all tested sets with Benjamini-Hochberg (Benjamini and Hochberg 1995).
- The universe is the dataset's genes after the gene mask, optionally narrowed to a boolean
.varcolumn such ashighly_variable. A set's sizeKis counted within that universe, and sets whose in-universe size falls outside the Set size range are not tested. - Symbols match case-insensitively after an exact match fails, so a human-symbol library works on mouse data.
- Directional sets are tested with their up and down genes pooled, since overlap ignores sign.
- Sets below Min overlap are still tested and still count toward the multiple-testing correction; they are only flagged and hidden by default. Dropping them before the correction would bias it.
Each row reports the overlap k/K, the expected count, the fold enrichment (k over expected), the odds ratio (with 0.5 added to every cell of the 2 × 2 table when any cell is zero, so it stays finite), p and padj. Expanding a row lists the overlapping genes.
Run it¶
- Open the tool and stay on Overlap (ORA).
- Under Gene sets to test, tick cached libraries, and under My gene sets: optionally pick one of your folders.
- Set Universe: to all visible genes or a boolean
.varcolumn. - Choose the Query gene list: one of your gene sets, Paste genes… (one symbol per line, or comma or space separated), or Marker genes of each group in a column… to run one test per group (see All groups in one run).
- Click Run overlap test (Run overlap test per group for the marker query).
| Parameter | Default | What it does |
|---|---|---|
| Set size | 5 to 500 | Library sets with fewer or more genes in the universe are not tested. |
| Min overlap | 2 | Rows with a smaller overlap are hidden (but tested). |
| Top N markers (marker query) | 100 | Marker genes per group used as each group's query list. |
| Min in-group frac., Max out-group frac., Min fold change (marker query) | from marker_genes: in config (blank: no filter) |
Filters on the marker ranking before the top N are taken, as in Find Marker Genes. |
A query needs at least two genes present in the universe.
GSEA (preranked)¶
How it works¶
Genes are ranked by a score, and for each set Skopia walks down the ranking, stepping up at each set member (weighted by the member's |score| raised to Weight) and down at each non-member. The enrichment score (ES) is the walk's largest deviation from zero (Subramanian et al. 2005). Positive ES means the set's genes collect at the top of the ranking; negative, at the bottom. The leading edge is the members before the peak (or after it, for a negative ES).
Significance comes from a gene-permutation null: for a set of size k, the null ES values are those of random k-gene subsets of the same ranking. One pool of permutations serves every set size, so each size class costs one vectorized evaluation, the approach of fgsea (Korotkevich et al. 2016); a whole GO library runs in seconds. The null is split by sign: a positive ES is compared with the positive null values only. The normalized enrichment score (NES) is ES divided by the mean absolute null ES of the same sign, so NES is comparable across set sizes. P-values are empirical and adjusted with Benjamini-Hochberg.
Directional sets are tested as two sets, <name> and <name> (down), because a ranked test cares which way each member should move.
p-values have a floor
An empirical p-value cannot be smaller than 1 / (1 + the number of same-sign null values), about 2 / Permutations: with the default 1,000 permutations, about 0.002. If many sets sit at the floor, the padj ordering among them is not informative; raise Permutations.
Rankings¶
| Ranking | What it ranks by |
|---|---|
| Differential expression | A contrast of one group of an .obs column against rest or against another group, by Wilcoxon or t-test. rank by test statistic (default) or rank by log2 fold change. Cells: restricts the contrast to a saved named subset (default all cells). |
| Differential expression, All groups (one vs rest) | One GSEA per group of the column. See All groups in one run. |
| PCA loading | One Component's gene loadings from the dataset's PCA (or a subset's, X_pca_<name>). Run PCA first. |
Run it¶
- Open the tool and switch to GSEA (preranked).
- Choose the ranking and its options.
- Tick libraries under Gene sets to test, optionally a folder under My gene sets:, and set Universe:.
- Click Run GSEA (Run GSEA per group for all groups). GSEA runs as a background task with progress.
| Parameter | Default | What it does |
|---|---|---|
| Set size | 15 to 500 | Sets outside this range (counted in the universe) are not tested. |
| Permutations | 1000 | Size of the permutation null. Sets the p-value floor (about 2 / permutations). |
| Weight | 1.0 | Exponent on |score| in the running sum. 0 gives the classic unweighted Kolmogorov-Smirnov walk. |
| Seed | 0 | Seed for the permutations, so a run is reproducible. |
Each row reports the set size, ES, NES, p and padj. Expanding a row draws the running score with a rug of the members' positions and the ranking-metric strip below, and lists the leading-edge genes; click a gene to color the embedding by it.
All groups in one run¶
Both tabs can test every group of a column at once:
- GSEA: choose All groups (one vs rest) as the group.
- ORA: choose Marker genes of each group in a column… as the query. Skopia runs one-vs-rest marker genes for every group, keeps the top N per group, and tests each list.
The batch stores one ordinary result per group plus a collection that lists them. A group with fewer than two cells on either side of its contrast is skipped and named rather than failing the run. The results view shows one chip per group with its count of significant sets; pick a chip to see that group's table. The Enrichment… hand-off from Compare Cells, Find Marker Genes or Diff Exp opens the tool preset to the checked groups (or to group 1 versus group 2).
A batch result is what the enrichment figures are drawn from: Heatmap figure… makes a gene sets × groups heatmap and Network figure… a network of groups and gene sets, both as saved, editable figures in the Figures tab. See The Figures tab.
Results¶
| Control | What it does |
|---|---|
| padj filter | Shows rows at or below the cutoff (default 0.05). |
| Filter by name or library | Searches the table. |
| hide below min overlap (ORA) | Hides rows under Min overlap. |
| Add N to gene sets | Files one gene set per row passing the padj filter (top 50 rows) in the Enrichment category: the overlap genes for ORA, the leading edge for GSEA. A batch files one folder per group. |
| Copy TSV | Copies the table to the clipboard. |
| Download SVG | Saves the expanded GSEA running-score plot. |
| Previous runs… | Reopens or deletes a stored result. |
What it writes¶
| Where | What |
|---|---|
uns['skopia_enrichment'][key] |
Each result as a JSON string: parameters, the ranking summary, every tested set's statistics and genes. Keys are ora_<query>, gsea_<column>_<group>_vs_<reference> or gsea_pca<n>; batches add ora_<column>_<group>_markers and gsea_<column>_<group>_vs_rest per group, plus a collection key ora_<column>_batch or gsea_<column>_batch. |
Results therefore travel with the saved .h5ad. Every run is a step in the analysis record and the notebook export (xa.run_overlap_enrichment(...), xa.prepare_gsea(...) and their batch versions); see Analysis record and notebook export.
Configuration¶
Defaults live under enrichment: in config.yaml (Configure defaults):
| Key | Default | Meaning |
|---|---|---|
min_set_size, max_set_size |
5, 500 | ORA set size range. |
min_overlap |
2 | ORA rows below this are hidden by default. |
gsea_min_set_size, gsea_max_set_size |
15, 500 | GSEA set size range. |
n_perm |
1000 | GSEA permutations. |
weight |
1.0 | GSEA running-sum exponent (0 = classic KS). |
padj_cutoff |
0.05 | Results table filter. |
marker_top_n |
100 | Markers per group for the ORA batch. This is its own key: Find Marker Genes shows 5 per group by default (marker_genes.top_n), too few for an overlap test. |
Tips and pitfalls¶
Choose the universe deliberately
ORA asks whether a list is enriched relative to the genes it could have contained. If your list came from highly variable genes, set Universe: to highly_variable; testing it against all genes credits the library sets with whatever HVG selection itself favors.
A gene list is not independent of its own clustering
Markers of a cluster are, by construction, genes that separate that cluster. Enrichment of those markers describes what the cluster is, not independent evidence that it exists.
Note
A GSEA ranking needs at least two genes with a finite score. PCA-loading GSEA uses the loadings of the PCA's own genes (usually the highly variable genes), so genes outside the PCA do not take part.
Related¶
- Gene set library and bundles: fetch the libraries enrichment tests against
- Differential expression and markers: the contrasts and marker lists enrichment starts from
- The Figures tab: enrichment heatmap and network figures
- Tutorial: Gene sets, scores and enrichment