GitHub
Back to all tutorials

Spatial analysis

Spatial Analysis - Visium HD

This tutorial analyzes a 10x Genomics Visium HD dataset in CellPilot: loading the Space Ranger output, overlaying the tissue image, exploring clusters and marker genes on the tissue, re-analyzing a large dataset with sketching, naming cell types, asking about regions you draw, cell-cell interactions, and BANKSY spatial domains. Every command is typed in the chat box of the AI Assistant panel; no code or API key is needed. The screenshots come from CellPilot 2.1.0 running this exact dataset.

Input data

The example is the 10x Genomics Visium HD CytAssist Gene Expression Library of Mouse Kidney (FFPE), analyzed with Space Ranger 4.0. The commands below download the cell-segmented Space Ranger output and the full-resolution tissue image of the section (about 6.7 GB in total); you can also download them from the 10x Genomics dataset page.

mkdir -p visiumhd_mouse_kidney
cd visiumhd_mouse_kidney
BASE=https://cf.10xgenomics.com/samples/spatial-exp/4.0.1/Visium_HD_Mouse_Kidney
SAMPLE=Visium_HD_Mouse_Kidney
curl -O ${BASE}/${SAMPLE}_segmented_outputs.tar.gz
curl -O ${BASE}/${SAMPLE}_tissue_image.btf

1. Prepare the Space Ranger folder

tar xzf ${SAMPLE}_segmented_outputs.tar.gz

This creates a segmented_outputs/ folder: Space Ranger's cells, segmented from the H&E image. It holds cell_segmentations.geojson (cell outlines), filtered_feature_cell_matrix.h5 (gene counts per cell), spatial/ (positions and images) and analysis/ (Space Ranger's clusters and UMAP). Keep the structure as it is; the archive is no longer needed.

Your own data

Select the folder produced by spaceranger count (the sample folder or its outs folder); no renaming is needed. CellPilot uses segmented_outputs when it is there, otherwise the 8 µm bins of binned_outputs; to use another bin size, select its square_* folder.

2. Load the dataset

  1. Open CellPilot.
  2. In the Data Loader & Model panel, set Data Type to Spatial, Platform to 10x Visium HD and Data to Single sample.
  3. Click Browse and select the visiumhd_mouse_kidney folder (the folder that contains segmented_outputs/) or segmented_outputs itself.
  4. Wait for the data to load (about half a minute on our test computer).

CellPilot shows two views: the UMAP View and the Spatial View, which draws every cell at its position in the tissue, colored by cluster. The clusters and the UMAP are Space Ranger's own (graph-based clustering, numbered from 1). Visium HD measures the whole transcriptome, so every gene can be plotted; no imputation is needed.

What you should see: 277,728 cells, 19,070 genes and 25 clusters. how many cells are there answers 277,728.
CellPilot after loading the Visium HD mouse kidney dataset
After loading: UMAP View (left) and Spatial View (right) with Space Ranger's 25 clusters.

3. Add the tissue image

  1. In the Spatial View, click Add Image.
  2. Under Histology Image (TIFF), click Select Image... and choose Visium_HD_Mouse_Kidney_tissue_image.btf.
  3. Leave Transformation Matrix (CSV) empty.
  4. Click Load Image.

This is the microscope image Space Ranger used for this section (a BigTIFF, 26,720 × 31,062 pixels), so the cells already line up with it and no matrix is needed. CellPilot converts the image into tiles for fast zooming; the first time this takes about a minute, and the tiles are kept, so loading the image again is quick. The image shows the whole section; the cells cover the part that was measured.

The Add Histology Image dialog
The Add Histology Image dialog: the image, no matrix.
Visium HD clusters on the tissue image
The clusters on the tissue image.

Another image of the section

An image from another microscope must first be registered to the Visium HD coordinates. Align it with Loupe Browser and Space Ranger (see the 10x Genomics Visium HD alignment tutorial), or load it with a 3 × 3 transformation matrix CSV that maps the image onto the Visium HD coordinates.

4. Explore clusters and marker genes

Tell me about cluster 14
Find markers for cluster 14
Plot Umod
Plot Nphs2
Violin plot Umod
Dotplot Nphs2 Lrp2 Umod Slc12a3 Aqp2
Change color to lightgray lemonchiffon red

Gene plots color the cells on both the UMAP and the tissue. The dot plot follows the nephron: Nphs2 (podocytes of the glomerulus), Lrp2 (proximal tubule), Umod (thick ascending limb of the loop of Henle), Slc12a3 (distal convoluted tubule) and Aqp2 (collecting duct). The first question about a cluster compares all 19,070 genes across 277,728 cells and takes about 3 minutes; later marker questions take about a minute.

Cluster 14 has 5,531 cells (2.0%); its top marker genes are Pvalb, Lhfpl1, Htr3a and Slc12a3, and CellPilot names it a distal tubule cell, closest to DCT1 (distal convoluted tubule 1). Umod is highest in the band of thick ascending limbs between cortex and inner medulla. Podocytes form no cluster of their own in Space Ranger's clustering, so the Nphs2 column of the dot plot is nearly empty, but Plot Nphs2 shows the glomeruli as round spots in the cortex.
Marker genes of cluster 14
Find markers for cluster 14: the marker table (left) next to the tissue.
Umod on the UMAP and the tissue
Plot Umod: the thick ascending limb.
Nphs2 on the tissue
Plot Nphs2: the glomeruli in the cortex.
Violin plot of Umod
Violin plot Umod: highest in clusters 10 and 2. With many clusters the plot scrolls sideways in a narrow window.
Dot plot of five nephron markers
Dotplot Nphs2 Lrp2 Umod Slc12a3 Aqp2, recolored light gray–lemon chiffon–red.

