Description Usage Arguments Value Details about testEmptyDrops Details about emptyDrops Handling overdispersion NA values in the results Non-empty droplets versus cells Author(s) References See Also Examples

Distinguish between droplets containing cells and ambient RNA in a droplet-based single-cell RNA sequencing experiment.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ```
testEmptyDrops(
m,
lower = 100,
niters = 10000,
test.ambient = FALSE,
ignore = NULL,
alpha = NULL,
round = TRUE,
by.rank = NULL,
BPPARAM = SerialParam()
)
emptyDrops(m, ...)
## S4 method for signature 'ANY'
emptyDrops(
m,
lower = 100,
retain = NULL,
barcode.args = list(),
round = TRUE,
test.ambient = FALSE,
...,
BPPARAM = SerialParam()
)
## S4 method for signature 'SummarizedExperiment'
emptyDrops(m, ..., assay.type = "counts")
``` |

`m` |
A numeric matrix-like object - usually a dgTMatrix or dgCMatrix -
containing droplet data For |

`lower` |
A numeric scalar specifying the lower bound on the total UMI count, at or below which all barcodes are assumed to correspond to empty droplets. |

`niters` |
An integer scalar specifying the number of iterations to use for the Monte Carlo p-value calculations. |

`test.ambient` |
A logical scalar indicating whether results should be returned for barcodes with totals less than or equal to |

