| Title: | smoothclust |
|---|---|
| Description: | Method for identification 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. |
| Authors: | Lukas M. Weber [aut, cre] (ORCID: <https://orcid.org/0000-0002-3282-1730>) |
| Maintainer: | Lukas M. Weber <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.9.3 |
| Built: | 2026-07-14 21:43:58 UTC |
| Source: | https://github.com/bioc/smoothclust |
Function for boundary density metric
boundary_density( spatial_coords, labels, k = 6, n_threads = 1, adjust = c("none", "analytic", "permutation"), n_permutations = 1000, seed = NULL )boundary_density( spatial_coords, labels, k = 6, n_threads = 1, adjust = c("none", "analytic", "permutation"), n_permutations = 1000, seed = NULL )
spatial_coords |
Numeric matrix containing spatial coordinates of
points, formatted as nrow = number of points, ncol = 2 (assuming x and y
dimensions). For example, 'spatial_coords = spatialCoords(spe)' if using a
|
labels |
Atomic vector or factor containing cluster labels for each
point. Missing values are not allowed. For example, 'labels <-
colData(spe)$label' if using a |
k |
Number of k nearest neighbors to use in calculation. Default = 6 (e.g. for hexagonal arrangement in 10x Genomics Visium platform). |
n_threads |
Number of threads to use for nearest-neighbor searches. Default = 1. |
adjust |
Composition adjustment to calculate. Options are
|
n_permutations |
Number of random label permutations to use when
|
seed |
Optional random seed to use when |
Function to calculate the raw boundary density metric, defined as the average fraction of nearest neighbors per point that are from a different cluster. This metric can be used to quantify and compare the relative density of the boundaries of clusters or spatial domains. Optional composition adjustments can be used to compare the raw boundary density to an expected value under random relabeling.
Returns a list containing values at each point (i.e. the number of
nearest neighbors that are from a different cluster, the number of nearest
neighbors, and the local raw boundary density) as well as the mean
discordant neighbor count and the sample-level raw boundary density. If
adjust = "analytic", the list also contains the expected boundary
density, relative boundary density, and excess boundary density. If
adjust = "permutation", the list also contains the permutation
mean, standard deviation, relative boundary density, standardized score,
and number of permutations.
spatial_coords <- cbind(c(0, 1, 3, 6), 0) labels <- c("A", "B", "A", "A") # calculate raw boundary density metric res <- boundary_density(spatial_coords, labels, k = 2) str(res) res$n_discordant res$mean_discordant res$boundary_density # calculate analytic composition adjustment res_adj <- boundary_density(spatial_coords, labels, k = 2, adjust = "analytic") res_adj$expected_boundary_density res_adj$relative_boundary_densityspatial_coords <- cbind(c(0, 1, 3, 6), 0) labels <- c("A", "B", "A", "A") # calculate raw boundary density metric res <- boundary_density(spatial_coords, labels, k = 2) str(res) res$n_discordant res$mean_discordant res$boundary_density # calculate analytic composition adjustment res_adj <- boundary_density(spatial_coords, labels, k = 2, adjust = "analytic") res_adj$expected_boundary_density res_adj$relative_boundary_density
Method for identification of spatial domains and spatially-aware clustering.
smoothclust( input, assay_name = "counts", spatial_coords = NULL, method = c("uniform", "kernel", "knn"), bandwidth = 0.05, k = 18, truncate = 0.05, n_threads = 1 )smoothclust( input, assay_name = "counts", spatial_coords = NULL, method = c("uniform", "kernel", "knn"), bandwidth = 0.05, k = 18, truncate = 0.05, n_threads = 1 )
input |
Input data, which can be provided as either a
|
assay_name |
For a |
spatial_coords |
Numeric matrix of spatial coordinates, assumed to contain x coordinates in first column and y coordinates in second column. This argument is only used if the input is a numeric matrix. |
method |
Method used for smoothing. Options are |
bandwidth |
Bandwidth parameter for smoothing, expressed as proportion
of width or height (whichever is greater) of tissue area. Only used for
|
k |
Number of nearest neighbors parameter for |
truncate |
Truncation threshold parameter if |
n_threads |
Number of threads to use for nearest-neighbor searches. Default = 1. |
Method for identification of spatial domains and spatially-aware clustering in spatial transcriptomics data.
Method for identification 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.
Returns spatially smoothed expression values, which can then be used
as the input for further downstream analyses. Results are returned either
as a SpatialExperiment object containing a new assay named
<assay_name>_smooth (e.g. counts_smooth or
logcounts_smooth), or as a numeric matrix, depending on the input
type.
set.seed(123) input <- matrix(rpois(60, lambda = 10), nrow = 10) spatial_coords <- cbind(rep(1:3, each = 2), rep(1:2, times = 3)) # smooth a numeric expression matrix out <- smoothclust(input, spatial_coords = spatial_coords, bandwidth = 0.6) dim(out)set.seed(123) input <- matrix(rpois(60, lambda = 10), nrow = 10) spatial_coords <- cbind(rep(1:3, each = 2), rep(1:2, times = 3)) # smooth a numeric expression matrix out <- smoothclust(input, spatial_coords = spatial_coords, bandwidth = 0.6) dim(out)