Skip to content

Commit

Permalink
enforced known doublets in class (plger#70), fixed BPPARAM serialize …
Browse files Browse the repository at this point in the history
…error on large single samples
  • Loading branch information
plger committed Mar 23, 2023
1 parent 2245624 commit df9910e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: scDblFinder
Type: Package
Title: scDblFinder
Version: 1.13.9
Version: 1.13.10
Authors@R: c(
person("Pierre-Luc", "Germain", email="[email protected]", role=c("cre","aut"), comment=c(ORCID="0000-0003-3418-4218")),
person("Aaron", "Lun", email="[email protected]", role="ctb"))
Expand Down
18 changes: 10 additions & 8 deletions R/scDblFinder.R
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ scDblFinder <- function(
if(!is.null(clusters)) ex <- getExpectedDoublets(clusters, dbr)

if(verbose) message("Evaluating kNN...")
d <- .evaluateKNN(pca, ctype, ado2, expected=ex, k=k, BPPARAM=BPPARAM)
d <- .evaluateKNN(pca, ctype, ado2, expected=ex, k=k)

#if(characterize) knn <- d$knn ## experimental
d <- d$d
Expand Down Expand Up @@ -494,14 +494,12 @@ scDblFinder <- function(
return(sce_out)
}
rowData(orig)$scDblFinder.selected <- row.names(orig) %in% sel_features
.scDblAddCD(orig, d)
.scDblAddCD(orig, d, known=knownDoublets)
}

#' @importFrom BiocNeighbors AnnoyParam
.evaluateKNN <- function(pca, ctype, origins, expected=NULL, k,
BPPARAM=SerialParam()){
knn <- suppressWarnings(findKNN(pca, max(k), BPPARAM=BPPARAM,
BNPARAM=AnnoyParam()))
.evaluateKNN <- function(pca, ctype, origins, expected=NULL, k){
knn <- suppressWarnings(findKNN(pca, max(k), BNPARAM=AnnoyParam()))
hasOrigins <- length(unique(origins))>1
knn$type <- matrix(as.integer(ctype)[knn$index]-1L, nrow=nrow(knn$index))
if(hasOrigins) knn$orig <- matrix(origins[knn$index], nrow=nrow(knn[[1]]))
Expand Down Expand Up @@ -757,7 +755,7 @@ scDblFinder <- function(

# add the relevant fields of the scDblFinder results table to the SCE
#' @importFrom stats relevel
.scDblAddCD <- function(sce, d){
.scDblAddCD <- function(sce, d, known=NULL){
fields <- c("sample","cluster","class","score","ratio","weighted",
"difficulty","cxds_score","mostLikelyOrigin","originAmbiguous",
"origin.prob", "origin.call", "origin.2ndBest")
Expand All @@ -766,8 +764,12 @@ scDblFinder <- function(
for(f in fields){
if(!is.null(d[[f]])) sce[[paste0("scDblFinder.",f)]] <- d[[f]]
}
if(!is.null(sce$scDblFinder.class)) sce$scDblFinder.class <-
if(!is.null(sce$scDblFinder.class)){
print(table(known))
if(!is.null(known)) sce$scDblFinder.class[known] <- "doublet"
sce$scDblFinder.class <-
relevel(as.factor(sce$scDblFinder.class),"singlet")
}
if(is(d,"DataFrame") && !is.null(metadata(d)$scDblFinder.stats))
metadata(sce)$scDblFinder.stats <- metadata(d)$scDblFinder.stats
sce
Expand Down
4 changes: 4 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Changes in version 1.13.10 (2023-03-23)
+ fixed serializing error in multithreading large single samples
+ enforced provided knownDoublets to also be classified as such even in discard mode (issue #70)

Changes in version 1.13.7 (2023-01-09)
+ added possibility to provide the genes/features to use, updated docs

Expand Down

0 comments on commit df9910e

Please sign in to comment.