Perform unsupervised spatially-informed clustering on the spots/cells of a ST sample

STclust(
  x = NULL,
  ws = 0.025,
  dist_metric = "euclidean",
  linkage = "ward.D",
  ks = "dtc",
  topgenes = 2000,
  deepSplit = F
)

Arguments

x

an STlist with normalized expression data

ws

a double (0-1) indicating the weight to be applied to spatial distances. Defaults to 0.025

dist_metric

the distance metric to be used. Defaults to 'euclidean'. Other options are the same as in wordspace::dist.matrix

linkage

the linkage method applied to hierarchical clustering. Passed to hclust and defaults to 'ward.D'

ks

the range of k values to assess. Defaults to dtc, meaning cutreeDynamic is applied

topgenes

the number of genes with highest spot-to-spot expression variation. The variance is calculated via Seurat::FindVariableFeatures.

deepSplit

a logical or integer (1-4), to be passed to cutreeDynamic and control cluster resolution

Value

an STlist with cluster assignments

Details

The function takes an STlist and calculates euclidean distances between cells or spots based on the x,y spatial locations, and the expression of the top variable genes (Seurat::FindVariableFeatures). The resulting distances are weighted by applying 1-ws to the gene expression distances and ws to the spatial distances. Hierarchical clustering is performed on the sum of the weighted distance matrices. The STclust method allows for identification of tissue niches/domains that are spatially cohesive.

Examples

# Using included melanoma example (Thrane et al.)
library('spatialGE')
data_files <- list.files(system.file("extdata", package="spatialGE"), recursive=T, full.names=T)
count_files <- grep("counts", data_files, value=T)
coord_files <- grep("mapping", data_files, value=T)
clin_file <- grep("thrane_clinical", data_files, value=T)
melanoma <- STlist(rnacounts=count_files[c(1,3)], spotcoords=coord_files[c(1,3)], samples=clin_file)
#> Warning: Sample ST_mel1_rep2 was not found among the count/coordinate files.
#> Warning: Sample ST_mel2_rep2 was not found among the count/coordinate files.
#> Warning: Sample ST_mel3_rep1 was not found among the count/coordinate files.
#> Warning: Sample ST_mel3_rep2 was not found among the count/coordinate files.
#> Warning: Sample ST_mel4_rep1 was not found among the count/coordinate files.
#> Warning: Sample ST_mel4_rep2 was not found among the count/coordinate files.
#> Found matrix data
#> Matching gene expression and coordinate data...
#> Converting counts to sparse matrices
#> Completed STlist!
#> 
melanoma <- transform_data(melanoma, method='log')
melanoma <- STclust(melanoma, ws=c(0, 0.025))
#> STclust started.
#> 
#> Found more than one class "dist" in cache; using the first, from namespace 'BiocGenerics'
#> Also defined by ‘spam’
#> Found more than one class "dist" in cache; using the first, from namespace 'BiocGenerics'
#> Also defined by ‘spam’
#> STclust completed in 0.05 min.
#> 
STplot(melanoma, ws=0.025, samples='ST_mel1_rep1', ptsize=1)
#> $ST_mel1_rep1_stclust_spw0.025_dsplFalse

#>