Analysing spatial transcriptomics data: from spots to tissue domains

What changes when every measurement has a location, and how to work with it.

Single-cell RNA-seq tells you which cell types are in a tissue. It loses where they were. Spatial transcriptomics keeps the coordinates, so you can ask where cell types sit, which ones neighbour each other, and how expression changes across a tissue section. This post covers the main steps for spot-based data, with code in Python.

Two kinds of spatial data

Spot-based methods, such as Visium, place a grid of capture spots over a tissue section. Each spot is about 55 micrometres across and reads out the whole transcriptome, but it captures a mixture of cells, so a spot's profile is a blend.

Imaging-based methods, such as MERFISH, Xenium and seqFISH, detect individual RNA molecules under a microscope. They reach single-cell or subcellular resolution, but they measure a chosen panel of genes and not the whole transcriptome. The steps below focus on spot-based data, and several of them (neighbour graphs, spatially variable genes, neighbourhood analysis) apply to both.

1. Quality control and normalisation

The start looks like single-cell analysis: filter genes detected in very few spots, then normalise and log-transform. The difference is that you should plot the quality metrics on the tissue. A region with low counts may be a fold, a tear, or the edge of the section, and it may also be a real area with few cells. Look at the image before removing spots, so that you do not filter out real biology.

2. Find tissue domains

Clustering spots by expression alone works, but the clusters can end up scattered across the section, even when the tissue has clear regions. Spatially aware methods add neighbour information so that nearby spots are encouraged to share a label. Examples include BayesSpace, SpaGCN, STAGATE and GraphST. Whatever you use, compare the resulting domains with the histology image. Domains that follow known anatomy are a good sign.

3. Deconvolve the spots

Because each spot contains several cells, a useful next step is to estimate how much of each cell type a spot contains. Deconvolution methods do this using a single-cell reference from the same or a similar tissue. Tools include cell2location, RCTD, Tangram and SpatialPrompt, which is a spatially aware method for deconvolution and clustering. The output is a table of cell-type proportions per spot.

The reference decides the result. A cell type that is missing from the reference cannot be found in the spots, and its signal gets assigned to the closest match. Check the proportions against what you know about the tissue.

4. Find spatially variable genes

Spatially variable genes are genes whose expression follows a pattern across the tissue, instead of being scattered at random. Moran's I is a standard measure, and SPARK-X and SpatialDE are popular alternatives. Many of the genes you find will simply be markers of the domains from step 2. To find something new, ask whether a gene varies within a domain, and not only between domains.

5. Look at neighbourhoods

Because you know which spots are neighbours, you can test which cell types or domains sit next to each other more often than chance would predict. You can also restrict ligand-receptor analysis to neighbouring spots, using tools such as Squidpy, CellChat or COMMOT. Treat these results as hypotheses to follow up, not as proof of signalling.

A starting point in Squidpy

import scanpy as sc
import squidpy as sq

adata = sq.read.visium("spaceranger_output/")
adata.var_names_make_unique()

# Quality control
sc.pp.calculate_qc_metrics(adata, inplace=True)
sc.pp.filter_genes(adata, min_cells=10)
sc.pl.spatial(adata, color="total_counts")

# Normalise and cluster on expression
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
sc.pp.highly_variable_genes(adata, n_top_genes=2000)
sc.pp.pca(adata)
sc.pp.neighbors(adata)
sc.tl.leiden(adata, resolution=0.5, flavor="igraph", n_iterations=2, directed=False)
sc.pl.spatial(adata, color="leiden")

# Spatial neighbours and spatially variable genes (Moran's I)
sq.gr.spatial_neighbors(adata, coord_type="grid", n_neighs=6)
hvg = adata.var_names[adata.var["highly_variable"]]
sq.gr.spatial_autocorr(adata, mode="moran", genes=hvg, n_perms=100, n_jobs=1)
adata.uns["moranI"].head(10)

Common mistakes

Previous: a single-cell RNA-seq workflow  ยท  All posts