`ignore` |
A numeric scalar specifying the lower bound on the total UMI count, at or below which barcodes will be ignored (see Details for how this differs from |

`alpha` |
A numeric scalar specifying the scaling parameter for the Dirichlet-multinomial sampling scheme. |

`round` |
Logical scalar indicating whether to check for non-integer values in |

`by.rank` |
An integer scalar parametrizing an alternative method for identifying assumed empty droplets - see |

`BPPARAM` |
A BiocParallelParam object indicating whether parallelization should be used. |

`...` |
For the generic, further arguments to pass to individual methods. For the SummarizedExperiment method, further arguments to pass to the ANY method. For the ANY method, further arguments to pass to |

`retain` |
A numeric scalar specifying the threshold for the total UMI count above which all barcodes are assumed to contain cells. |

`barcode.args` |
Further arguments to pass to |

`assay.type` |
Integer or string specifying the assay containing the count matrix. |

`testEmptyDrops`

will return a DataFrame with the following components:

`Total`

:Integer, the total UMI count for each barcode.

`LogProb`

:Numeric, the log-probability of observing the barcode's count vector under the null model.

`PValue`

:Numeric, the Monte Carlo p-value against the null model.

`Limited`

:Logical, indicating whether a lower p-value could be obtained by increasing

`niters`

.

`emptyDrops`

will return a DataFrame like `testEmptyDrops`

, with an additional `FDR`

field.

The metadata of the output DataFrame will contains the ambient profile in `ambient`

, the estimated/specified value of `alpha`

, the specified value of `lower`

(possibly altered by `use.rank`

) and the number of iterations in `niters`

.
For `emptyDrops`

, the metadata will also contain the retention threshold in `retain`

.

`testEmptyDrops`

The `testEmptyDrops`

function first obtains an estimate of the composition of the ambient pool of RNA based on the barcodes with total UMI counts less than or equal to `lower`

(see `?ambientProfileEmpty`

for details).
This assumes that a cell-containing droplet would generally have higher total counts than empty droplets containing RNA from the ambient pool.
Counts for the low-count barcodes are pooled together, and an estimate of the proportion vector for the ambient pool is calculated using `goodTuringProportions`

.
The count vector for each barcode above `lower`

is then tested for a significant deviation from these proportions.

Then, `testEmptyDrops`

will test each barcode for significant deviations from the ambient profile.
The null hypothesis is that transcript molecules are included into droplets by multinomial sampling from the ambient profile.
For each barcode, the probability of obtaining its count vector based on the null model is computed.
Then, `niters`

count vectors are simulated from the null model.
The proportion of simulated vectors with probabilities lower than the observed multinomial probability for that barcode is used to calculate the p-value.

We use this Monte Carlo approach as an exact multinomial p-value is difficult to calculate.
However, the p-value is lower-bounded by the value of `niters`

(Phipson and Smyth, 2010), which can result in loss of power if `niters`

is too small.
Users can check whether this loss of power has any practical consequence by checking the `Limited`

field in the output.
If any barcodes have `Limited=TRUE`

but does *not* reject the null hypothesis, it suggests that `niters`

should be increased.

The stability of the Monte Carlo $p$-values depends on `niters`

, which is only set to a default of 10000 for speed.
Larger values improve stability with the only cost being that of time, so users should set `niters`

to the largest value they are willing to wait for.

The `ignore`

argument can also be set to ignore barcodes with total counts less than or equal to `ignore`

.
This differs from the `lower`

argument in that the ignored barcodes are not necessarily used to compute the ambient profile.
Users can interpret `ignore`

as the minimum total count required for a barcode to be considered as a potential cell.
In contrast, `lower`

is the maximum total count below which all barcodes are assumed to be empty droplets.

`emptyDrops`

The `emptyDrops`

function identifies droplets that are likely to contain cells by calling `testEmptyDrops`

.
The Benjamini-Hochberg correction is applied to the Monte Carlo p-values to correct for multiple testing.
Cells can then be defined by taking all barcodes with significantly non-ambient profiles, e.g., at a false discovery rate of 0.1%.

Barcodes that contain more than `retain`

total counts are always retained.
This ensures that large cells with profiles that are very similar to the ambient pool are not inadvertently discarded.
If `retain`

is not specified, it is set to the total count at the knee point detected by `barcodeRanks`

.
Manual specification of `retain`

may be useful if the knee point was not correctly identified in complex log-rank curves.
Users can also set `retain=Inf`

to disable automatic retention of barcodes with large totals.

All barcodes with total counts above `retain`

are assigned p-values of zero *during correction*, reflecting our assumption that they are true positives.
This ensures that their Monte Carlo p-values do not affect the correction of other genes, and also means that they will have FDR values of zero.
However, their original Monte Carlo p-values are still reported in the output, as these may be useful for diagnostic purposes.

This effect also means that users will not be able to recover the reported `FDR`

by simply running `p.adjust`

on the reported `PValue`

.
Similarly, setting `test.ambient=TRUE`

will also modify the p-values prior to correction, see commentary below.

In general, users should call `emptyDrops`

rather than `testEmptyDrops`

.
The latter is a “no frills” version that is largely intended for use within other functions.

If `alpha`

is set to a positive number, sampling is assumed to follow a Dirichlet-multinomial (DM) distribution.
The parameter vector of the DM distribution is defined as the estimated ambient profile scaled by `alpha`

.
Smaller values of `alpha`

model overdispersion in the counts, due to dependencies in sampling between molecules.
If `alpha=NULL`

, a maximum likelihood estimate is obtained from the count profiles for all barcodes with totals less than or equal to `lower`

.
If `alpha=Inf`

, the sampling of molecules is modelled with a multinomial distribution.

Users can check whether the model is suitable by extracting the p-values for all barcodes with `test.ambient=TRUE`

.
Under the null hypothesis, the p-values for presumed ambient barcodes (i.e., with total counts less than or equal to `lower`

) should be uniformly distributed.
Skews in the p-value distribution are indicative of an inaccuracy in the model and/or its estimates (of `alpha`

or the ambient profile).

`NA`

values in the resultsWe assume that barcodes with total UMI counts less than or equal to `lower`

correspond to empty droplets.
These are used to estimate the ambient expression profile against which the remaining barcodes are tested.
Under this definition, these low-count barcodes cannot be cell-containing droplets and are excluded from the hypothesis testing.
By removing these uninteresting tests, we obtain a modest improvement in detection power for the high-count barcodes.

However, it is still desirable for the number of rows of the output DataFrame to be the same as `ncol(m)`

.
This allows easy subsetting of `m`

based on a logical vector constructed from the output (e.g., to retain all FDR values below a threshold).
To satisfy this requirement, the rows for the excluded barcodes are filled in with `NA`

values for all fields in the output.
We suggest using `which`

to pick barcodes below a FDR threshold, see the Examples.

If `test.ambient=TRUE`

, non-`NA`

p-values will be reported for all barcodes with positive total counts, including those not greater than `lower`

.
This is occasionally useful for diagnostics to ensure that the p-values are well-calibrated for barcodes corresponding to (presumably) empty droplets.
Specifically, if the null hypothesis were true, p-values for low-count barcodes should have a uniform distribution.
Any strong peaks in the p-values near zero indicate that `emptyDrops`

is not controlling the FDR correctly.

Note that, when setting `test.ambient=TRUE`

in `emptyDrops`

, barcodes less than or equal to `lower`

will still have `NA`

values in `FDR`

.
Such barcodes are still explicitly ignored in the correction as these are considered to be uninteresting.
For back-compatibility purposes, setting `test.ambient=NA`

will include these barcodes in the correction.

Technically speaking, `emptyDrops`

is designed to identify barcodes that correspond to non-empty droplets.
This is close to but not quite the same as identifying cells,
as droplets containing cell fragments, stripped nuclei and damaged cells will still be significantly non-empty.
As such, it may often be necessary to perform additional quality control on the significant barcodes;
we suggest doing so using methods from the scater package.

On occasion, `emptyDrops`

may identify many more non-empty droplets than the expected number of cells.
This is probably due to the generation of multiple cell fragments when a single cell is extensively damaged.
In such cases, it is informative to construct a MA plot comparing the average expression between retained low-count barcodes and discarded barcodes to see which genes are driving the differences (and thus contributing to the larger number of non-empty calls).
Mitochondrial and ribosomal genes are typical offenders; the former can be either up or down in the ambient solution, depending on whether the damage was severe enough to dissociate mitochondria from the cell fragments, while the latter is usually down in low-count barcodes due to loss of cytoplasmic RNA in cell fragments.

To mitigate this effect, we can filtering out the problematic genes from the matrix provided to `emptyDrops`

.
This eliminates their effect on the significance calculations and reduces the number of uninteresting non-empty calls,
see https://github.com/MarioniLab/DropletUtils/issues/36 for an example.
Of course, the full set of genes can still be retained for downstream analysis.

Aaron Lun

Lun A, Riesenfeld S, Andrews T, Dao TP, Gomes T, participants in the 1st Human Cell Atlas Jamboree, Marioni JC (2019).
Distinguishing cells from empty droplets in droplet-based single-cell RNA sequencing data.
*Genome Biol.* 20, 63.

Phipson B, Smyth GK (2010).
Permutation P-values should never be zero: calculating exact P-values when permutations are randomly drawn.
*Stat. Appl. Genet. Mol. Biol.* 9:Article 39.

`barcodeRanks`

, for choosing the knee point.

`defaultDrops`

, for an implementation of the cell-calling method used by CellRanger version 2.

`ambientProfileEmpty`

, for more details on estimation of the ambient profile.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ```
# Mocking up some data:
set.seed(0)
my.counts <- DropletUtils:::simCounts()
# Identify likely cell-containing droplets.
out <- emptyDrops(my.counts)
out
is.cell <- out$FDR <= 0.01
sum(is.cell, na.rm=TRUE)
# Subsetting the matrix to the cell-containing droplets.
# (using 'which()' to handle NAs smoothly).
cell.counts <- my.counts[,which(is.cell),drop=FALSE]
dim(cell.counts)
# Check if p-values are lower-bounded by 'niters'
# (increase 'niters' if any Limited==TRUE and Sig==FALSE)
table(Sig=is.cell, Limited=out$Limited)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.