k-Nearest neighbor cluster label smoothing.
smoothLabels(
se,
cluster_names = NULL,
coord_names = NULL,
k = 15L,
prop_thres = 0.5,
max_iter = 10,
verbose = TRUE
)A SpatialExperiment,
SingleCellExperiment or SummarizedExperiment
object with cluster labels in colData(se).
A string vector of label names to smooth. If NULL, smooths labels in colData(se) matching /^clust/
A string vector specifying the names in colData
corresponding to spatial coordinates.
An integer scalar specifying number of neighbors for smooething.
A numeric scalar \(\in [0,1]\) specifying a label proportions threshold If the fraction of neighbors with a certain label exceeds this proportion, change the label of the current sample (default: 0.5).
An integer scalar specifying the max number of smoothing iterations. Set to -1 for smoothing to convergence.
A logical scalar specifying verbosity.
A SpatialExperiment / SingleCellExperiment / SummarizedExperiment
object with smoothed cluster labels in colData(se) suffixed with
'_smooth'.
As described in SpiceMix (https://doi.org/10.1038/s41588-022-01256-z). Implemented for labels that can be coerced to numeric only.
data(rings)
spe <- runBanksyPCA(rings, assay_name = "counts", lambda = 0.2, npcs = 20)
#> Computing neighbors...
#> Spatial mode is kNN_median
#> Parameters: k_geom=15
#> Done
#> Building sparse weight matrix
#> Computing scaling parameters for own expression
#> Computing clipping excess for own expression
#> Computing scaling params and clipping for H0
#> H0 genes requiring clipping: 0 / 50
#> Clipping corrections: own=0 H0=0 entries
#> Computing BANKSY PCA (20 PCs) via C++ irlba (work=27)
#> iter=1 mprod=54 sv[20]=8.5000e+00 t=0s
#> iter=2 mprod=68 sv[20]=1.1893e+01 t=0s
#> iter=5 mprod=110 sv[20]=1.4406e+01 t=0s
#> iter=8 mprod=152 sv[20]=1.4489e+01 t=0s
#> Converged: iter=8, mprod=152
#> Done.
spe <- clusterBanksy(spe, lambda = 0.2, resolution = 1)
spe <- smoothLabels(spe, cluster_names = "clust_M0_lam0.2_k50_res1")
#> Iteration 1
#> Change: 21
#> Iteration 2
#> Change: 16
#> Iteration 3
#> Change: 13
#> Iteration 4
#> Change: 6
#> Iteration 5
#> Change: 3
#> Iteration 6
#> Change: 0