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.
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)
haystack
on the spatial coordinatesThe 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.