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
- Open CellPilot.
- In the Data Loader & Model panel, set Data Type to Spatial, Platform to 10x Visium HD and Data to Single sample.
- Click Browse and select the
visiumhd_mouse_kidneyfolder (the folder that containssegmented_outputs/) orsegmented_outputsitself. - 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.
how many cells are there answers 277,728.
3. Add the tissue image
- In the Spatial View, click Add Image.
- Under Histology Image (TIFF), click Select Image... and choose
Visium_HD_Mouse_Kidney_tissue_image.btf. - Leave Transformation Matrix (CSV) empty.
- 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.
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.
Plot Nphs2 shows the glomeruli as round spots in the cortex.
Find markers for cluster 14: the marker table (left) next to the tissue.
Plot Umod: the thick ascending limb.
Plot Nphs2: the glomeruli in the cortex.
Violin plot Umod: highest in clusters 10 and 2. With many clusters the plot scrolls sideways in a narrow window.
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.
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.
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.
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.
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.
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.
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.
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.