Skip to contents

Merge probability matrix based on annotations

Usage

mergeByGroup(pm, group_df, continuousAnnotation = FALSE)

Arguments

pm

A numeric matrix. Probability matrix generated by the soft_max function.

group_df

A matrix. If continuousAnnotation = FALSE, it should be a character (or factor) matrix of discrete labels matching pm. If continuousAnnotation = TRUE, it should be a numeric fuzzy-annotation matrix (cells × types), where rows sum to 1.

continuousAnnotation

Logical. If TRUE, interprets group_df as fuzzy probabilities instead of discrete labels.

Value

A probability matrix, describing the probability of each cell being in each cellular neighborhood.

Examples


data("spe_test")

spe <- readHoodData(spe, anno_col = "celltypes")

fnc <- findNearCells(spe, k = 100)

pm <- scanHoods(fnc$distance)
#> Tau is set to: 22747.4

pm2 <- mergeByGroup(pm, fnc$cells)

# Fuzzy annotation example:
# Create a 10×3 fuzzy annotation, rows sum to 1
fuzzy_df <- matrix(runif(ncol(pm) * 3), ncol = 3)
fuzzy_df <- sweep(fuzzy_df, 1, rowSums(fuzzy_df), "/")
colnames(fuzzy_df) <- paste0("celltype_", seq(3))
pm_cont <- mergeByGroup(pm, fuzzy_df, continuousAnnotation = TRUE)