This function computes gene-level entropy across neighboring cells for a specified assay in a Seurat object. It optionally saves the entropy matrix to file and/or adds it as a new assay named `"assay_entropy"`.

run_entropy(
  seu,
  assay,
  nn_list = NULL,
  nn.name = NULL,
  output_path = NULL,
  add_assay = TRUE,
  k.param = 15,
  npca = 20,
  nfeatures = 3000
)

Arguments

seu

A Seurat object.

assay

Character. Name of the assay to use.

nn_list

Optional named list of neighbor cell indices or names per cell. If NULL, neighbors are computed using PCA.

nn.name

Optional character. If neighbors are already present in the Seurat object, this specifies the name of the neighbor graph to use (e.g. `"SCT"` or `"RNA"`).

output_path

Optional character string. If provided, saves the full entropy matrix to this file (using `qs::qsave()`).

add_assay

Logical. If TRUE (default), adds the entropy matrix to the Seurat object as a new assay called `"assay_entropy"`.

k.param

Integer. Number of nearest neighbors to use when computing the neighbor graph. Default is 15.

npca

Integer. Number of PCA dimensions to use when computing neighbors. Default is 20.

nfeatures

Integer. Number of variable features to select before PCA and neighbor finding. Default is 3000.

Value

If `add_assay = TRUE`, returns the modified Seurat object with a new assay named `"assay_entropy"`. If `add_assay = FALSE`, returns a data frame of mean entropy values per cell.

Examples

# Assuming `pbmc` is a Seurat object with an "RNA" assay:
run_entropy(pbmc_small, assay = "RNA", k.param = 15)
#> INFO [2025-04-25 14:45:09] Starting entropy estimation for assay: RNA
#> Error: object 'pbmc_small' not found