Tuesday, June 30, 2026

Visualizing Spatially Variable Genes on Tissue: sq.pl.spatial_scatter

In the previous post we ran Moran's I on the 10x Genomics mouse brain Visium dataset and ranked 500 genes by spatial autocorrelation. The top hit was Itpka at I = 0.674. But a number alone doesn't tell you much. This post puts those genes on the tissue.

The setup

Same preprocessed AnnData object from post 5 — 500 HVGs, normalized, log1p transformed, spatial neighbors computed. We pass the top 5 SVGs directly to sq.pl.spatial_scatter.

import squidpy as sq
import scanpy as sc

adata = sc.read_h5ad("visium_hne_adata.h5ad")
sc.pp.highly_variable_genes(adata, n_top_genes=500, flavor="cell_ranger")
adata = adata[:, adata.var.highly_variable].copy()
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
sq.gr.spatial_neighbors(adata)

top5 = ["Itpka", "Fezf1", "Baiap3", "Shox2", "Slc30a3"]

sq.pl.spatial_scatter(
    adata,
    color=top5,
    ncols=3,
    save="svg_top5_combined.png"
)

sq.pl.spatial_scatter reads spot coordinates from adata.obsm["spatial"] and colors each spot by expression value. The colormap runs from purple (low) to yellow (high), matching scanpy's default viridis scale.

Results

Top 5 spatially variable genes visualized on mouse brain Visium tissue

Top 5 SVGs by Moran's I score plotted on the coronal mouse brain section. Each spot represents one Visium capture area (~55 µm diameter).

What each pattern tells us

Itpka (I = 0.674) — hippocampus arc
The high-expression spots cluster tightly in the upper-left region of the section — the hippocampal formation. Itpka encodes IP3 3-kinase A, which is highly enriched in hippocampal neurons and involved in calcium signaling. The spatial pattern matches known anatomy exactly: a compact, curved structure that stands out from surrounding cortex.

Fezf1 (I = 0.634) — deep cortical layer band
Expression is restricted to a narrow band along the lower edge of the cortical mantle. Fezf1 is a transcription factor required for the identity of layer 5 and layer 6 corticospinal neurons. The thin stripe visible here is consistent with cortical laminar organization — layers 5/6 run as a continuous band at the base of the neocortex.

Baiap3 (I = 0.622) — subcortical focal cluster
High expression concentrated in the lower-right, corresponding to a subcortical nucleus. Baiap3 (brain-specific angiogenesis inhibitor 1-associated protein 3) is a synaptic scaffolding protein expressed in specific subcortical populations. The focal, non-laminar pattern distinguishes it from the cortical layer markers above.

Shox2 (I = 0.611) — thalamic/hypothalamic domain
A broad cluster in the lower-left, covering what appears to be thalamic or hypothalamic territory. Shox2 marks specific nuclei in this region and is involved in the development of thalamic relay circuits. The expression domain is spatially coherent but larger than the single-nucleus pattern of Baiap3.

Slc30a3 (I = 0.600) — cortical band, broader than Fezf1
Expression forms a wider band than Fezf1 and extends further across the cortical surface. Slc30a3 encodes a zinc transporter enriched in excitatory cortical neurons. Unlike the deep-layer specificity of Fezf1, Slc30a3 appears to span multiple cortical layers, which explains the broader stripe.

Pattern categories

Looking across the five maps, two distinct spatial modes emerge:

Laminar patterns (Fezf1, Slc30a3) — horizontal bands parallel to the cortical surface. These genes define layer identity. The Moran's I is high because spots within a layer are neighbors of other spots in the same layer, and they all share expression of the same laminar marker.

Regional patterns (Itpka, Baiap3, Shox2) — compact clusters corresponding to anatomically defined structures. These genes are on in one region and off everywhere else. This on/off contrast across space is exactly what Moran's I detects: neighboring spots agree on expression, and that agreement is strong.

Both modes score high on Moran's I, but for slightly different reasons. Laminar genes have many neighbors (a full band of spots), while regional genes have fewer but with very high expression contrast against background.

A note on the colormap

The viridis colormap scales independently per gene, so the yellow in Itpka (max ~80) is not comparable to yellow in Fezf1 (max ~14). This is the default behavior and is fine for qualitative comparison of spatial pattern, but misleading if you want to compare expression levels across genes. For cross-gene level comparison, fix the colormap range with vmax:

sq.pl.spatial_scatter(adata, color="Itpka", vmin=0, vmax=20)

What's next

The next logical step is neighborhood enrichment analysis — looking at which cell types or clusters tend to be spatially adjacent. That's sq.gr.nhood_enrichment, and it answers a different question: not which genes vary across space, but which populations co-locate.

Full code at github.com/lociven/spatiabio-tutorials.

Get the complete pack

Squidpy Complete Analysis Pack — 10 Notebooks

All 10 notebooks from this series in one download — SVGs, neighborhood enrichment, co-occurrence, ligand-receptor, and the complete pipeline. Verified and ready to run on your own data.

Get it for $19 →

No comments:

Post a Comment

I Gave Claude Science One Prompt. It Ran a Full Spatial Analysis.

By Lociven · SpatiaBio · July 2, 2026 I gave Claude Science AI Workbench — Anthropic's new scientific analysis platform — a single...