Skip to contents

Derives a per-sample library-size offset (LS) by computing, for each (sample, cell type), a log size factor from total counts over total area, centring these per cell type, and taking the median across cell types for each sample. The offset is written to a per-cell colData column so it can enter the model design as a nuisance covariate.

Usage

computeSizeFactors(spe, ...)

# S4 method for class 'ANY'
computeSizeFactors(
  spe,
  cell_type = "cell_type",
  sample_id = "sample_id",
  count = "nCount",
  area = "Area",
  name = "LS",
  ...
)

Arguments

spe

a SpatialExperiment.

...

ignored.

cell_type

a character, the colData column of cell type labels.

sample_id

a character, the colData column of sample identifiers.

count

a character, the colData column of per-cell total counts (e.g. total UMI or negative-probe counts).

area

a character, the colData column of per-cell area.

name

a character, the colData column to write the LS offset to (default "LS").

Value

the input spe with a per-cell name column in colData.

Examples

data(toySpiDE)
spe <- toySpiDE
spe <- computeSizeFactors(spe, count = "nCount", area = "Area")
head(spe$LS)
#> [1] -0.008037579 -0.008037579 -0.008037579 -0.008037579 -0.008037579
#> [6] -0.008037579