Spatial
This page covers spatial transcriptomics and imaging mass cytometry. Notes start from the files the instrument software writes, such as Visium, Xenium or CosMx output, and keep each spot or cell at its position in the tissue.
Prompts to try
Find spatial domains in a human DLPFC Visium section. Send:
Load Visium_humanDLPFC from STexampleData and keep the spots on the tissue.Then:
Preprocess the data for BayesSpace with 15 principal components.Then:
Cluster the spots into seven domains with nrep 1000 and a burn-in of 100, and set a seed.Cell types or tissue domains with BANKSY. Send:
Load the hippocampus VeraFISH data that comes with Banksy and put it in a SpatialExperiment.Then:
What does BANKSY's lambda parameter control?Build a neighbourhood graph for tumour imaging mass cytometry data. Send:
Load the single-cell object from IMMUcan_2022_CancerExample in imcdatasets. Which columns hold the image, the cell type and the coordinates?Then:
Build a k-nearest-neighbour spatial graph within each image, using cell_x and cell_y as coordinates.Read raw Xenium output. The XeniumOutput example in SFEData is a small set of raw output files from a 10x Xenium run:
Download the XeniumOutput example from SFEData.
What a note can do
Notes hold the data in a SpatialExperiment or SpatialFeatureExperiment, which keep the counts together with positions, images and cell outlines, and draw it on the tissue with ggspavis. They follow the OSTA book and the tidy spatial workshop.
- Many platforms. Notes work with Visium, Slide-seq, the original Spatial Transcriptomics array, seqFISH, MERFISH and MERSCOPE, CosMx, Xenium, STARmap PLUS and imaging mass cytometry, and read raw Xenium and CosMx output into R.
- Quality control. Notes flag low-quality spots or cells, and SpotSweeper finds local outliers and tissue damage.
- Spatially variable genes. nnSVG finds genes whose level follows a pattern across the tissue.
- Tissue regions. BayesSpace and BANKSY group spots or cells into regions, using their neighbours as well as their genes.
- Patterns in space. Voyager and spdep compute measures such as Moran’s I and Getis-Ord to show where a gene or score clusters.
- Neighbours. hoodscanR, imcRtools and spicyR test which cell types sit together more often than by chance.
- Mixtures. SPOTlight and spacexr estimate which cell types make up each spot.
Reports on Roihu lists the CSC tools for work on sequencing reads.
Example notes

- A first look at a Visium brain section: what is stored where, and genes drawn on the tissue image.
- Spot-level quality control on Visium: which spots to remove, checked against the tissue.
- Spatially variable genes with nnSVG: genes with a pattern in space.
- Spatial domains with BayesSpace: regions compared with the known brain layers.
- Cell types versus tissue domains with BANKSY: one parameter moves the clustering between the two.
- Which cells sit next to each other in tumours?: neighbour tests on imaging mass cytometry.
- From raw Xenium files to an object: instrument output read into an R object with cell outlines.
- Cell classes across slices of the hypothalamus: a MERFISH atlas across several slices.