mergeNiches

Merge niche cell-type columns into groups

Description

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 signature '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").

Details

The group membership is recorded in metadata(spe)$spiDE_niche_groups (per niche reducedDim) so that a subsequent fitSpiDE() never tests an index cell type against a merged niche it is a member of (its own density would otherwise contaminate the niche).

Value

the input spe with merged niche reducedDims.

Examples

library("spiDE")

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