## ----load, include=FALSE, echo=FALSE------------------------------------------
library(scDblFinder)
set.seed(123)

## ----scDblFinder--------------------------------------------------------------
# we first generate example data:
sce <- mockDoubletSCE(ncells=c(100,150,200), ngenes=500, dbl.rate=0.15)
# we call doublets (somewhat quickly):
sce <- scDblFinder(sce, artificialDoublets = 300, clusters="cluster", threshold=0.5)

## ----mostLikely1--------------------------------------------------------------
table(call=sce$scDblFinder.class,
      mostLikelyOrigin=sce$scDblFinder.mostLikelyOrigin)

## ----compareKnn---------------------------------------------------------------
isDoublet <- which(sce$type=="doublet")
table(prediction=sce$scDblFinder.mostLikelyOrigin[isDoublet],
      truth=sce$origin[isDoublet])

## ----classifier---------------------------------------------------------------
# to keep things quick here, with cap it to 20 rounds: 
clf <- identifyDoubletOrigins(sce, clusters="cluster", max_rounds = 20, verbose = FALSE)

## ----compareClassifier--------------------------------------------------------
table(prediction=clf$calls, truth=colData(sce)[names(clf$calls), "origin"])

## -----------------------------------------------------------------------------
clf$stats

## -----------------------------------------------------------------------------
doubletPairwiseEnrichment(clf$stats)

## -----------------------------------------------------------------------------
sessionInfo()

