Analysis of Visium data with singleCellHaystack"

knitr::opts_chunk$set(
    fig.align = "center",
    message = TRUE,
    warning = TRUE,
  collapse = TRUE,
  comment = "#>",
  fig.align = 'center'
)

library(Seurat)
library(SeuratData)
library(singleCellHaystack)

set.seed(1)

We can apply singleCellHaystack to spatial transcriptomics data as well. Here we use Seurat and the spatial transcriptomics data available in the SeuratData package. For this example we use 10x Genomics Visium platform brain data. For more details about analyzing spatial transcriptomics with Seurat take a look at their spatial transcriptomics vignette here.

Preparing input data

library(Seurat)
library(SeuratData)
library(singleCellHaystack)

We focus on the anterior1 slice.

if (!"stxBrain" %in% SeuratData::InstalledData()[["Dataset"]]) {
  SeuratData::InstallData("stxBrain")
}

anterior1 <- LoadData("stxBrain", type = "anterior1")
anterior1

We filter genes with less 10 cells with non-zero counts. This reduces the computational time by eliminating very lowly expressed genes.

counts <- GetAssayData(anterior1, slot = "counts")
sel.ok <- Matrix::rowSums(counts > 1) > 10

anterior1 <- anterior1[sel.ok, ]
anterior1

We can plot the total number of counts per bead, superimposed on the image of the brain.

SpatialFeaturePlot(anterior1, features = "nCount_Spatial")

We normalize the data we use log normalization.

anterior1 <- NormalizeData(anterior1)

Running haystack on the spatial coordinates

The two inputs to singleCellHaystack are 1) the gene expression data and 2) the spatial coordinates of the Visium spots. Please note that we are not using an embedding as input space here, but the actual 2D coordinates of spots inside the tissue. Since this Visium dataset only contains about 2.7k spots and 12k genes, running singleCellHaystack should only take about a minute.

dat.expression <- GetAssayData(anterior1, slot = "data")
dat.coord <- GetTissueCoordinates(anterior1, "anterior1")

set.seed(123)
res <- haystack(dat.coord, dat.expression)

We can check the top genes with spatial biased distribution.

show_result_haystack(res.haystack = res, n = 10)

And we can visualize the expression of the 6 top-scoring genes in the spatial plot.

top6 <- show_result_haystack(res.haystack = res, n = 6)
SpatialFeaturePlot(anterior1, features = rownames(top6))


Try the singleCellHaystack package in your browser

Any scripts or data that you put into this service are public.

singleCellHaystack documentation built on Dec. 28, 2022, 1:29 a.m.