knitr::opts_chunk$set(echo = TRUE, dev = "png")
Droplet-based microfluidic devices have become widely used to perform single-cell RNA sequencing (scRNA-seq). However, ambient RNA present in the cell suspension can be aberrantly counted along with a cell’s native mRNA and result in cross-contamination of transcripts between different cell populations. DecontX is a Bayesian method to estimate and remove contamination in individual cells. DecontX assumes the observed expression of a cell is a mixture of counts from two multinomial distributions: (1) a distribution of native transcript counts from the cell’s actual population and (2) a distribution of contaminating transcript counts from all other cell populations captured in the assay. Overall, computational decontamination of single cell counts can aid in downstream clustering and visualization. Only the expression profile of "real" cells after cell calling are required to run DecontX. Empty cell droplet information (low expression cell barcodes before cell calling) are not needed.
celda can be installed from Bioconductor:
if (!requireNamespace("BiocManager", quietly = TRUE)) { install.packages("BiocManager") } BiocManager::install("celda")
The package can be loaded using the library
command.
library(celda)
DecontX can take either SingleCellExperiment
object from package SingleCellExperiment package or a single counts matrix as input. decontX
will attempt to convert any input matrix to class dgCMatrix
from package Matrix before beginning any analyses.
We will utlize the 10X PBMC 4K dataset as an example. This can be easily retrieved from the package TENxPBMCData. Make sure the the column names are set before running decontX.
# Install TENxPBMCData if is it not already if (!requireNamespace("TENxPBMCData", quietly = TRUE)) { if (!requireNamespace("BiocManager", quietly = TRUE)) { install.packages("BiocManager") } BiocManager::install("TENxPBMCData") } # Load PBMC data library(TENxPBMCData) pbmc4k <- TENxPBMCData("pbmc4k") colnames(pbmc4k) <- paste(pbmc4k$Sample, pbmc4k$Barcode, sep = "_") rownames(pbmc4k) <- rowData(pbmc4k)$Symbol_TENx
To run decontX with a SingleCellExperiment object, simply use the following command.
pbmc4k <- decontX(x = pbmc4k)
The contamination can be found in the colData(pbmc4k)$decontX_contamination
and the decontaminated counts can be accessed with decontXcounts(pbmc4k)
. If the input object was a matrix, make sure to save the output into a variable with a different name (e.g. result). The result object will be a list with contamination in result$contamination
and the decontaminated counts in result$decontXcounts
.
DecontX creates a UMAP which we can use to plot the cluster labels automatically identified in the analysis. Note that the clustering approach used here is designed to find "broad" cell types rather than individual cell subpopulations within a cell type.
umap <- reducedDim(pbmc4k, "decontX_UMAP") plotDimReduceCluster(x = pbmc4k$decontX_clusters, dim1 = umap[, 1], dim2 = umap[, 2])
The percentage of contamination in each cell can be plotting on the UMAP to visualize what what clusters may have higher levels of ambient RNA.
plotDecontXContamination(pbmc4k)
Known marker genes can also be plotted on the UMAP to identify the cell types for each cluster. We will use CD3D and CD3E for T-cells, LYZ, S100A8, and S100A9 for monocytes, CD79A, CD79B, and MS4A1 for B-cells, GNLY for NK-cells, and PPBP for megakaryocytes.
library(scater) pbmc4k <- logNormCounts(pbmc4k) plotDimReduceFeature(as.matrix(logcounts(pbmc4k)), dim1 = umap[, 1], dim2 = umap[, 2], features = c("CD3D", "CD3E", "GNLY", "LYZ", "S100A8", "S100A9", "CD79A", "CD79B", "MS4A1"), exactMatch = TRUE)
The percetage of cells within a cluster that have detectable expression of marker genes can be displayed in a barplot. Markers for cell types need to be supplied in a named list. First, the detection of marker genes in the original counts
assay is shown:
markers <- list(Tcell_Markers = c("CD3E", "CD3D"), Bcell_Markers = c("CD79A", "CD79B", "MS4A1"), Monocyte_Markers = c("S100A8", "S100A9", "LYZ"), NKcell_Markers = "GNLY") cellTypeMappings <- list(Tcells = 2, Bcells = 5, Monocytes = 1, NKcells = 6) plotDecontXMarkerPercentage(pbmc4k, markers = markers, groupClusters = cellTypeMappings, assayName = "counts")
We can then look to see how much DecontX removed aberrant expression of marker genes in each cell type by changing the assayName
to decontXcounts
:
plotDecontXMarkerPercentage(pbmc4k, markers = markers, groupClusters = cellTypeMappings, assayName = "decontXcounts")
Percentages of marker genes detected in other cell types were reduced or completely removed. For example, the percentage of cells that expressed Monocyte marker genes was greatly reduced in T-cells, B-cells, and NK-cells.
The original counts and decontamined counts can be plotted side-by-side by listing multiple assays in the assayName
parameter. This option is only available if the data is stored in SingleCellExperiment
object.
plotDecontXMarkerPercentage(pbmc4k, markers = markers, groupClusters = cellTypeMappings, assayName = c("counts", "decontXcounts"))
Some helpful hints when using plotDecontXMarkerPercentage
:
groupCluster
parameter, which also needs to be a named list. If groupCluster
is used, cell clusters not included in the list will be excluded in the barplot. For example, if we wanted to group T-cells and NK-cells together, we could set cellTypeMappings <- list(NK_Tcells = c(2,6), Bcells = 5, Monocytes = 1)
threshold
parameter.SingleCellExperiment
, then you will need to supply the original counts matrix or the decontaminated counts matrix as the first argument to generate the barplots. Another useful way to assess the amount of decontamination is to view the expression of marker genes before and after decontX
across cell types. Here we view the monocyte markers in each cell type. The violin plot shows that the markers have been removed from T-cells, B-cells, and NK-cells, but are largely unaffected in monocytes.
plotDecontXMarkerExpression(pbmc4k, markers = markers[["Monocyte_Markers"]], groupClusters = cellTypeMappings, ncol = 3)
Some helfpul hints when using plotDecontXMarkerExpression
:
groupClusters
works the same way as in plotDecontXMarkerPercentage
.groupClusters
). Therefore, you may want to keep the number of markers small in each plot and call the function multiple times for different sets of marker genes. plotDots = TRUE
and/or log tranform the points on the fly by setting log1p = TRUE
. SingleCellExperiment
. Therefore you could also examine normalized expression of the original and decontaminated counts. For example:pbmc4k <- scater::logNormCounts(pbmc4k, exprs_values = "decontXcounts", name = "dlogcounts") plotDecontXMarkerExpression(pbmc4k, markers = markers[["Monocyte_Markers"]], groupClusters = cellTypeMappings, ncol = 3, assayName = c("logcounts", "dlogcounts"))
The ability of DecontX to accurately identify contamination is dependent on the cell cluster labels. DecontX assumes that contamination for a cell cluster comes from combination of counts from all other clusters. The default clustering approach used by DecontX tends to select fewer clusters that represent broader cell types. For example, all T-cells tend to be clustered together rather than splitting naive and cytotoxic T-cells into separate clusters. Custom cell type labels can be suppled via the z
parameter if some cells are not being clustered appropriately by the default method.
There are ways to force decontX
to estimate more or less contamination across a dataset by manipulating the priors. The delta
parameter is a numeric vector of length two. It is the concentration parameter for the Dirichlet distribution which serves as the prior for the proportions of native and contamination counts in each cell. The first element is the prior for the proportion of native counts while the second element is the prior for the proportion of contamination counts. These essentially act as pseudocounts for the native and contamination in each cell. If estimateDelta = TRUE
, delta
is only used to produce a random sample of proportions for an initial value of contamination in each cell. Then delta
is updated in each iteration. If estimateDelta = FALSE
, then delta
is fixed with these values for the entire inference procedure. Fixing delta
and setting a high number in the second element will force decontX
to be more aggressive and estimate higher levels of contamination in each cell at the expense of potentially removing native expression. For example, in the previous PBMC example, we can see what the estimated delta
was by looking in the estimates:
metadata(pbmc4k)$decontX$estimates$all_cells$delta
Setting a higher value in the second element of delta and estimateDelta = FALSE
will force decontX
to estimate higher levels of contamination per cell:
pbmc4k.delta <- decontX(pbmc4k, delta = c(9, 20), estimateDelta = FALSE) plot(pbmc4k$decontX_contamination, pbmc4k.delta$decontX_contamination, xlab = "DecontX estimated priors", ylab = "Setting priors to estimate higher contamination") abline(0, 1, col = "red", lwd = 2)
sessionInfo()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.