Skip to contents

A function to perform a weighted, adaptive smoothing of gene expression based on the heterogeneity of the cell neighbourhood. Heterogeneous neighbourhoods are smoothed less with higher weights given to cells belonging to same initial group. Homogeneous neighbourhoods are smoothed more with similar weights given to most cells.

Usage

adaptiveSmoothing(spe, nnCells, NN, kernel, spread, threads)

Arguments

spe

SpatialExperiment object with logcounts, PCA, 'putative cell type' groups, and entropy outputs included.

nnCells

a character matrix of NN nearest neighbours - rows are cells and columns are their nearest neighbours ranged from closest to farthest neighbour. For sort = TRUE, the neighbours belonging to the same 'putative cell type' group as the cell are moved closer to it.

NN

an integer for the number of neighbourhood cells the function should consider. The value must be greater than or equal to 1. Default value is 30.

kernel

a character for type of distribution to be used. The two valid values are "G" or "E". G for Gaussian distribution, and E for exponential distribution. Default value is "G".

spread

a numeric value for distribution spread, represented by standard deviation for Gaussian distribution and rate for exponential distribution. Default value is 0.05 for Gaussian distribution and 20 for exponential distribution.

threads

a numeric value for the number of CPU cores to be used for the analysis. Default value set to 1.

Value

SpatialExperiment object including smoothed gene expression values as another assay.

Examples

data(example)

# requires matrix containing NN nearest neighbour cell labels (nnCells),
# generated using the neighbourDetect() function
spe <- clustSIGNAL::adaptiveSmoothing(spe, nnCells, NN = 30, kernel = "G",
                                      spread = 0.05, threads = 1)
#> [1] "Smoothing performed. NN = 30 Kernel = G Spread = 0.05 Time 01:20:45"
spe
#> class: SpatialExperiment 
#> dim: 351 1000 
#> metadata(0):
#> assays(2): logcounts smoothed
#> rownames(351): Abcc4 Acp5 ... Zfp57 Zic3
#> rowData names(0):
#> colnames(1000): embryo2_Pos29_cell110_z2 embryo2_Pos29_cell117_z2 ...
#>   embryo2_Pos50_cell361_z5 embryo2_Pos50_cell372_z2
#> colData names(5): uniqueID sample_id entropy nsCluster initCluster
#> reducedDimNames(1): PCA
#> mainExpName: NULL
#> altExpNames(0):
#> spatialCoords names(2) : X Y
#> imgData names(1): sample_id