Merge spots¶
Merge Spots puts a large cell back together from the spots it covers. Where a cell is much bigger than the spot (a hypertrophic chondrocyte against a Visium HD bin), each spot holds only a fraction of the cell's transcripts, so every spot in the region looks shallow and none is a usable profile of the cell. Merge Spots groups neighboring spots in a region you draw, up to the size of one cell, and sums their counts.
Where to find it
Analyze → Spatial → Merge Spots → Open Merge Spots tool…
How it works¶
Within the selected region, neighboring spots are joined by greedy agglomeration over a Delaunay neighbor graph: the closest adjacent pair whose merged footprint (the largest distance between any two of its spots) still fits inside one cell is joined first, then the next, until no allowed join remains. This is constrained hierarchical clustering with a diameter cap, and it is deterministic (ties on a regular lattice break the same way every run).
Geometry decides which spots join; similarity can only refuse a join. The spots most worth merging are the low-count ones, and a correlation between two profiles of about 40 counts is mostly sampling noise: ranking candidate pairs by it would give a different grouping on every run. So the diameter cap, which is stable and has biological meaning, drives the grouping, and correlation enters only as a floor that blocks a join across a clear boundary between cell types.
- Size cap. Skopia measures the spot pitch as the median nearest-neighbor distance (in µm), and allows a merged group as many spots as a disc of Max diameter (µm) covers at that pitch, unless you set Max spots yourself. Only pairs closer than the diameter are candidates.
- Veto. Two groups are not joined when the correlation of their profiles is below Min correlation. The veto compares depth-normalized, log-transformed profiles (counts per 10,000, then
log1p) over the genes you pick, recomputed from the summed counts as groups grow. It does not correlate raw counts, because on raw counts any two spots agree: both are dominated by the same few high expressors, and the veto would never fire. - Sums raw counts. The merge adds integer counts. It reads
layers['counts']when present, otherwise.X, and refuses a matrix that is not integer-valued.
Run it¶
- Set the physical scale of the coordinates if it is not already known: Display → µm per coordinate unit (see Display settings). Visium HD data loaded from
feature_slice.h5needs no setup. Without a scale, a diameter in µm means nothing and the tool refuses. - Lasso the region of large cells on the spatial plot (Select, mask and delete). The region is your statement that these spots belong to cells larger than the spot; at least two spots are needed.
- Open Analyze → Spatial → Merge Spots → Open Merge Spots tool….
- Set Max diameter (µm), the veto's Min correlation and the genes it reads, and Eligibility.
- Click Preview. Nothing is created. The preview reports the region size, the measured pitch and the resulting maximum spots per merge, how many merged spots result, the distribution of merge sizes, the median counts per spot before merging, how many candidate pairs the veto blocked, and where Min correlation sits in the distribution of candidate correlations.
- Adjust and preview again until the veto is doing what you intend.
- Click Create merged dataset. The result opens as a new dataset in its own tab; the source dataset is untouched.
Parameters¶
| Parameter | Default | What it does |
|---|---|---|
| Max diameter (µm) | 40 | A merged group stops growing once its footprint would exceed this. The one parameter with biological meaning: set it to the diameter of the cells in the region. |
| Max spots | auto | Maximum spots per group. Blank derives it from the diameter and the measured pitch. |
| Min correlation | 0.15 | Joins between groups whose normalized profiles correlate below this are blocked. A floor, not a ranking. |
| Veto genes | all genes | Genes the veto correlates over: a boolean .var column, a combination of columns, or a Gene Panel gene set. Correlation uses those genes' expression, never a set score. |
| Eligibility | Every spot in the region | Only spots under a count threshold (default 500 counts) or Only the shallowest fraction (default 0.5) leave well-covered spots alone, at the price of an output whose count distributions differ by construction. |
What it writes¶
A new dataset, with one row per spot outside the region plus one row per group inside it (a region spot that joined nothing is a group of one):
| Where | What |
|---|---|
.X and layers['counts'] |
Raw counts: copied for spots outside the region, summed for groups. Every row, including those outside the region, is a raw count, whatever .X held in the source. |
.obsm[<spatial key>] |
Coordinates; a merged group sits at the mean of its spots. No other .obsm is kept. |
Categorical .obs columns |
Carried over; a merged group takes the majority value of its spots. |
obs['merged_n_spots'] |
Spots in the group (1 for spots outside the region). |
obs['merge_group'] |
Group id (g0, g1, …); empty for spots outside the region. |
obs['merge_purity'] |
For merged groups: the share of member spots that agree with the majority label of the first categorical .obs column. A low value marks a merge that crossed a boundary the veto missed. |
uns['skopia_spot_merge'] |
Parameters, source file, and spot counts before and after. |
Merged rows are named merged_g<id>. The µm scale is copied from the source.
The merged dataset carries no derived numbers. Numeric and QC .obs columns are dropped, not averaged, and embeddings other than the spatial one are dropped: a mean of per-spot scores is an approximation the summed counts cannot justify, and a UMAP position from the original spots would draw for a merged row while meaning nothing. Rebuild from the raw counts: normalize, then rerun PCA, neighbors, clustering and anything else you need on the new dataset.
Tips and pitfalls¶
Read the veto line in the preview
If Min correlation sits below nearly all candidate correlations, the veto is inert and geometry alone decides. If it sits inside the bulk of the distribution, it is blocking ordinary joins. On the bundled toy dataset, a 111-spot region merged to 40 spots at a 90 µm diameter, giving a 929-spot dataset (1,000 - 111 + 40); raising the veto to 0.9 blocked 71 pairs and left 108 spots, and the preview reported that the threshold sat outside the bulk of the distribution.
Compare against the source, not instead of it
Merging creates rows that never existed, so any embedding, clustering or differential expression table from the source does not apply to the merged dataset. Keep the source open beside it for comparison.
Visium HD: binning from 2 µm¶
A related step happens at load time. 10x Visium HD downloads ship a *_feature_slice.h5 holding expression at 2 µm resolution. Skopia detects this format and rebins it to 8 µm tissue bins using the file's own tissue mask, writes bin centroids in µm to obsm['spatial'], records the bin size so the µm scale is known, and imports 10x's precomputed clusterings as categorical columns. The first load takes about 1 to 2 minutes and is cached next to the source file. Fixed binning does not follow cell boundaries; Merge Spots is the tool for regions where one cell spans many bins. See Load your data.