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 Slide-seqV2 hippocampus 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 ssHippo slice.
if (!"ssHippo" %in% SeuratData::InstalledData()[["Dataset"]]) { SeuratData::InstallData("ssHippo") } ssHippo <- LoadData("ssHippo") ssHippo
We filter genes with less 10 cells with non-zero counts. This reduces the computational time by eliminating very lowly expressed genes.
counts <- GetAssayData(ssHippo, slot = "counts") sel.ok <- Matrix::rowSums(counts > 1) > 10 ssHippo <- ssHippo[sel.ok, ] ssHippo
We can plot the total number of counts per bead, superimposed on the image of the brain.
SpatialFeaturePlot(ssHippo, features = "nCount_Spatial")
We normalize the data we use log normalization.
ssHippo <- NormalizeData(ssHippo)
haystack
on the spatial coordinatesThe two inputs to singleCellHaystack
are 1) the gene expression data and 2) the spatial coordinates of the Slide-seq V2 pucks. 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 dataset contains about 53k spots and 11k genes, a run of singleCellHaystack
can take a few minutes.
dat.expression <- GetAssayData(ssHippo, slot = "data") dat.coord <- GetTissueCoordinates(ssHippo) set.seed(123) res <- haystack(dat.coord[,1:2], 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(ssHippo, features = rownames(top6))
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.