5. Adjust analysis parameters (sketching)

Rerun the analysis by setting min gene = 50
Rerun umap with min dist = 0.4
Recluster the cells using resolution = 2.0

For Visium HD datasets with 50,000 cells or more, CellPilot re-analyzes with a sketch: it picks 50,000 representative cells (keeping rare ones), computes the UMAP and the clusters on them, and gives every other cell the cluster of its nearest sketch cells. This keeps large tissues responsive and preserves rare populations. A new UMAP keeps the clusters; a new resolution reuses the sketch, so re-clustering takes seconds. CellPilot numbers its own clusters from 0.

With min gene = 50, 276,707 cells remain. At resolution 2.0, how many clusters are there answers 28 clusters. On our test computer, re-running the analysis took about 7 minutes, the UMAP about 4.5 minutes and re-clustering 18 seconds.

6. Identify cell types

Annotate all clusters
yes

CellPilot compares every cluster with built-in reference atlases and names the most similar cell type; for this section it recognizes the kidney and uses three mouse kidney atlases. yes renames the clusters; clusters with the same name are merged. With names, the region questions below answer in cell types. Check the names against the marker genes: names ending in ? are not clear-cut, and the small separate group named P-EC-AVR Scd1+ has the genes of fat cells (Scd1, Fabp4, Cfd), most likely fat next to the kidney.

The organ is recognized as kidney (mouse kidney atlases of Lake 2025, Wu 2022 and Kirita 2020). Of the 28 clusters, 6 are clear, 15 probable and 7 not clear-cut; after yes they become 21 names along the nephron: proximal tubule (PT-S1, PT-S2, PT-S3), thin limbs (DTL2, ATL), thick ascending limbs (C-TAL, M-TAL), distal convoluted tubule (DCT1, DCT2), connecting tubule (CNT), collecting duct (IMCD, intercalated cells), fibroblasts, vascular smooth muscle cells and pericytes, and endothelial cells.
Clusters named with cell types
After yes: cell type names on the UMAP and the tissue.

You can change cluster names at any time, for example if an automatic name looks wrong: Rename P-EC-AVR Scd1+ to Adipocytes.

7. Select a region and ask about it

Click the rectangle (or freehand) selection tool at the top right of the Spatial View, next to Add Image, and drag over the tissue. Then ask:

What is this region?
What cell types are in the selected region?
Find markers for the selected spatial region

What cell types are in the selected region? lists the clusters (cell types once named) of the cells inside it; the other two compare its cells with all other cells and list the genes higher inside.

The answers depend on where you draw. For the region in the figure (4,319 cells in the cortex): 30.4% PT-S1, 17.4% PT-S1/S2 and 11.8% PT-S2 (proximal tubule), then endothelial cells, CNT, fibroblasts and DCT1; top marker genes Spp2, Slc5a2, Slc5a12, Slc6a19, Nox4 and Gatm, genes of the early proximal tubule.
A selected region on the tissue
A drawn region (dashed rectangle) and its marker genes (left).

8. Cell-cell interactions between regions

Draw a second region, then ask:

Run cell-cell interaction analysis across selected regions

CellPilot tests ligand–receptor pairs (CellChat database) between the cells of the drawn regions and reports the significant interactions.

Between the cortex region and a second region in the inner medulla (7,484 cells): 365 significant interactions in 101 pathways, in about 20 seconds; the strongest is App–Tnfrsf21 (APP pathway, region 2 to region 1), then App–Cd74, App–Sorl1 and collagen IV–integrin pairs (Col4a5–ITGAV_ITGB8).
Ligand-receptor interactions between two regions
Interactions between the two drawn regions.

9. Spatial domains with BANKSY

Run BANKSY region segmentation
Show regions
What cell types are in region 0?
Rename region 0 to cortex

BANKSY finds tissue domains from each cell's own expression and that of its neighbors. The regions can be shown, described by their cell types, renamed, and used for marker analysis like drawn regions.

BANKSY takes about 18 minutes for these 276,707 cells. It finds 6 regions (numbered from 0) that follow the zones of the kidney from the outside in: region 0 the cortex, region 2 the outer stripe of the outer medulla (PT-S3 and thick ascending limbs), regions 3 and 4 the inner stripe (medullary thick ascending limbs and thin limbs), region 5 the inner medulla (collecting ducts, thin limbs and fibroblasts) and region 1 the vessels and fibroblasts, mostly around the pelvis. Region 0 holds 82,853 cells, 59% of them proximal tubule (PT-S1 23.1%, PT-S2 18.6%, PT-S1/S2 16.9%) and 8.8% fibroblasts: the cortex, so it is renamed cortex. The same data and settings give the same regions in every run; with other settings or your own data, check each region's cell types (What cell types are in region N?) before naming it.
BANKSY spatial domains
Show regions: the BANKSY domains on the UMAP and the tissue, with region 0 named cortex.

10. Save and revisit results

CellPilot saves the analysis (clusters, names and BANKSY regions) as cellpilot_results.json in the data folder. When you load the same folder again, CellPilot asks whether to load the previous results.