Browse code

Adding bgBatch to each batch cycle inference workflow

Yuan authored on 13/01/2022 18:08:39
Showing 1 changed files

... ...
@@ -170,6 +170,8 @@ setMethod("decontX", "SingleCellExperiment", function(x,
170 170
     # Remove cells with the same ID between x and the background matrix
171 171
     background <- .checkBackground(x = x, background = background,
172 172
                                    logfile = logfile, verbose = verbose)
173
+    # Does bgBatch needs to be checked?
174
+    
173 175
     if (is.null(bgAssayName)) {
174 176
       bgAssayName <- assayName
175 177
     }
... ...
@@ -392,7 +394,7 @@ setMethod(
392 394
   nC <- ncol(counts)
393 395
   allCellNames <- colnames(counts)
394 396
 
395
-  ## Set up final deconaminated matrix
397
+  ## Set up final decontaminated matrix
396 398
   estRmat <- Matrix::Matrix(
397 399
     data = 0,
398 400
     ncol = totalCells,
... ...
@@ -404,6 +406,9 @@ setMethod(
404 406
   ## Generate batch labels if none were supplied
405 407
   if (is.null(batch)) {
406 408
     batch <- rep("all_cells", nC)
409
+    
410
+    # When no batch, batchBackground can have max 1 batch, depending on if
411
+    # countsBackground supplied
407 412
     batchBackground <- rep("all_cells", ncol(countsBackground))
408 413
   }
409 414
   runParams$batch <- batch
... ...
@@ -439,6 +444,7 @@ setMethod(
439 444
 
440 445
     zBat <- NULL
441 446
     countsBat <- counts[, batch == bat]
447
+    bgBat <- countsBackground[, bactchBackgound == bat]
442 448
 
443 449
     ## Convert to sparse matrix
444 450
     if (!inherits(countsBat, "dgCMatrix")) {
... ...
@@ -451,9 +457,9 @@ setMethod(
451 457
       )
452 458
       countsBat <- methods::as(countsBat, "dgCMatrix")
453 459
     }
454
-    if (!is.null(countsBackground)) {
455
-      if (!inherits(countsBackground, "dgCMatrix")) {
456
-        countsBackground <- methods::as(countsBackground, "dgCMatrix")
460
+    if (!is.null(bgBat)) {
461
+      if (!inherits(bgBat, "dgCMatrix")) {
462
+        bgBat <- methods::as(bgBat, "dgCMatrix")
457 463
       }
458 464
     }
459 465
 
... ...
@@ -465,7 +471,7 @@ setMethod(
465 471
         counts = countsBat,
466 472
         z = zBat,
467 473
         batch = bat,
468
-        countsBackground = countsBackground,
474
+        countsBackground = bgBat,
469 475
         maxIter = maxIter,
470 476
         delta = delta,
471 477
         estimateDelta = estimateDelta,
... ...
@@ -484,7 +490,7 @@ setMethod(
484 490
           counts = countsBat,
485 491
           z = zBat,
486 492
           batch = bat,
487
-          countsBackground = countsBackground,
493
+          countsBackground = bgBat,
488 494
           maxIter = maxIter,
489 495
           delta = delta,
490 496
           estimateDelta = estimateDelta,