Skip to contents

Ambient RNA decontamination with decontX

Usage

RunDecontX(
  srt,
  assay = "RNA",
  group.by = NULL,
  batch = NULL,
  background = NULL,
  background_assay = NULL,
  bg_batch = NULL,
  assay_name = "decontXcounts",
  store_assay = TRUE,
  round_counts = FALSE,
  data_type = NULL,
  seed = 11,
  ...,
  verbose = TRUE
)

Arguments

srt

A Seurat object.

assay

Assay to decontaminate.

group.by, batch

Cell cluster and batch labels passed to decontX::decontX(). Column name, cell-aligned vector, or NULL.

background

Background / empty-droplet input: a Seurat object, SingleCellExperiment, or count matrix.

background_assay

Assay used when background is a Seurat or SingleCellExperiment. NULL uses assay (Seurat) or "counts" (SCE).

bg_batch

Batch labels for background.

assay_name, store_assay, round_counts

Store rounded decontaminated counts as a new assay.

data_type

Optional CheckDataType() result, used internally to avoid rescanning the count matrix.

seed

Random seed.

...

Passed to decontX::decontX().

verbose

Whether to print messages.

Value

A Seurat object with decontX contamination in meta.data and optional decontaminated counts in a new assay.

Examples

data(pancreas_sub)
pancreas_sub <- RunStandardWorkflow(pancreas_sub)
#>  [2026-08-30 04:56:02] Start standard processing workflow...
#>  [2026-08-30 04:56:02] Checking a list of <Seurat>...
#> ! [2026-08-30 04:56:03] Data 1/1 of the `srt_list` is "unknown"
#> Warning: Data 1/1 of the `srt_list` is "unknown"
#>  [2026-08-30 04:56:03] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on 1/1 of `srt_list`...
#>  [2026-08-30 04:56:03] Perform `FindVariableFeatures()` on 1/1 of `srt_list`...
#>  [2026-08-30 04:56:03] Use the separate HVF from `srt_list`
#>  [2026-08-30 04:56:03] Number of available HVF: 2000
#>  [2026-08-30 04:56:03] Finished check
#>  [2026-08-30 04:56:03] Perform `ScaleData()`
#>  [2026-08-30 04:56:03] Perform pca linear dimension reduction
#>  [2026-08-30 04:56:03] Use stored estimated dimensions 1:23 for Standardpca
#>  [2026-08-30 04:56:04] Perform `Seurat::FindClusters()` with `cluster_algorithm = 'louvain'` and `cluster_resolution = 0.6`
#>  [2026-08-30 04:56:04] Reorder clusters...
#>  [2026-08-30 04:56:04] Skip `log1p()` because `layer = data` is not "counts"
#>  [2026-08-30 04:56:04] Perform umap nonlinear dimension reduction
#>  [2026-08-30 04:56:12] Standard processing workflow completed
pancreas_sub <- RunDecontX(
  pancreas_sub,
  group.by = "CellType"
)
#>  [2026-08-30 04:56:12] Running decontX
#>  [2026-08-30 04:56:12] Data type is raw counts
#> Warning: 'librarySizeFactors' is deprecated.
#> Use 'scrapper::centerSizeFactors' instead.
#> See help("Deprecated")
#> Warning: 'normalizeCounts' is deprecated.
#> Use 'scrapper::normalizeCounts' instead.
#> See help("Deprecated")
#>  [2026-08-30 04:56:25] decontX contamination (median/mean/max): 0.0272 / 0.0875 / 0.6737
#>  [2026-08-30 04:56:25] decontX assay stored as decontXcounts
#>  [2026-08-30 04:56:25] decontX decontamination completed

FeatureStatPlot(
  pancreas_sub,
  stat.by = "decontX_contamination"
)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's colour values.


FeatureDimPlot(
  pancreas_sub,
  features = "decontX_contamination"
)