Skip to content

Place dissociated cells on a tissue map

Advanced 15 minutes Data: bundled toy_localize_spatial.h5ad (1,200 spots) and toy_localize_scrna.h5ad (900 cells), 120 genes

Dissociating a tissue for scRNA-seq throws away where each cell was. If a spatial dataset of the same tissue exists, its spots can lend their positions back: each dissociated cell is placed where the spots that look most like it are. Localize does that, scores how much to trust each placement, and can check itself on the spatial data before you believe it.

The two bundled files are made for learning this. The scRNA-seq file was simulated from the same tissue as the spatial one and keeps each cell's true position in obs['true_x'], obs['true_y'] and the embedding spatial_true, so you can compare the prediction with the truth. Real data never gives you that.

1. Load both datasets

Open File → Load… twice, each time with Load into: set to New dataset: first backend/skopia/data/toy_localize_spatial.h5ad, then backend/skopia/data/toy_localize_scrna.h5ad. Make the scRNA-seq tab active: Localize writes into the dataset that is active.

Color by cell_type. There are seven types: four occupy one zone each of a ring (Anterior, Basal, Posterior, Apical), Bipolar sits in two separate patches, and Circulating and Immune are scattered with no positional pattern. Switch the Embedding to spatial_true to see this layout.

The true positions of the scRNA-seq cells

2. Open the tool and pick the reference

Open Analyze → Spatial → Localize and click Open Localize tool….

  1. Set Reference to toy_localize_spatial.h5ad. The first spatial dataset in the list is preselected, which is not necessarily the one you want; with the wrong reference the tool reports how few genes the two share and refuses to pretend.
  2. Query is the active dataset, toy_localize_scrna.h5ad. Writes to shows .obsm['X_spatial_pred'].
  3. The panel reports 120 of the reference's 120 genes are present here (100%).

Leave the defaults for now: Neighbours (k) 30, Expression transform z-score per dataset, Similarity correlation, Aggregation weighted mean.

3. Check accuracy before you trust it

Click Check accuracy on the reference. Localize hides some spots of the spatial dataset, places them from their expression as if they were dissociated cells, and measures how far off it lands. On this pair, with the defaults:

Measure Value
Median error 29.7
Predicting the tissue center for every cell 66.9
Random placement 80.0
Held-out cells within 10% of the tissue diameter 42%
Structure preserved (r) 0.31
Confidence tracks error (r) -0.66

The baselines are what make the number meaningful: an error of 29.7 means nothing alone, but it is well under half of what guessing the center gives. The last line says that low-confidence placements are the bad ones, so the confidence score is worth using.

4. Localize

Click Localize. The tool reports Wrote .obsm['X_spatial_pred'] for 900 of 900 cells. Median confidence 0.57. 386 cells score below 0.2. It also writes obs['X_spatial_pred_confidence'] and obs['X_spatial_pred_similarity'].

Close the tool, set the Embedding to X_spatial_pred and color by cell_type.

Predicted positions with weighted-mean aggregation

Weighted-mean aggregation (k = 30): the four zone types land on their own zones, pulled toward each zone's center. Bipolar cells land between their two patches, and Circulating and Immune cells collect in the middle.

Then color by X_spatial_pred_confidence (Continuous tab).

Predicted positions colored by confidence

Confidence (0 to 0.74 in this run). The scattered types in the middle have the lowest confidence: their expression carries no information about position, and the score says so.

5. A type found in two places

Look again at Bipolar. Its cells resemble spots in two separate patches, and a weighted mean of positions from two patches is a point between them, where no Bipolar cell exists. The tool warns about this under Aggregation.

Open the tool again, set Aggregation to densest cluster, change the output name to X_spatial_pred_densest so the first result is kept, and run Check accuracy and Localize again. On this pair:

weighted mean densest cluster
Median error 29.7 26.6
Within 10% of the diameter 42% 47%
Confidence tracks error (r) -0.66 -0.43

Predicted positions with densest-cluster aggregation

Densest-cluster aggregation: each cell's position is the mean of the tightest cluster among its neighbors' positions, so Bipolar cells land in one of their two real patches instead of the gap. Which patch is a guess: the guide reports it picks correctly about half the time on this benchmark.

Neither choice wins everywhere: densest cluster places cells on real tissue (though not always in the right patch) and lowers the median error here, while weighted mean gives a confidence score that tracks error more closely. Which aggregation to use depends on whether your cell types have one location or several; the Localize guide describes the others, including transport, which fills the tissue the way the spots do.

What to take from this

  • Always run Check accuracy first, and compare with the baselines.
  • Color by confidence before interpreting a predicted map. Cells of types that have no spatial pattern will be placed somewhere; the confidence is how you know not to believe it.
  • On your own data, use genes that vary in space: run Spatial Autocorrelation on the reference and pick spatially_variable as the Similarity basis.