Repository navigation
03 Quick Start
kroy3 edited this page Nov 20, 2026
·
3 revisions
This chapter runs a complete analysis on simulated data in which the true contamination is known, so you can see Decant recover it.
library(Decant)
sim <- simulate_experiment(seed = 1)
dim(sim$observed)
#> [1] 600 1200
dim(sim$empty)
#> [1] 600 4000-
simulate_experiment(seed = 1)creates a contaminated experiment with 600 genes, 1,200 cells of six cell types, and 4,000 empty droplets. Theseedmakes the result identical every time. -
sim$observedholds the contaminated cell counts (genes × cells). -
sim$emptyholds the empty droplets (genes × droplets). - The simulation also stores the answer:
sim$truth(the clean counts),sim$rho_true(each cell's true contamination) andsim$labels(the cell types).
res <- decant(sim$observed, sim$empty, clusters = sim$labels)
res
#> <decant> 600 genes x 1200 cells
#> modules : cluster_rho, correction_bayes_absent
#> rho : median 0.199 (10%-90%: 0.117-0.305)-
decant()takes the cell counts, the empty droplets and the cluster labels, and returns a result object. - Printing the result shows its size, the steps that ran (
modules) and a summary of the estimated contamination: the median cell is 19.9% ambient, and 80% of cells lie between 11.7% and 30.5%.
summary(res$rho)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.02389 0.14950 0.19933 0.20574 0.25223 0.55303
summary(sim$rho_true)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.0148 0.1371 0.1907 0.1970 0.2473 0.5317
cor(res$rho, sim$rho_true)
#> [1] 0.9760583-
res$rhois the estimated contamination of every cell. - The estimates sit slightly above the truth here (median 0.199 against 0.191), and the correlation of 0.98 shows Decant ranks cells correctly.
score_correction(sim$observed, sim$observed, sim$truth)$l1_error
#> [1] 0.2451949
score_correction(sim$observed, res$corrected, sim$truth)$l1_error
#> [1] 0.04837206-
score_correction()compares a matrix with the clean truth. Itsl1_erroradds up every count that is wrong, whether contamination left behind or real signal removed, as a fraction of the true total. - Without correction (first line) 24.5% of counts are wrong. After Decant the error falls to 4.8%.
corrected <- res$corrected
all(corrected <= sim$observed)
#> [1] TRUE-
res$correctedhas the same genes, cells and class as the input and can be used wherever you would use raw counts. - The check confirms that no count was increased.
# Requires your own data
library(Decant)
raw <- read_10x_counts("sample/outs/raw_feature_bc_matrix")
cells <- colnames(read_10x_counts("sample/outs/filtered_feature_bc_matrix"))
d <- split_droplets(raw, cells = cells)
res <- decant(d$cells, d$empties, clusters = my_clusters)-
read_10x_counts()reads a Cell Ranger folder into a sparse matrix. - The filtered matrix is read only for its column names, the barcodes Cell Ranger called as cells.
-
split_droplets()separates the raw matrix into cells and empty droplets. -
my_clustersis a vector with one cluster label per cell, in the same order as the columns ofd$cells, for example from Seurat.
Chapter 4 explains each of these steps.
Previous: Chapter 2, Key Concepts | Next: Chapter 4, Preparing Your Data
Decant user guide · Repository · Report an issue · MIT License
Decant User Guide
- Preface
- 1. Installation
- 2. Key Concepts
- 3. Quick Start
- 4. Preparing Your Data
- 5. Running Decant
- 6. Seurat Integration
- 7. Estimation and Correction
- 8. Multi-Sample Experiments
- 9. Differential Expression
- 10. Splice-Aware and Genotype Modules
- 11. Diagnostics and Troubleshooting
- 12. Validation and Benchmarks
- 13. Function Reference
- 14. Cell-Cell Communication