Browse code

Fixed bug related to factors/integers for z/y cluster labels within internal functions

Joshua D. Campbell authored on 22/10/2022 00:27:29
Showing 1 changed files
... ...
@@ -534,7 +534,7 @@ setMethod("recursiveSplitCell",
534 534
       verbose = FALSE,
535 535
       reorder = reorder)
536 536
     currentK <- length(unique(celdaClusters(modelInitial)$z)) + 1
537
-    overallZ <- celdaClusters(modelInitial)$z
537
+    overallZ <- as.integer(celdaClusters(modelInitial)$z)
538 538
     resList <- list(modelInitial)
539 539
     while (currentK <= maxK) {
540 540
       # previousY <- overallY
... ...
@@ -574,14 +574,14 @@ setMethod("recursiveSplitCell",
574 574
       # If the number of clusters is still "currentK", then keep the
575 575
       # reordering, otherwise keep the previous configuration
576 576
       if (length(unique(celdaClusters(tempModel)$z)) == currentK) {
577
-        overallZ <- celdaClusters(tempModel)$z
577
+        overallZ <- as.integer(celdaClusters(tempModel)$z)
578 578
       } else {
579 579
         overallZ <- tempSplit$z
580 580
         ll <- .logLikelihoodcelda_CG(
581 581
           counts,
582 582
           s,
583 583
           overallZ,
584
-          celdaClusters(tempModel)$y,
584
+          as.integer(celdaClusters(tempModel)$y),
585 585
           currentK,
586 586
           L,
587 587
           alpha,
... ...
@@ -590,7 +590,7 @@ setMethod("recursiveSplitCell",
590 590
           gamma
591 591
         )
592 592
         tempModel <- methods::new("celda_CG",
593
-          clusters = list(z = overallZ, y = celdaClusters(tempModel)$y),
593
+          clusters = list(z = overallZ, y = as.integer(celdaClusters(tempModel)$y)),
594 594
           params = list(
595 595
             K = as.integer(currentK),
596 596
             L = as.integer(L),
... ...
@@ -670,7 +670,7 @@ setMethod("recursiveSplitCell",
670 670
       reorder = reorder
671 671
     )
672 672
     currentK <- length(unique(celdaClusters(modelInitial)$z)) + 1
673
-    overallZ <- celdaClusters(modelInitial)$z
673
+    overallZ <- as.integer(celdaClusters(modelInitial)$z)
674 674
     ll <- .logLikelihoodcelda_C(
675 675
       counts, s, overallZ, currentK,
676 676
       alpha, beta
... ...
@@ -707,7 +707,7 @@ setMethod("recursiveSplitCell",
707 707
       # Handle rare cases where a population has no cells after running
708 708
       # the model
709 709
       if (length(unique(celdaClusters(tempModel)$z)) == currentK) {
710
-        overallZ <- celdaClusters(tempModel)$z
710
+        overallZ <- as.integer(celdaClusters(tempModel)$z)
711 711
       } else {
712 712
         overallZ <- tempSplit$z
713 713
       }
... ...
@@ -772,7 +772,7 @@ setMethod("recursiveSplitCell",
772 772
       reorder = reorder
773 773
     )
774 774
     currentK <- length(unique(celdaClusters(modelInitial)$z)) + 1
775
-    overallZ <- celdaClusters(modelInitial)$z
775
+    overallZ <- as.integer(celdaClusters(modelInitial)$z)
776 776
     resList <- list(modelInitial)
777 777
     while (currentK <= maxK) {
778 778
       tempSplit <- .singleSplitZ(counts,
... ...
@@ -798,7 +798,7 @@ setMethod("recursiveSplitCell",
798 798
       )
799 799
 
800 800
       if (length(unique(celdaClusters(tempModel)$z)) == currentK) {
801
-        overallZ <- celdaClusters(tempModel)$z
801
+        overallZ <- as.integer(celdaClusters(tempModel)$z)
802 802
       } else {
803 803
         overallZ <- tempSplit$z
804 804
         ll <-
... ...
@@ -1336,7 +1336,7 @@ setMethod("recursiveSplitModule",
1336 1336
       verbose = FALSE,
1337 1337
       reorder = reorder)
1338 1338
     currentL <- length(unique(celdaClusters(modelInitial)$y)) + 1
1339
-    overallY <- celdaClusters(modelInitial)$y
1339
+    overallY <- as.integer(celdaClusters(modelInitial)$y)
1340 1340
 
1341 1341
     resList <- list(modelInitial)
1342 1342
     while (currentL <= maxL) {
... ...
@@ -1365,7 +1365,7 @@ setMethod("recursiveSplitModule",
1365 1365
         zInit = overallZ,
1366 1366
         reorder = reorder
1367 1367
       )
1368
-      overallY <- celdaClusters(tempModel)$y
1368
+      overallY <- as.integer(celdaClusters(tempModel)$y)
1369 1369
 
1370 1370
       ## Add new model to results list and increment L
1371 1371
       .logMessages(
... ...
@@ -1428,8 +1428,8 @@ setMethod("recursiveSplitModule",
1428 1428
     )
1429 1429
     modelInitial@params$countChecksum <- countChecksum
1430 1430
 
1431
-    currentL <- length(unique(celdaClusters(modelInitial)$y)) + 1
1432
-    overallY <- celdaClusters(modelInitial)$y
1431
+    currentL <- length(unique(as.integer(celdaClusters(modelInitial)$y))) + 1
1432
+    overallY <- as.integer(celdaClusters(modelInitial)$y)
1433 1433
 
1434 1434
     ## Decomposed counts for full count matrix
1435 1435
     p <- .cGDecomposeCounts(counts, overallY, currentL)
... ...
@@ -1465,7 +1465,7 @@ setMethod("recursiveSplitModule",
1465 1465
         yInit = tempSplit$y,
1466 1466
         reorder = reorder
1467 1467
       )
1468
-      overallY <- celdaClusters(tempModel)$y
1468
+      overallY <- as.integer(celdaClusters(tempModel)$y)
1469 1469
 
1470 1470
       # Adjust decomposed count matrices
1471 1471
       p <- .cGReDecomposeCounts(counts,
... ...
@@ -1543,7 +1543,7 @@ setMethod("recursiveSplitModule",
1543 1543
       nchains = 1,
1544 1544
       verbose = FALSE
1545 1545
     )
1546
-    overallY <- celdaClusters(modelInitial)$y
1546
+    overallY <- as.integer(celdaClusters(modelInitial)$y)
1547 1547
     currentL <- length(unique(overallY)) + 1
1548 1548
 
1549 1549
     ## Perform splitting for y labels
... ...
@@ -1572,7 +1572,7 @@ setMethod("recursiveSplitModule",
1572 1572
         yInit = tempSplit$y,
1573 1573
         reorder = reorder
1574 1574
       )
1575
-      overallY <- celdaClusters(tempModel)$y
1575
+      overallY <- as.integer(celdaClusters(tempModel)$y)
1576 1576
 
1577 1577
       ## Add new model to results list and increment L
1578 1578
       .logMessages(
Browse code

Fixed bug where sample labels were not stored correctly when using recurrsive split. Updated report to handle plotting of character cell annotations without trying to convert to numeric

Joshua D. Campbell authored on 14/04/2022 17:45:59
Showing 1 changed files
... ...
@@ -547,7 +547,7 @@ setMethod("recursiveSplitCell",
547 547
         beta = beta
548 548
       )
549 549
       tempModel <- .celda_CG(counts,
550
-        sampleLabel = s,
550
+        sampleLabel = sampleLabel,
551 551
         K = as.integer(currentK),
552 552
         L = as.integer(L),
553 553
         yInit = overallY,
... ...
@@ -660,7 +660,7 @@ setMethod("recursiveSplitCell",
660 660
       logfile = logfile
661 661
     )
662 662
     modelInitial <- .celda_C(countsY,
663
-      sampleLabel = s,
663
+      sampleLabel = sampleLabel,
664 664
       K = as.integer(initialK),
665 665
       zInitialize = "split",
666 666
       nchains = 1,
... ...
@@ -691,7 +691,7 @@ setMethod("recursiveSplitCell",
691 691
         beta = beta
692 692
       )
693 693
       tempModel <- .celda_C(countsY,
694
-        sampleLabel = s,
694
+        sampleLabel = sampleLabel,
695 695
         K = as.integer(currentK),
696 696
         nchains = 1,
697 697
         zInitialize = "random",
... ...
@@ -762,7 +762,7 @@ setMethod("recursiveSplitCell",
762 762
       logfile = logfile
763 763
     )
764 764
     modelInitial <- .celda_C(counts,
765
-      sampleLabel = s,
765
+      sampleLabel = sampleLabel,
766 766
       K = as.integer(initialK),
767 767
       zInitialize = "split",
768 768
       nchains = 1,
... ...
@@ -784,7 +784,7 @@ setMethod("recursiveSplitCell",
784 784
         beta = beta
785 785
       )
786 786
       tempModel <- .celda_C(counts,
787
-        sampleLabel = s,
787
+        sampleLabel = sampleLabel,
788 788
         K = as.integer(currentK),
789 789
         nchains = 1,
790 790
         zInitialize = "random",
Browse code

Removed ability to subsample counts matrix when calculating perplexity. This will take a much larger update where theta, probability of each cell population in each sample, will need to be calculated from new samples by predicting the population for each cell.

Joshua D. Campbell authored on 11/04/2022 18:48:36
Showing 1 changed files
... ...
@@ -137,14 +137,9 @@
137 137
 #' @param doResampling Boolean. If \code{TRUE}, then each cell in the counts
138 138
 #' matrix will be resampled according to a multinomial distribution to introduce
139 139
 #' noise before calculating perplexity. Default \code{FALSE}.
140
-#' @param doSubsampling Boolean. If \code{TRUE}, then a subset of cells from
141
-#' the original counts matrix will be randomly selected. Default \code{TRUE}.
142 140
 #' @param numResample Integer. The number of times to resample the counts matrix
143
-#' for evaluating perplexity if \code{doSubsampling} is set to \code{TRUE}.
141
+#' for evaluating perplexity if \code{doResampling} is set to \code{TRUE}.
144 142
 #' Default \code{5}.
145
-#' @param numSubsample Integer. The number of cells to sample from the
146
-#' the counts matrix if \code{doSubsampling} is set to \code{TRUE}. 
147
-#' Default \code{5000}.
148 143
 #' @param verbose Logical. Whether to print log messages. Default TRUE.
149 144
 #' @param logfile Character. Messages will be redirected to a file named
150 145
 #'  "logfile". If NULL, messages will be printed to stdout.  Default NULL.
... ...
@@ -174,9 +169,7 @@ setGeneric("recursiveSplitCell",
174 169
         seed = 12345,
175 170
         perplexity = TRUE,
176 171
         doResampling = FALSE,
177
-        doSubsampling = TRUE,
178 172
         numResample = 5,
179
-        numSubsample = 5000,
180 173
         logfile = NULL,
181 174
         verbose = TRUE) {
182 175
     standardGeneric("recursiveSplitCell")})
... ...
@@ -221,9 +214,7 @@ setMethod("recursiveSplitCell",
221 214
         seed = 12345,
222 215
         perplexity = TRUE,
223 216
         doResampling = FALSE,
224
-        doSubsampling = TRUE,
225 217
         numResample = 5,
226
-        numSubsample = 5000,
227 218
         logfile = NULL,
228 219
         verbose = TRUE) {
229 220
 
... ...
@@ -263,9 +254,7 @@ setMethod("recursiveSplitCell",
263 254
             seed = seed,
264 255
             perplexity = perplexity,
265 256
             doResampling = doResampling,
266
-            doSubsampling = doSubsampling,
267 257
             numResample = numResample,
268
-            numSubsample = numSubsample,
269 258
             logfile = logfile,
270 259
             verbose = verbose)
271 260
 
... ...
@@ -335,9 +324,7 @@ setMethod("recursiveSplitCell",
335 324
         seed = 12345,
336 325
         perplexity = TRUE,
337 326
         doResampling = FALSE,
338
-        doSubsampling = TRUE,
339 327
         numResample = 5,
340
-        numSubsample = 5000,
341 328
         logfile = NULL,
342 329
         verbose = TRUE) {
343 330
 
... ...
@@ -368,9 +355,7 @@ setMethod("recursiveSplitCell",
368 355
             seed = seed,
369 356
             perplexity = perplexity,
370 357
             doResampling = doResampling,
371
-            doSubsampling = doSubsampling,
372 358
             numResample = numResample,
373
-            numSubsample = numSubsample,
374 359
             logfile = logfile,
375 360
             verbose = verbose)
376 361
 
... ...
@@ -415,9 +400,7 @@ setMethod("recursiveSplitCell",
415 400
     seed,
416 401
     perplexity,
417 402
     doResampling,
418
-    doSubsampling,
419 403
     numResample,
420
-    numSubsample,
421 404
     logfile,
422 405
     verbose) {
423 406
 
... ...
@@ -436,9 +419,7 @@ setMethod("recursiveSplitCell",
436 419
             reorder = reorder,
437 420
             perplexity = perplexity,
438 421
             doResampling = doResampling,
439
-            doSubsampling = doSubsampling,
440 422
             numResample = numResample,
441
-            numSubsample = numSubsample,
442 423
             logfile = logfile,
443 424
             verbose = verbose)
444 425
     } else {
... ...
@@ -458,9 +439,7 @@ setMethod("recursiveSplitCell",
458 439
                 reorder = reorder,
459 440
                 perplexity = perplexity,
460 441
                 doResampling = doResampling,
461
-                doSubsampling = doSubsampling,
462 442
                 numResample = numResample,
463
-                numSubsample = numSubsample,
464 443
                 logfile = logfile,
465 444
                 verbose = verbose)
466 445
         )
... ...
@@ -484,9 +463,7 @@ setMethod("recursiveSplitCell",
484 463
                                reorder,
485 464
                                perplexity,
486 465
                                doResampling,
487
-                               doSubsampling,
488 466
                                numResample,
489
-                               numSubsample,
490 467
                                logfile,
491 468
                                verbose) {
492 469
 
... ...
@@ -890,9 +867,7 @@ setMethod("recursiveSplitCell",
890 867
     )
891 868
     celdaRes <- resamplePerplexity(counts, celdaRes,
892 869
                                    doResampling = doResampling,
893
-                                   doSubsampling = doSubsampling,
894
-                                   numResample = numResample,
895
-                                   numSubsample = numSubsample)
870
+                                   numResample = numResample)
896 871
   }
897 872
   endTime <- Sys.time()
898 873
   .logMessages(
... ...
@@ -973,14 +948,9 @@ setMethod("recursiveSplitCell",
973 948
 #' @param doResampling Boolean. If \code{TRUE}, then each cell in the counts
974 949
 #' matrix will be resampled according to a multinomial distribution to introduce
975 950
 #' noise before calculating perplexity. Default \code{FALSE}.
976
-#' @param doSubsampling Boolean. If \code{TRUE}, then a subset of cells from
977
-#' the original counts matrix will be randomly selected. Default \code{TRUE}.
978 951
 #' @param numResample Integer. The number of times to resample the counts matrix
979
-#' for evaluating perplexity if \code{doSubsampling} is set to \code{TRUE}.
952
+#' for evaluating perplexity if \code{doResampling} is set to \code{TRUE}.
980 953
 #' Default \code{5}.
981
-#' @param numSubsample Integer. The number of cells to sample from the
982
-#' the counts matrix if \code{doSubsampling} is set to \code{TRUE}. 
983
-#' Default \code{5000}.
984 954
 #' @param verbose Logical. Whether to print log messages. Default TRUE.
985 955
 #' @param logfile Character. Messages will be redirected to a file named
986 956
 #'  "logfile". If NULL, messages will be printed to stdout.  Default NULL.
... ...
@@ -1010,9 +980,7 @@ setGeneric("recursiveSplitModule",
1010 980
         seed = 12345,
1011 981
         perplexity = TRUE,
1012 982
         doResampling = FALSE,
1013
-        doSubsampling = TRUE,
1014 983
         numResample = 5,
1015
-        numSubsample = 5000,
1016 984
         verbose = TRUE,
1017 985
         logfile = NULL) {
1018 986
     standardGeneric("recursiveSplitModule")})
... ...
@@ -1050,9 +1018,7 @@ setMethod("recursiveSplitModule",
1050 1018
         seed = 12345,
1051 1019
         perplexity = TRUE,
1052 1020
         doResampling = FALSE,
1053
-        doSubsampling = TRUE,
1054 1021
         numResample = 5,
1055
-        numSubsample = 5000,
1056 1022
         verbose = TRUE,
1057 1023
         logfile = NULL) {
1058 1024
 
... ...
@@ -1092,9 +1058,7 @@ setMethod("recursiveSplitModule",
1092 1058
             seed = seed,
1093 1059
             perplexity = perplexity,
1094 1060
             doResampling = doResampling,
1095
-            doSubsampling = doSubsampling,
1096 1061
             numResample = numResample,
1097
-            numSubsample = numSubsample,
1098 1062
             verbose = verbose,
1099 1063
             logfile = logfile)
1100 1064
 
... ...
@@ -1157,9 +1121,7 @@ setMethod("recursiveSplitModule",
1157 1121
         seed = 12345,
1158 1122
         perplexity = TRUE,
1159 1123
         doResampling = FALSE,
1160
-        doSubsampling = TRUE,
1161 1124
         numResample = 5,
1162
-        numSubsample = 5000,
1163 1125
         verbose = TRUE,
1164 1126
         logfile = NULL) {
1165 1127
 
... ...
@@ -1190,9 +1152,7 @@ setMethod("recursiveSplitModule",
1190 1152
             seed = seed,
1191 1153
             perplexity = perplexity,
1192 1154
             doResampling = doResampling,
1193
-            doSubsampling = doSubsampling,
1194 1155
             numResample = numResample,
1195
-            numSubsample = numSubsample,
1196 1156
             verbose = verbose,
1197 1157
             logfile = logfile)
1198 1158
 
... ...
@@ -1237,9 +1197,7 @@ setMethod("recursiveSplitModule",
1237 1197
     seed,
1238 1198
     perplexity,
1239 1199
     doResampling,
1240
-    doSubsampling,
1241 1200
     numResample,
1242
-    numSubsample,
1243 1201
     verbose,
1244 1202
     logfile) {
1245 1203
 
... ...
@@ -1261,9 +1219,7 @@ setMethod("recursiveSplitModule",
1261 1219
             verbose = verbose,
1262 1220
             logfile = logfile,
1263 1221
             doResampling = doResampling,
1264
-            doSubsampling = doSubsampling,
1265
-            numResample = numResample,
1266
-            numSubsample = numSubsample)
1222
+            numResample = numResample)
1267 1223
     } else {
1268 1224
         with_seed(seed,
1269 1225
             celdaList <- .recursiveSplitModule(
... ...
@@ -1283,9 +1239,7 @@ setMethod("recursiveSplitModule",
1283 1239
                 verbose = verbose,
1284 1240
                 logfile = logfile,
1285 1241
                 doResampling = doResampling,
1286
-                doSubsampling = doSubsampling,
1287
-                numResample = numResample,
1288
-                numSubsample = numSubsample)
1242
+                numResample = numResample)
1289 1243
         )
1290 1244
     }
1291 1245
 
... ...
@@ -1309,9 +1263,7 @@ setMethod("recursiveSplitModule",
1309 1263
                                  verbose = TRUE,
1310 1264
                                  logfile = NULL,
1311 1265
                                  doResampling = FALSE,
1312
-                                 doSubsampling = TRUE,
1313
-                                 numResample = 5,
1314
-                                 numSubsample = 5000) {
1266
+                                 numResample = 5) {
1315 1267
 
1316 1268
   .logMessages(paste(rep("=", 50), collapse = ""),
1317 1269
     logfile = logfile,
... ...
@@ -1673,9 +1625,7 @@ setMethod("recursiveSplitModule",
1673 1625
     )
1674 1626
     celdaRes <- resamplePerplexity(counts, celdaRes,
1675 1627
                                    doResampling = doResampling,
1676
-                                   doSubsampling = doSubsampling,
1677
-                                   numResample = numResample,
1678
-                                   numSubsample = numSubsample)
1628
+                                   numResample = numResample)
1679 1629
   }
1680 1630
 
1681 1631
   endTime <- Sys.time()
Browse code

Added subsampling parameters for perplexity calculation to recursive split functions

Joshua D. Campbell authored on 28/03/2022 12:00:25
Showing 1 changed files
... ...
@@ -134,6 +134,17 @@
134 134
 #' @param perplexity Logical. Whether to calculate perplexity for each model.
135 135
 #'  If FALSE, then perplexity can be calculated later with
136 136
 #'  \link{resamplePerplexity}. Default TRUE.
137
+#' @param doResampling Boolean. If \code{TRUE}, then each cell in the counts
138
+#' matrix will be resampled according to a multinomial distribution to introduce
139
+#' noise before calculating perplexity. Default \code{FALSE}.
140
+#' @param doSubsampling Boolean. If \code{TRUE}, then a subset of cells from
141
+#' the original counts matrix will be randomly selected. Default \code{TRUE}.
142
+#' @param numResample Integer. The number of times to resample the counts matrix
143
+#' for evaluating perplexity if \code{doSubsampling} is set to \code{TRUE}.
144
+#' Default \code{5}.
145
+#' @param numSubsample Integer. The number of cells to sample from the
146
+#' the counts matrix if \code{doSubsampling} is set to \code{TRUE}. 
147
+#' Default \code{5000}.
137 148
 #' @param verbose Logical. Whether to print log messages. Default TRUE.
138 149
 #' @param logfile Character. Messages will be redirected to a file named
139 150
 #'  "logfile". If NULL, messages will be printed to stdout.  Default NULL.
... ...
@@ -162,6 +173,10 @@ setGeneric("recursiveSplitCell",
162 173
         reorder = TRUE,
163 174
         seed = 12345,
164 175
         perplexity = TRUE,
176
+        doResampling = FALSE,
177
+        doSubsampling = TRUE,
178
+        numResample = 5,
179
+        numSubsample = 5000,
165 180
         logfile = NULL,
166 181
         verbose = TRUE) {
167 182
     standardGeneric("recursiveSplitCell")})
... ...
@@ -205,6 +220,10 @@ setMethod("recursiveSplitCell",
205 220
         reorder = TRUE,
206 221
         seed = 12345,
207 222
         perplexity = TRUE,
223
+        doResampling = FALSE,
224
+        doSubsampling = TRUE,
225
+        numResample = 5,
226
+        numSubsample = 5000,
208 227
         logfile = NULL,
209 228
         verbose = TRUE) {
210 229
 
... ...
@@ -243,6 +262,10 @@ setMethod("recursiveSplitCell",
243 262
             reorder = reorder,
244 263
             seed = seed,
245 264
             perplexity = perplexity,
265
+            doResampling = doResampling,
266
+            doSubsampling = doSubsampling,
267
+            numResample = numResample,
268
+            numSubsample = numSubsample,
246 269
             logfile = logfile,
247 270
             verbose = verbose)
248 271
 
... ...
@@ -311,6 +334,10 @@ setMethod("recursiveSplitCell",
311 334
         reorder = TRUE,
312 335
         seed = 12345,
313 336
         perplexity = TRUE,
337
+        doResampling = FALSE,
338
+        doSubsampling = TRUE,
339
+        numResample = 5,
340
+        numSubsample = 5000,
314 341
         logfile = NULL,
315 342
         verbose = TRUE) {
316 343
 
... ...
@@ -340,6 +367,10 @@ setMethod("recursiveSplitCell",
340 367
             reorder = reorder,
341 368
             seed = seed,
342 369
             perplexity = perplexity,
370
+            doResampling = doResampling,
371
+            doSubsampling = doSubsampling,
372
+            numResample = numResample,
373
+            numSubsample = numSubsample,
343 374
             logfile = logfile,
344 375
             verbose = verbose)
345 376
 
... ...
@@ -383,6 +414,10 @@ setMethod("recursiveSplitCell",
383 414
     reorder,
384 415
     seed,
385 416
     perplexity,
417
+    doResampling,
418
+    doSubsampling,
419
+    numResample,
420
+    numSubsample,
386 421
     logfile,
387 422
     verbose) {
388 423
 
... ...
@@ -400,6 +435,10 @@ setMethod("recursiveSplitCell",
400 435
             minCell = minCell,
401 436
             reorder = reorder,
402 437
             perplexity = perplexity,
438
+            doResampling = doResampling,
439
+            doSubsampling = doSubsampling,
440
+            numResample = numResample,
441
+            numSubsample = numSubsample,
403 442
             logfile = logfile,
404 443
             verbose = verbose)
405 444
     } else {
... ...
@@ -418,6 +457,10 @@ setMethod("recursiveSplitCell",
418 457
                 minCell = minCell,
419 458
                 reorder = reorder,
420 459
                 perplexity = perplexity,
460
+                doResampling = doResampling,
461
+                doSubsampling = doSubsampling,
462
+                numResample = numResample,
463
+                numSubsample = numSubsample,
421 464
                 logfile = logfile,
422 465
                 verbose = verbose)
423 466
         )
... ...
@@ -440,6 +483,10 @@ setMethod("recursiveSplitCell",
440 483
                                minCell,
441 484
                                reorder,
442 485
                                perplexity,
486
+                               doResampling,
487
+                               doSubsampling,
488
+                               numResample,
489
+                               numSubsample,
443 490
                                logfile,
444 491
                                verbose) {
445 492
 
... ...
@@ -841,7 +888,11 @@ setMethod("recursiveSplitCell",
841 888
       verbose = verbose,
842 889
       logfile = NULL
843 890
     )
844
-    celdaRes <- resamplePerplexity(counts, celdaRes)
891
+    celdaRes <- resamplePerplexity(counts, celdaRes,
892
+                                   doResampling = doResampling,
893
+                                   doSubsampling = doSubsampling,
894
+                                   numResample = numResample,
895
+                                   numSubsample = numSubsample)
845 896
   }
846 897
   endTime <- Sys.time()
847 898
   .logMessages(
... ...
@@ -918,7 +969,18 @@ setMethod("recursiveSplitCell",
918 969
 #'  \link[withr]{with_seed} are made.
919 970
 #' @param perplexity Logical. Whether to calculate perplexity for each model.
920 971
 #'  If FALSE, then perplexity can be calculated later with
921
-#'  \link{resamplePerplexity}. Default TRUE.
972
+#'  \link{resamplePerplexity}. Default \code{TRUE}.
973
+#' @param doResampling Boolean. If \code{TRUE}, then each cell in the counts
974
+#' matrix will be resampled according to a multinomial distribution to introduce
975
+#' noise before calculating perplexity. Default \code{FALSE}.
976
+#' @param doSubsampling Boolean. If \code{TRUE}, then a subset of cells from
977
+#' the original counts matrix will be randomly selected. Default \code{TRUE}.
978
+#' @param numResample Integer. The number of times to resample the counts matrix
979
+#' for evaluating perplexity if \code{doSubsampling} is set to \code{TRUE}.
980
+#' Default \code{5}.
981
+#' @param numSubsample Integer. The number of cells to sample from the
982
+#' the counts matrix if \code{doSubsampling} is set to \code{TRUE}. 
983
+#' Default \code{5000}.
922 984
 #' @param verbose Logical. Whether to print log messages. Default TRUE.
923 985
 #' @param logfile Character. Messages will be redirected to a file named
924 986
 #'  "logfile". If NULL, messages will be printed to stdout.  Default NULL.
... ...
@@ -947,6 +1009,10 @@ setGeneric("recursiveSplitModule",
947 1009
         reorder = TRUE,
948 1010
         seed = 12345,
949 1011
         perplexity = TRUE,
1012
+        doResampling = FALSE,
1013
+        doSubsampling = TRUE,
1014
+        numResample = 5,
1015
+        numSubsample = 5000,
950 1016
         verbose = TRUE,
951 1017
         logfile = NULL) {
952 1018
     standardGeneric("recursiveSplitModule")})
... ...
@@ -983,6 +1049,10 @@ setMethod("recursiveSplitModule",
983 1049
         reorder = TRUE,
984 1050
         seed = 12345,
985 1051
         perplexity = TRUE,
1052
+        doResampling = FALSE,
1053
+        doSubsampling = TRUE,
1054
+        numResample = 5,
1055
+        numSubsample = 5000,
986 1056
         verbose = TRUE,
987 1057
         logfile = NULL) {
988 1058
 
... ...
@@ -1021,6 +1091,10 @@ setMethod("recursiveSplitModule",
1021 1091
             reorder = reorder,
1022 1092
             seed = seed,
1023 1093
             perplexity = perplexity,
1094
+            doResampling = doResampling,
1095
+            doSubsampling = doSubsampling,
1096
+            numResample = numResample,
1097
+            numSubsample = numSubsample,
1024 1098
             verbose = verbose,
1025 1099
             logfile = logfile)
1026 1100
 
... ...
@@ -1082,6 +1156,10 @@ setMethod("recursiveSplitModule",
1082 1156
         reorder = TRUE,
1083 1157
         seed = 12345,
1084 1158
         perplexity = TRUE,
1159
+        doResampling = FALSE,
1160
+        doSubsampling = TRUE,
1161
+        numResample = 5,
1162
+        numSubsample = 5000,
1085 1163
         verbose = TRUE,
1086 1164
         logfile = NULL) {
1087 1165
 
... ...
@@ -1111,6 +1189,10 @@ setMethod("recursiveSplitModule",
1111 1189
             reorder = reorder,
1112 1190
             seed = seed,
1113 1191
             perplexity = perplexity,
1192
+            doResampling = doResampling,
1193
+            doSubsampling = doSubsampling,
1194
+            numResample = numResample,
1195
+            numSubsample = numSubsample,
1114 1196
             verbose = verbose,
1115 1197
             logfile = logfile)
1116 1198
 
... ...
@@ -1154,6 +1236,10 @@ setMethod("recursiveSplitModule",
1154 1236
     reorder,
1155 1237
     seed,
1156 1238
     perplexity,
1239
+    doResampling,
1240
+    doSubsampling,
1241
+    numResample,
1242
+    numSubsample,
1157 1243
     verbose,
1158 1244
     logfile) {
1159 1245
 
... ...
@@ -1173,7 +1259,11 @@ setMethod("recursiveSplitModule",
1173 1259
             reorder = reorder,
1174 1260
             perplexity = perplexity,
1175 1261
             verbose = verbose,
1176
-            logfile = logfile)
1262
+            logfile = logfile,
1263
+            doResampling = doResampling,
1264
+            doSubsampling = doSubsampling,
1265
+            numResample = numResample,
1266
+            numSubsample = numSubsample)
1177 1267
     } else {
1178 1268
         with_seed(seed,
1179 1269
             celdaList <- .recursiveSplitModule(
... ...
@@ -1191,7 +1281,11 @@ setMethod("recursiveSplitModule",
1191 1281
                 reorder = reorder,
1192 1282
                 perplexity = perplexity,
1193 1283
                 verbose = verbose,
1194
-                logfile = logfile)
1284
+                logfile = logfile,
1285
+                doResampling = doResampling,
1286
+                doSubsampling = doSubsampling,
1287
+                numResample = numResample,
1288
+                numSubsample = numSubsample)
1195 1289
         )
1196 1290
     }
1197 1291
 
... ...
@@ -1213,7 +1307,11 @@ setMethod("recursiveSplitModule",
1213 1307
                                  reorder = TRUE,
1214 1308
                                  perplexity = TRUE,
1215 1309
                                  verbose = TRUE,
1216
-                                 logfile = NULL) {
1310
+                                 logfile = NULL,
1311
+                                 doResampling = FALSE,
1312
+                                 doSubsampling = TRUE,
1313
+                                 numResample = 5,
1314
+                                 numSubsample = 5000) {
1217 1315
 
1218 1316
   .logMessages(paste(rep("=", 50), collapse = ""),
1219 1317
     logfile = logfile,
... ...
@@ -1573,7 +1671,11 @@ setMethod("recursiveSplitModule",
1573 1671
       verbose = verbose,
1574 1672
       logfile = NULL
1575 1673
     )
1576
-    celdaRes <- resamplePerplexity(counts, celdaRes)
1674
+    celdaRes <- resamplePerplexity(counts, celdaRes,
1675
+                                   doResampling = doResampling,
1676
+                                   doSubsampling = doSubsampling,
1677
+                                   numResample = numResample,
1678
+                                   numSubsample = numSubsample)
1577 1679
   }
1578 1680
 
1579 1681
   endTime <- Sys.time()
Browse code

Sample labels are stored in their original form

Joshua D. Campbell authored on 03/10/2021 21:43:01
Showing 1 changed files
... ...
@@ -496,7 +496,7 @@ setMethod("recursiveSplitCell",
496 496
       verbose = verbose,
497 497
       logfile = logfile)
498 498
     modelInitial <- .celda_CG(counts,
499
-      sampleLabel = s,
499
+      sampleLabel = sampleLabel,
500 500
       K = as.integer(initialK),
501 501
       L = as.integer(L),
502 502
       zInitialize = "split",
... ...
@@ -1272,7 +1272,7 @@ setMethod("recursiveSplitModule",
1272 1272
       logfile = logfile
1273 1273
     )
1274 1274
     modelInitial <- .celda_CG(counts,
1275
-      sampleLabel = s,
1275
+      sampleLabel = sampleLabel,
1276 1276
       L = initialL,
1277 1277
       K = K,
1278 1278
       zInitialize = "predefined",
... ...
@@ -1640,6 +1640,7 @@ setMethod("recursiveSplitModule",
1640 1640
             perplexity = perplexity,
1641 1641
             logfile = logfile,
1642 1642
             verbose = verbose)
1643
+    SummarizedExperiment::colData(sce)$"celda_sample_label" <- sampleLabel
1643 1644
     return(sce)
1644 1645
 
1645 1646
 }
... ...
@@ -1687,5 +1688,6 @@ setMethod("recursiveSplitModule",
1687 1688
             perplexity = perplexity,
1688 1689
             logfile = logfile,
1689 1690
             verbose = verbose)
1691
+    SummarizedExperiment::colData(sce)$"celda_sample_label" <- sampleLabel
1690 1692
     return(sce)
1691 1693
 }
Browse code

fix perplexity argument passing error

zhewa authored on 02/05/2021 22:14:04
Showing 1 changed files
... ...
@@ -1549,7 +1549,7 @@ setMethod("recursiveSplitModule",
1549 1549
     )
1550 1550
   }
1551 1551
 
1552
-  ## Summarize paramters of different models
1552
+  ## Summarize parameters of different models
1553 1553
   logliks <- vapply(resList, function(mod) {
1554 1554
     bestLogLikelihood(mod)
1555 1555
   }, double(1))
Browse code

add arguments to generic functions

zhewa authored on 01/05/2021 20:59:26
Showing 1 changed files
... ...
@@ -137,7 +137,6 @@
137 137
 #' @param verbose Logical. Whether to print log messages. Default TRUE.
138 138
 #' @param logfile Character. Messages will be redirected to a file named
139 139
 #'  "logfile". If NULL, messages will be printed to stdout.  Default NULL.
140
-#' @param ... Ignored. Placeholder to prevent check warning.
141 140
 #' @return A \linkS4class{SingleCellExperiment} object. Function
142 141
 #'  parameter settings and celda model results are stored in the
143 142
 #'  \link{metadata} \code{"celda_grid_search"} slot. The models in
... ...
@@ -146,7 +145,25 @@
146 145
 #' @seealso \link{recursiveSplitModule} for recursive splitting of feature
147 146
 #'  modules.
148 147
 #' @export
149
-setGeneric("recursiveSplitCell", function(x, ...) {
148
+setGeneric("recursiveSplitCell",
149
+    function(x,
150
+        useAssay = "counts",
151
+        altExpName = "featureSubset",
152
+        sampleLabel = NULL,
153
+        initialK = 5,
154
+        maxK = 25,
155
+        tempL = NULL,
156
+        yInit = NULL,
157
+        alpha = 1,
158
+        beta = 1,
159
+        delta = 1,
160
+        gamma = 1,
161
+        minCell = 3,
162
+        reorder = TRUE,
163
+        seed = 12345,
164
+        perplexity = TRUE,
165
+        logfile = NULL,
166
+        verbose = TRUE) {
150 167
     standardGeneric("recursiveSplitCell")})
151 168
 
152 169
 
... ...
@@ -905,7 +922,6 @@ setMethod("recursiveSplitCell",
905 922
 #' @param verbose Logical. Whether to print log messages. Default TRUE.
906 923
 #' @param logfile Character. Messages will be redirected to a file named
907 924
 #'  "logfile". If NULL, messages will be printed to stdout.  Default NULL.
908
-#' @param ... Ignored. Placeholder to prevent check warning.
909 925
 #' @return A \linkS4class{SingleCellExperiment} object. Function
910 926
 #'  parameter settings and celda model results are stored in the
911 927
 #'  \link{metadata} \code{"celda_grid_search"} slot. The models in
... ...
@@ -914,7 +930,25 @@ setMethod("recursiveSplitCell",
914 930
 #' @seealso \code{recursiveSplitCell} for recursive splitting of cell
915 931
 #'  populations.
916 932
 #' @export
917
-setGeneric("recursiveSplitModule", function(x, ...) {
933
+setGeneric("recursiveSplitModule",
934
+    function(x,
935
+        useAssay = "counts",
936
+        altExpName = "featureSubset",
937
+        initialL = 10,
938
+        maxL = 100,
939
+        tempK = 100,
940
+        zInit = NULL,
941
+        sampleLabel = NULL,
942
+        alpha = 1,
943
+        beta = 1,
944
+        delta = 1,
945
+        gamma = 1,
946
+        minFeature = 3,
947
+        reorder = TRUE,
948
+        seed = 12345,
949
+        perplexity = TRUE,
950
+        verbose = TRUE,
951
+        logfile = NULL) {
918 952
     standardGeneric("recursiveSplitModule")})
919 953
 
920 954
 
Browse code

Fix lints

Joshua D. Campbell authored on 07/04/2021 21:37:51
Showing 1 changed files
... ...
@@ -1343,7 +1343,7 @@ setMethod("recursiveSplitModule",
1343 1343
       verbose = FALSE
1344 1344
     )
1345 1345
     modelInitial@params$countChecksum <- countChecksum
1346
-    
1346
+
1347 1347
     currentL <- length(unique(celdaClusters(modelInitial)$y)) + 1
1348 1348
     overallY <- celdaClusters(modelInitial)$y
1349 1349
 
Browse code

Refactored matrix multiplication with sparse matrices to a separate function. Fixed unit tests and one bug in recursiveModuleSplit

Joshua D. Campbell authored on 06/04/2021 02:13:59
Showing 1 changed files
... ...
@@ -1342,7 +1342,8 @@ setMethod("recursiveSplitModule",
1342 1342
       nchains = 1,
1343 1343
       verbose = FALSE
1344 1344
     )
1345
-
1345
+    modelInitial@params$countChecksum <- countChecksum
1346
+    
1346 1347
     currentL <- length(unique(celdaClusters(modelInitial)$y)) + 1
1347 1348
     overallY <- celdaClusters(modelInitial)$y
1348 1349
 
Browse code

Added rmarkdown docs for running and plotting celda_cg. Some document updates to recursiveSplit functions. Includes new wrapper functions in reports.R

Joshua D. Campbell authored on 22/03/2021 12:41:06
Showing 1 changed files
... ...
@@ -96,23 +96,26 @@
96 96
 #'  to use. Default "featureSubset".
97 97
 #' @param sampleLabel Vector or factor. Denotes the sample label for each cell
98 98
 #'  (column) in the count matrix.
99
-#' @param initialK Integer. Minimum number of cell populations to try.
99
+#' @param initialK Integer. Initial number of cell populations to try.
100
+#' Default \code{5}.
100 101
 #' @param maxK Integer. Maximum number of cell populations to try.
102
+#' Default \code{25}.
101 103
 #' @param tempL Integer. Number of temporary modules to identify and use in cell
102 104
 #'  splitting. Only used if \code{yInit = NULL}. Collapsing features to a
103 105
 #'  relatively smaller number of modules will increase the speed of clustering
104 106
 #'  and tend to produce better cell populations. This number should be larger
105
-#'  than the number of true modules expected in the dataset. Default NULL.
107
+#'  than the number of true modules expected in the dataset. Default
108
+#'  \code{NULL.}
106 109
 #' @param yInit Integer vector. Module labels for features. Cells will be
107 110
 #'  clustered using the \link{celda_CG} model based on the modules specified in
108 111
 #'  \code{yInit} rather than the counts of individual features. While the
109 112
 #'  features will be initialized to the module labels in \code{yInit}, the
110 113
 #'  labels will be allowed to move within each new model with a different K.
111 114
 #' @param alpha Numeric. Concentration parameter for Theta. Adds a pseudocount
112
-#'  to each cell population in each sample. Default 1.
115
+#'  to each cell population in each sample. Default \code{1}.
113 116
 #' @param beta Numeric. Concentration parameter for Phi. Adds a pseudocount to
114 117
 #'  each feature in each cell (if \code{yInit} is NULL) or to each module in
115
-#'  each cell population (if \code{yInit} is set). Default 1.
118
+#'  each cell population (if \code{yInit} is set). Default \code{1}.
116 119
 #' @param delta Numeric. Concentration parameter for Psi. Adds a pseudocount
117 120
 #'  to each feature in each module. Only used if \code{yInit} is set. Default 1.
118 121
 #' @param gamma Numeric. Concentration parameter for Eta. Adds a pseudocount
... ...
@@ -864,23 +867,23 @@ setMethod("recursiveSplitCell",
864 867
 #'  \link[SingleCellExperiment]{SingleCellExperiment} object. Default "counts".
865 868
 #' @param altExpName The name for the \link{altExp} slot
866 869
 #'  to use. Default "featureSubset".
867
-#' @param initialL Integer. Minimum number of modules to try.
868
-#' @param maxL Integer. Maximum number of modules to try.
870
+#' @param initialL Integer. Initial number of modules.
871
+#' @param maxL Integer. Maximum number of modules.
869 872
 #' @param tempK Integer. Number of temporary cell populations to identify and
870 873
 #'  use in module splitting. Only used if \code{zInit = NULL} Collapsing cells
871 874
 #'  to a relatively smaller number of cell popluations will increase the
872 875
 #'  speed of module clustering and tend to produce better modules. This number
873 876
 #'  should be larger than the number of true cell populations expected in the
874
-#'  dataset. Default 100.
877
+#'  dataset. Default \code{100}.
875 878
 #' @param zInit Integer vector. Collapse cells to cell populations based on
876 879
 #'  labels in \code{zInit} and then perform module splitting. If NULL, no
877
-#'  collapasing will be performed unless \code{tempK} is specified.
878
-#'  Default NULL.
880
+#'  collapsing will be performed unless \code{tempK} is specified.
881
+#'  Default \code{NULL}.
879 882
 #' @param sampleLabel Vector or factor. Denotes the sample label for each cell
880
-#'  (column) in the count matrix. Only used if \code{zInit} is set.
883
+#'  (column) in the count matrix. Default \code{NULL}.
881 884
 #' @param alpha Numeric. Concentration parameter for Theta. Adds a pseudocount
882 885
 #'  to each cell population in each sample. Only used if \code{zInit} is set.
883
-#'  Default 1.
886
+#'  Default \code{1}.
884 887
 #' @param beta Numeric. Concentration parameter for Phi. Adds a pseudocount
885 888
 #'  to each feature module in each cell. Default 1.
886 889
 #' @param delta Numeric. Concentration parameter for Psi. Adds a pseudocount
Browse code

fix doc warning file link in package does not exist and so has been treated as a topic

zhewa authored on 16/10/2020 21:36:32
Showing 1 changed files
... ...
@@ -90,9 +90,9 @@
90 90
 #'  with the matrix located in the assay slot under \code{useAssay}.
91 91
 #'  Rows represent features and columns represent cells.
92 92
 #' @param useAssay A string specifying the name of the
93
-#'  \link[SummarizedExperiment]{assay}
93
+#'  \link{assay}
94 94
 #'  slot to use. Default "counts".
95
-#' @param altExpName The name for the \link[SingleCellExperiment]{altExp} slot
95
+#' @param altExpName The name for the \link{altExp} slot
96 96
 #'  to use. Default "featureSubset".
97 97
 #' @param sampleLabel Vector or factor. Denotes the sample label for each cell
98 98
 #'  (column) in the count matrix.
... ...
@@ -137,7 +137,7 @@
137 137
 #' @param ... Ignored. Placeholder to prevent check warning.
138 138
 #' @return A \linkS4class{SingleCellExperiment} object. Function
139 139
 #'  parameter settings and celda model results are stored in the
140
-#'  \link[S4Vectors]{metadata} \code{"celda_grid_search"} slot. The models in
140
+#'  \link{metadata} \code{"celda_grid_search"} slot. The models in
141 141
 #'  the list will be of class \code{celda_C} if \code{yInit = NULL} or
142 142
 #'  \code{celda_CG} if \code{zInit} is set.
143 143
 #' @seealso \link{recursiveSplitModule} for recursive splitting of feature
... ...
@@ -859,10 +859,10 @@ setMethod("recursiveSplitCell",
859 859
 #'  \linkS4class{SingleCellExperiment}
860 860
 #'  with the matrix located in the assay slot under \code{useAssay}.
861 861
 #'  Rows represent features and columns represent cells.
862
-#' @param useAssay A string specifying which \link[SummarizedExperiment]{assay}
862
+#' @param useAssay A string specifying which \link{assay}
863 863
 #'  slot to use if \code{x} is a
864 864
 #'  \link[SingleCellExperiment]{SingleCellExperiment} object. Default "counts".
865
-#' @param altExpName The name for the \link[SingleCellExperiment]{altExp} slot
865
+#' @param altExpName The name for the \link{altExp} slot
866 866
 #'  to use. Default "featureSubset".
867 867
 #' @param initialL Integer. Minimum number of modules to try.
868 868
 #' @param maxL Integer. Maximum number of modules to try.
... ...
@@ -905,7 +905,7 @@ setMethod("recursiveSplitCell",
905 905
 #' @param ... Ignored. Placeholder to prevent check warning.
906 906
 #' @return A \linkS4class{SingleCellExperiment} object. Function
907 907
 #'  parameter settings and celda model results are stored in the
908
-#'  \link[S4Vectors]{metadata} \code{"celda_grid_search"} slot. The models in
908
+#'  \link{metadata} \code{"celda_grid_search"} slot. The models in
909 909
 #'  the list will be of class \link{celda_G} if \code{zInit = NULL} or
910