1 Introduction

smoothclust is a method for segmentation of spatial domains and spatially-aware clustering in spatial transcriptomics data. The method generates spatial domains with smooth boundaries by smoothing gene expression profiles across neighboring spatial locations, followed by unsupervised clustering. Spatial domains consisting of consistent mixtures of cell types may then be further investigated by applying cell type compositional analyses or differential analyses.

2 Installation

The smoothclust package can be installed from Bioconductor as follows (using R version 4.4 onwards). This is the recommended installation for most users. Additional details are shown on the Bioconductor package landing page.


The latest development version of the package can also be installed from the devel version of Bioconductor or from GitHub.

3 Input data format

Input data can be provided either as a SpatialExperiment object within the Bioconductor framework, or as numeric matrices of expression values and spatial coordinates. See help file (?smoothclust) for details.

In the example workflow below, we assume the input is in SpatialExperiment format.

4 Tutorial

The example workflow in this section demonstrates how to run smoothclust to generate spatial domains with smooth boundaries for a dataset from the 10x Genomics Visium platform.


Load dataset from STexampleData package:

# load data
spe <- Visium_humanDLPFC()
## see ?STexampleData and browseVignettes('STexampleData') for documentation
## loading from cache
# keep spots over tissue
spe <- spe[, colData(spe)$in_tissue == 1]

## [1] 33538  3639
## [1] "counts"

Run smoothclust using default parameter settings, which have been selected to be appropriate for Visium data from human tissue.

The method for smoothing can be specified by providing the method argument, with available options uniform, kernel, and knn. Additional arguments can be used to set parameter values, including bandwidth, k, and truncate, depending on the choice of method. For more details, see the function documentation (?smoothclust) or the paper (in preparation).

# run smoothclust
spe <- smoothclust(spe)

The smoothed expression counts are stored in a new assay named counts_smooth:

# check output object
## [1] "counts"        "counts_smooth"

Calculate log-transformed normalized counts (logcounts) on the smoothed expression counts. Here, the argument assay.type = "counts_smooth" specifies that we want to calculate logcounts using the smoothed counts from smoothclust.

# calculate logcounts
spe <- logNormCounts(spe, assay.type = "counts_smooth")

## [1] "counts"        "counts_smooth" "logcounts"

Run clustering. We use a standard clustering workflow from single-cell data, consisting of k-means clustering on the top principal components (PCs) calculated on the set of top highly variable genes (HVGs) with logcounts as the input.

We use a relatively small number of clusters for demonstration purposes in this example:

# preprocessing steps for clustering

# remove mitochondrial genes
is_mito <- grepl("(^mt-)", rowData(spe)$gene_name, ignore.case = TRUE)
## is_mito
## 33525    13
spe <- spe[!is_mito, ]
## [1] 33525  3639
# select top highly variable genes (HVGs)
dec <- modelGeneVar(spe)
top_hvgs <- getTopHVGs(dec, prop = 0.1)
## [1] 986
spe <- spe[top_hvgs, ]
## [1]  986 3639
# dimensionality reduction

# compute PCA on top HVGs
spe <- runPCA(spe)
# run k-means clustering
k <- 5
clust <- kmeans(reducedDim(spe, "PCA"), centers = k)$cluster
## clust
##    1    2    3    4    5 
##  967 1574  492  272  334
colLabels(spe) <- factor(clust)

Plot clusters / spatial domains generated by the smoothclust workflow:

# color palettes
pal8 <- "libd_layer_colors"
pal36 <- unname(palette.colors(36, "Polychrome 36"))

# plot clusters / spatial domains
plotSpots(spe, annotate = "label", pal = pal8)