smoothLabels: k-Nearest neighbor cluster label smoothing.

View source: R/cluster.R

smoothLabelsR Documentation

k-Nearest neighbor cluster label smoothing.

Description

k-Nearest neighbor cluster label smoothing.

Usage

smoothLabels(
  se,
  cluster_names = NULL,
  coord_names = NULL,
  k = 15L,
  prop_thres = 0.5,
  max_iter = 10,
  verbose = TRUE
)

Arguments

se

A SpatialExperiment, SingleCellExperiment or SummarizedExperiment object with cluster labels in colData(se).

cluster_names

A string vector of label names to smooth. If NULL, smooths labels in colData(se) matching /^clust/

coord_names

A string vector specifying the names in colData corresponding to spatial coordinates.

k

An integer scalar specifying number of neighbors for smooething.

prop_thres

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).

max_iter

An integer scalar specifying the max number of smoothing iterations. Set to -1 for smoothing to convergence.

verbose

A logical scalar specifying verbosity.

Details

As described in SpiceMix (https://doi.org/10.1038/s41588-022-01256-z). Implemented for labels that can be coerced to numeric only.

Value

A SpatialExperiment / SingleCellExperiment / SummarizedExperiment object with smoothed cluster labels in colData(se) suffixed with '_smooth'.

Examples

data(rings)
spe <- computeBanksy(rings, assay_name = "counts", M = 1, k_geom = c(15, 30))
spe <- runBanksyPCA(spe, M = 1, lambda = 0.2, npcs = 20)
spe <- clusterBanksy(spe, M = 1, lambda = 0.2, resolution = 1)
spe <- smoothLabels(spe, cluster_names = "clust_M1_lam0.2_k50_res1")


prabhakarlab/Banksy documentation built on July 31, 2024, 7:37 p.m.