campbio / decontX

Methods for decontamination of single cell data
MIT License
29 stars 1 forks source link

how to remove contamination cells based on decontX #20

Closed BenxiaHu closed 4 months ago

BenxiaHu commented 5 months ago

how to remove contamination cells (cell barcodes) based on decontX?

joshua-d-campbell commented 4 months ago

Hello @BenxiaHu, There is a column colData of the SingleCellExperiment called "decontX_contamination" that gives the estimated levels of contamination for each cell. You can filter the cells based on this vector. Here is an example:

# Load libraries
library(decontX)
library(SingleCellExperiment)

# Run decontX
s <- simulateContamination(seed = 12345)
sce <- SingleCellExperiment(list(counts = s$observedCounts))
sce <- decontX(sce)

# Keep cells with less than 30% contamination
sce.filter <- sce[,sce$decontX_contamination < 0.3]

The threshold that you use will depend on your dataset. It is a good idea to generate the decontX plots as shown in the tutorial to get a sense of the distribution of the contamination and what threshold you want to use.