Recovering intra-sample doublets
Aaron Lun
infinite.monkeys.with.keyboards@gmail.com2024-09-19
Source:vignettes/recoverDoublets.Rmd
recoverDoublets.Rmd
tl;dr
See the relevant section of the OSCA
book for an example of the recoverDoublets()
function
in action on real data. A toy example is also provided in
?recoverDoublets
.
Mathematical background
Consider any two cell states and forming a doublet population . We will focus on the relative frequency of inter-sample to intra-sample doublets in . Given a vector containing the proportion of cells from each sample in state , and assuming that doublets form randomly between pairs of samples, the expected proportion of intra-sample doublets in is . Subtracting this from 1 gives us the expected proportion of inter-sample doublets . Similarly, the expected proportion of inter-sample doublets in is just .
Now, let’s consider the observed proportion of events in each state that are known doublets. We have as there are no other events in beyond actual doublets. On the other hand, we expect that due to presence of a large majority of non-doublet cells in (same for ). If we assume that and , the observed proportion should be larger than and . (The last assumption is not always true but the should give us enough wiggle room to be robust to violations.)
The above reasoning motivates the use of the proportion of known
doublet neighbors as a “doublet score” to identify events that are most
likely to be themselves doublets. recoverDoublets()
computes the proportion of known doublet neighbors for each cell by
performing a
-nearest
neighbor search against all other cells in the dataset. It is then
straightforward to calculate the proportion of neighboring cells that
are marked as known doublets, representing our estimate of
for each cell.
Obtaining explicit calls
While the proportions are informative, there comes a time when we
need to convert these into explicit doublet calls. This is achieved with
,
the vector of the proportion of cells from each sample across the entire
dataset (i.e., samples
). We assume that all cell states
contributing to doublet states have proportion vectors equal to
,
such that the expected proportion of doublets that occur between cells
from the same sample is
.
We then solve
for , where is the number of observed inter-sample doublets. The top events with the highest scores (and, obviously, are not already inter-sample doublets) are marked as putative intra-sample doublets.
Discussion
The rate and manner of doublet formation is (mostly) irrelevant as we condition on the number of events in . This means that we do not have to make any assumptions about the relative likelihood of doublets forming between pairs of cell types, especially when cell types have different levels of “stickiness” (or worse, stick specifically to certain other cell types). Such convenience is only possible because of the known doublet calls that allow us to focus on the inter- to intra-sample ratio.
The most problematic assumption is that required to obtain from . Obtaining a better estimate would require, at least, the knowledge of the two parent states for each doublet population. This can be determined with some simulation-based heuristics but it is likely to be more trouble than it is worth.
In this theoretical framework, we can easily spot a case where our
method fails. If both
and
are unique to a given sample, all events in
will be intra-sample doublets. This means that no events in
will ever be detected as inter-sample doublets, which precludes their
detection as intra-sample doublets by recoverDoublets
. The
computational remedy is to augment the predictions with simulation-based
methods (e.g., scDblFinder()
) while the experimental remedy
is to ensure that multiplexed samples include technical or biological
replicates.
Session information
## R version 4.4.1 (2024-06-14)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.5 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0
##
## locale:
## [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
## [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
## [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
## [10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
##
## time zone: UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] BiocStyle_2.32.1
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.37 desc_1.4.3 R6_2.5.1
## [4] bookdown_0.40 fastmap_1.2.0 xfun_0.47
## [7] cachem_1.1.0 knitr_1.48 htmltools_0.5.8.1
## [10] rmarkdown_2.28 lifecycle_1.0.4 cli_3.6.3
## [13] sass_0.4.9 pkgdown_2.1.1 textshaping_0.4.0
## [16] jquerylib_0.1.4 systemfonts_1.1.0 compiler_4.4.1
## [19] tools_4.4.1 ragg_1.3.3 bslib_0.8.0
## [22] evaluate_1.0.0 yaml_2.3.10 BiocManager_1.30.25
## [25] jsonlite_1.8.8 rlang_1.1.4 fs_1.6.4