Calculates the percentage contribution of a specified set of molecules to the total counts within the count matrix of the given assay.

computeCountPercentage(
  object,
  regex = NULL,
  molecules = NULL,
  var_name = NULL,
  assay_name = activeAssay(object),
  overwrite = FALSE
)

Arguments

object

An object of class SPATA2 or, in case of S4 generics, objects of classes for which a method has been defined.

regex

Character value. A regular expression with which to create the set of molecules (e.g. '^MT-.*' to subset human mitochondrial genes).

molecules

Character vector. Instead of providing a regular expression the set of molecules can be specified directly.

var_name

Character value. The name of the new meta feature.

assay_name

Only relevant if the SPATA2 object contains more than one assay: Denotes the assay of interest and thus the molecular modality to use. Defaults to the active assay as set by activateAssay().

overwrite

Logical value. Must be TRUE to allow overwriting.

Value

The updated input object, containing the added, removed or computed results.

Details

The equivalent of Seurat::PercentageFeatureSet(). Usage differs. See examples.

Examples


library(SPATA2)
library(SPATAData)
library(patchwork)

object <- downloadSpataObject("MGH258")

# compute the percentage contribution of mitochondrial genes
object <- computeCountPercentage(object, regex = "MT-.*", var_name = "perc_mit")

plotSurface(object, color_by = "perc_mit") +
plotDensityPlot(object, variables = "perc_mit")

# keep only spots with less than 20% mitochondrial counts
object <- filterSpataObject(object, perc_mit < 20)

# new outlier identification necessary?
plotSurface(object, color_by = "tissue_section")