Metacells¶
A metacell is a small group of highly similar cells whose profiles are combined into one. Summing the counts of a handful of near-identical cells removes most of the dropout and sampling noise of single cells, and the result is a dataset several times smaller that keeps far more heterogeneity than cluster averages do. The Metacells tool builds them by similarity or from your annotation and opens the result as a new dataset in its own tab, where every other tool works on it as on any single-cell dataset.
Where to find it
Analyze → Cells → Metacells → Open Metacells tool…
How it works¶
There are two ways to group the cells.
By similarity follows SuperCell (Bilous et al. 2022): walktrap community detection (Pons & Latapy 2006) on the kNN graph the dataset already has, with the merge tree cut so that the number of metacells is the number of cells divided by cells per metacell (the graining level, gamma). No new embedding or graph is computed, so the metacells reflect the genes, PCs and neighbors you chose. Optionally, no metacell may mix the labels of a column you pick (the sample, or a cell type annotation): edges between cells with different labels are ignored, so the metacells are built separately inside each label. A review of the methods (Bilous et al. 2024) recommends building metacells per sample or condition for this reason, and per annotation when one is trusted.
By annotation makes one metacell per combination of the labels you pick, for example each cell type in each sample. This is a pseudobulk. The combinations rarely hold similar numbers of cells, so the tool shows their sizes as soon as you pick columns. Combinations of fewer than 10 cells are left out unless you lower that floor, and the tool can also draw the same number of cells from every group and bring every profile to the same total counts; see Groups of unequal size.
Either way the member cells are then aggregated: the sum of raw counts, or the mean of the current matrix.
Method details
Each connected piece of the graph gets round(size / gamma) metacells, at least one, so the total is close to n / gamma but not exactly it; a cell left without edges is a metacell of its own. Walktrap uses walks of length 4 (igraph's default, as in SuperCell) and is deterministic. Its cost grows roughly with the square of the number of cells (2 s for 9,000 cells and 95 s for 50,000 on the development machine), so a connected piece above 20,000 cells is first cut into Leiden blocks and each block is partitioned on its own. Metacell sizes are uneven, as in SuperCell: walktrap follows the graph, so dense regions give larger metacells.
Other metacell methods take different routes: MetaCell and Metacell-2 (Baran et al. 2019; Ben-Kiki et al. 2022) partition a kNN graph with their own resampling and divide-and-conquer schemes, and SEACells (Persad et al. 2023) uses kernel archetypal analysis. SuperCell's approach was chosen because it needs only the existing kNN graph and has one parameter with a direct meaning.
Run it¶
- For grouping by similarity, build a graph with Neighbors first (PCA, neighbors, UMAP, Leiden). Grouping by annotation needs no graph.
- Open Analyze → Cells → Metacells and click Open Metacells tool….
- Choose By similarity or By annotation.
- By similarity: check Cells per metacell (the suggestion and its reason are shown), pick the kNN graph, and optionally click the columns under Keep each metacell within. By annotation: click the columns under Group cells by, in the order you want them named. The lines below the columns give the number of groups, their sizes and the smallest ones, and what the run would make with the Group size settings as they stand; set those if the sizes differ more than you want.
- Choose how to Aggregate, and optionally the columns to Report purity for.
- Click Create metacell dataset. The new dataset opens in its own tab, and the tool shows a summary: how many metacells, their sizes, the counts per metacell, and the purity of each column you asked about.
- Use File → Save to keep it. It is not saved automatically.
With a cell mask active, only the masked cells are grouped.
In the new dataset, start at Normalize when it holds summed counts (Preprocess). The embeddings it opens with are the member cells' mean positions, good for a first look; run PCA, Neighbors and UMAP on the metacells for analysis.
Parameters¶
| Parameter | Default | What it does |
|---|---|---|
| Mode | By similarity (By annotation when the dataset has no graph) | How cells are grouped |
| Cells per metacell | suggested from the data | Graining level, gamma: the mean number of cells per metacell |
| kNN graph | the dataset default graph | The graph walktrap runs on |
| Keep each metacell within | none | Label columns no metacell may mix |
| Group cells by | none | By annotation: one metacell per combination of these columns' labels |
| Leave out groups under | 10 | By annotation: a combination with fewer cells makes no metacell. Set it to 1 to keep every combination. |
| Same number of cells in every group | off | By annotation: each profile is made from that many cells drawn at random from its group. The number defaults to the smallest group that passed the floor; a group with fewer cells than the number is left out. |
| Same total counts in every profile | off | By annotation, summed counts only: counts are removed at random from each profile until all match the shallowest one |
| Seed | 0 | Fixes the cells drawn and the counts removed; shown when either of the two options above is on |
| Aggregate | Automatic | Sum of raw counts (the counts layer, else X when it holds whole numbers) or Mean of X as it stands. Automatic sums when raw counts exist and averages otherwise. |
| Report purity for | none | Label columns whose purity is reported and stored, besides the grouping columns |
| Membership column | metacell |
Column added to the source dataset with each cell's metacell id |
The suggested cells per metacell aims at 160,000 total counts per metacell, Metacell-2's default target: 160,000 divided by the median counts per cell, kept within 10 to 50. That range is the one SuperCell documents and over which the review found downstream results consistent. A dataset without raw counts gets 20, SuperCell 2.0's default. The suggestion is lowered when it would leave fewer than 50 metacells. Do not choose the value by a clustering score such as silhouette or modularity; the review found those misleading for this purpose. Choose it by how many counts and how many metacells you need.
Sum or mean. Summed raw counts are right for anything downstream, including differential expression: the new dataset is normalized like any other. Means of a normalized matrix suit display and scoring only.
Groups of unequal size¶
Label combinations differ in size by orders of magnitude, and a profile summed over 5 cells is not comparable with one summed over 5,000. Two things differ. The summed profile has fewer counts, so fewer genes are detected and low values are noisier; and it averages over fewer cells, so it reflects those few cells more than the population. The three Group size settings address these separately.
Leave out groups under drops combinations too small to stand for a population, 10 cells by default. Same number of cells in every group makes each profile from the same number of cells, drawn uniformly at random without replacement. The default number is the size of the smallest group that passed the floor, so the floor decides it: lowered to 1, a single one-cell combination would reduce every profile to one cell. Typing a larger number leaves out the groups that cannot supply it. The lines under the column pills show the result before you run.
Cells are never chosen by their depth. A cell's total counts follow its type, its cell-cycle phase and its quality, so drawing cells to match depth ranges across groups would draw the atypical cells of each group. Depth is handled on the summed counts instead: Same total counts in every profile removes counts at random from each profile until all match the shallowest, which is what sequencing every profile to that depth would have given. Each count is equally likely to stay, so a profile's composition is kept in expectation and the totals come out exactly equal.
Equal cells do not give equal depth. On a 700-cell mouse gastrulation dataset (7 cell types of 100 cells, five stages; cell type × stage gives 25 groups of 1 to 74 cells; raw counts summed):
| Setting | Groups | Summed counts per profile | Genes detected per profile |
|---|---|---|---|
| Floor of 1 (every cell) | 25 | 1,900 to 870,330 (458-fold) | 1,283 to 12,549 |
| Floor of 10 (the default) | 18 | 103,796 to 870,330 (8.4-fold) | 8,536 to 12,549 |
| Floor of 10, 12 cells per group (seed 0) | 18 | 103,796 to 222,148 (2.1-fold) | 8,536 to 10,469 |
| Floor of 10, 12 cells per group, same total counts | 18 | 103,796 in each | 8,275 to 9,464 |
| Floor of 10, every cell, same total counts | 18 | 103,796 in each | 8,349 to 9,303 |
Across the 25 unbalanced profiles the number of genes detected followed the summed counts (Spearman correlation 0.97). After drawing 12 cells per group it still did (0.83 across the 18 profiles), because the groups' cells differ in depth. With the totals matched and every cell kept, genes detected no longer followed the number of cells (0.09). So when the concern is detection and noise from depth, matching the total counts is the setting that removes it, and it does not require discarding cells. Drawing equal cells addresses the other concern, that a profile of many cells averages over more of the population than a profile of few.
The cost of both settings is data. Drawing 12 cells from a group of 74 discards 62 of them, and each profile is then one random draw: run it with another seed to see how much a result depends on the draw. Two alternatives keep every cell. For differential expression between conditions with replicate samples, the usual practice is to leave the groups unequal and use a count model that takes each profile's library size into account; Skopia's own tests do not do this yet. To get units of similar size from all the cells, use By similarity with Keep each metacell within set to the same columns: that gives several metacells of about the chosen size inside each combination. Those are not independent replicates; treating them, or cells, as replicates in a test between conditions inflates significance (Squair et al. 2021).
What it writes¶
In the source dataset:
| Where | What |
|---|---|
obs['metacell'] |
Each cell's metacell id; NaN outside the cell mask, and for a cell that went into no metacell (its group was left out, or the draw did not pick it). After a balanced run this column is the record of which cells each profile was made from. |
The new dataset (<source name>_metacells.h5ad, one row per metacell):
| Where | What |
|---|---|
X |
The aggregate: summed counts or means |
layers['counts'] |
The summed counts, for a sum |
obs_names |
mc_0, mc_1, … by similarity; the labels joined with | by annotation |
obs['metacell_id'], obs['n_cells'] |
The id used in the source's membership column, and the number of member cells |
obs['n_cells_available'] |
With Same number of cells in every group: the size of the whole group the cells were drawn from |
obs['n_counts_summed'] |
With Same total counts in every profile: the profile's total before counts were removed |
obs[<label column>] |
Each label column of the source, as the majority label of the member cells, with the source's colors. A text column with more labels than metacells (cell barcodes, say) is left out. |
obs[<label column>_purity] |
For the grouping columns and those you asked for: the share of member cells carrying the majority label |
obs[<numeric column>] |
The mean over the member cells (the cells drawn, after a balanced run); a true/false column becomes the share that are true |
obsm[...] |
Every embedding, as the mean position of the member cells |
uns['skopia_metacells'] |
The run: source file, mode, cells per metacell, graph, grouping columns, aggregation, time; for a balanced run also the floor, the cells per group, the seed, the names of the groups left out and the total every profile was thinned to |
Graphs, PCA loadings and other results of the source are not carried over: they describe the cells, not the metacells.
Tips and pitfalls¶
Metacells are not equally reliable
A metacell of 3 cells is noisier than one of 60. Skopia's tests do not weight by n_cells, so check that a result does not rest on the smallest metacells; filtering on n_cells in the new dataset is a simple guard. The review recommends size-aware downstream methods where available.
- Per-cell QC columns become means.
total_countsin the new dataset is the mean of the member cells' values, not the metacell's own total. Recompute QC metrics on the metacells if you need them. - Purity is your check on the grouping. Ask for the purity of an annotation you did not constrain on. Low purity means metacells mix what you consider different cells: lower the cells per metacell, or keep metacells within that column.
- Constraining adds metacells. Each label and each connected piece is rounded separately, and stray cells become their own metacells, so a constrained run gives somewhat more metacells than n / gamma (1,003 against an expected 919 for 9,186 limb mesenchyme cells at 10 per metacell kept within 13 cell types).
- Rare populations. A population smaller than the cells per metacell can be absorbed by its neighbors. Keep metacells within an annotation that names it, or lower the value.
- Do not treat metacells as cells for counting. Proportions of metacells are not proportions of cells; use
n_cells. - A balanced profile is one draw. With Same number of cells in every group, a different seed gives different cells. If a conclusion changes with the seed, it rested on the draw.
- Two runs give two tabs with the same name. The tab shows the number of metacells; rename on save.
Related¶
- PCA, neighbors, UMAP, Leiden
- Tight clusters
- Datasets, split view and compare
- Merge spots: the spatial counterpart
- Preprocess