Skip to contents

Sums the density columns of grouped cell types in each niche reducedDim, producing coarser niche covariates (e.g. merging Macrophage subtypes into a single "Macrophage" niche). Cell types absent from groups are retained as their own (singleton) niche.

Usage

mergeNiches(spe, groups, ...)

# S4 method for class 'ANY'
mergeNiches(spe, groups, sigma = NULL, name = "Niche", ...)

Arguments

spe

a SpatialExperiment with niche reducedDims (see buildNiches()).

groups

a named list mapping each merged niche name to a character vector of cell-type column names to sum.

...

ignored.

sigma

a numeric vector of bandwidths to update; NULL (default) updates every name<sigma> reducedDim present.

name

a character, the reducedDim name prefix (default "Niche").

Value

the input spe with merged niche reducedDims.

Details

The group membership is recorded in metadata(spe)$spiDE_niche_groups so that a subsequent fitSpiDE() / nicheDesign() automatically excludes a covariate whenever an index cell type is a member of the merged niche it is tested against (its own density would otherwise contaminate the niche).

Examples

data(toySpiDE)
spe <- toySpiDE
spe <- buildNiches(spe, sigma = 20)
spe <- mergeNiches(spe, groups = list(AC = c("A", "C")), sigma = 20)
colnames(SingleCellExperiment::reducedDim(spe, "Niche20"))
#> [1] "AC" "B"