Browse code

Fix UI bug: set Ref for cellRangerV2 importing

Yichen Wang authored on 09/11/2021 16:39:22
Showing 4 changed files

... ...
@@ -619,7 +619,7 @@ importCellRangerV2 <- function(
619 619
     if (is.null(cellRangerOutsV2)) {
620 620
         if (is.null(reference) | is.null(dataTypeV2)) {
621 621
             stop("'reference' and 'dataTypeV2' are required ",
622
-                 "when 'cellRangerOutsV2 is not specified!'")
622
+                 "when 'cellRangerOutsV2' is not specified!")
623 623
         }
624 624
     }
625 625
 
... ...
@@ -21,7 +21,8 @@ importMultipleSources <- function(allImportEntries, delayedArray = FALSE) {
21 21
           cellRangerDirs = entry$params$cellRangerDirs,
22 22
           sampleDirs = entry$params$sampleDirs,
23 23
           sampleNames = entry$params$sampleNames,
24
-          delayedArray = delayedArray
24
+          delayedArray = delayedArray,
25
+          reference = entry$params$reference
25 26
         )
26 27
       }
27 28
 
... ...
@@ -131,7 +131,7 @@ importCRSDir <- function(failed = FALSE) {
131 131
     shinyFiles::shinyDirButton("sDirectory", label = "Choose Directory", title = "Upload"),
132 132
     # A UI to display what users select
133 133
     verbatimTextOutput("sDirectoryPath", placeholder = TRUE),
134
-
134
+    tags$div(id = "sDirTable"),
135 135
     h3("Sample Name"),
136 136
     h5("If you do not provide an alternate sample name, the sample name will be set to the sample directory name."),
137 137
     textInput("sSampleID", ""),
... ...
@@ -400,6 +400,24 @@ shinyServer(function(input, output, session) {
400 400
         # create a new table for the selected directory
401 401
         count <- 0
402 402
         if (!is.na(path)) {
403
+          # Add Reference selection for cellRangerV2
404
+          if (input$algoChoice == "cellRanger2") {
405
+            ## Identify available reference
406
+            firstSampleDir <- list.dirs(path, recursive = FALSE)[1]
407
+            refPath <- file.path(firstSampleDir, "outs/filtered_gene_bc_matrices")
408
+            refList <- basename(list.dirs(refPath, recursive = FALSE))
409
+            ## Add UI
410
+            insertUI(
411
+              selector = "#bDirTable",
412
+              ui = fluidRow(
413
+                column(
414
+                  6,
415
+                  selectInput("cr2_b_Ref", "Reference:", refList)
416
+                )
417
+              )
418
+            )
419
+          }
420
+          # Add Sample Rename rows
403 421
           counts <- vector()
404 422
           for (sample in list.dirs(path, recursive = FALSE)) {
405 423
             count <- count+1
... ...
@@ -438,6 +456,25 @@ shinyServer(function(input, output, session) {
438 456
         vol <- roots[[input$sDirectory$root]]
439 457
         dirPaths$sDirectory <- paste0(vol, paste(unlist(input$sDirectory$path[-1]),
440 458
                                                  collapse = .Platform$file.sep))
459
+        path <- dirPaths$sDirectory
460
+        if (!is.na(path)) {
461
+          if (input$algoChoice == "cellRanger2") {
462
+            ## Identify available reference
463
+            refPath <- file.path(path, "outs/filtered_gene_bc_matrices")
464
+            refList <- basename(list.dirs(refPath, recursive = FALSE))
465
+            ## Add UI
466
+            insertUI(
467
+              selector = "#sDirTable",
468
+              ui = fluidRow(
469
+                column(
470
+                  6,
471
+                  selectInput("cr2_s_Ref", "Reference:", refList)
472
+                )
473
+              )
474
+            )
475
+          }
476
+          updateTextInput(session, "sSampleID", value = basename(path))
477
+        }
441 478
       }
442 479
     }
443 480
   )
... ...
@@ -522,7 +559,11 @@ shinyServer(function(input, output, session) {
522 559
             name <- basename(sample)
523 560
           }
524 561
           id <- paste0("bnewSampleCR2", allImportEntries$id_count)
525
-          entry <- list(type="cellRanger2", id=id, params=list(cellRangerDirs = basePath, sampleDirs = basename(sample), sampleNames = name))
562
+          entry <- list(type="cellRanger2", id=id, 
563
+                        params=list(cellRangerDirs = basePath, 
564
+                                    sampleDirs = basename(sample), 
565
+                                    sampleNames = name,
566
+                                    reference = input$cr2_b_Ref))
526 567
           allImportEntries$samples <- c(allImportEntries$samples, list(entry))
527 568
           fluidRowStyle <- paste0(paste0("#", id), "{border-bottom: 1px solid #bababa; padding-top: .9%; padding-bottom: .5%}")
528 569
           removeBtnStyle <- paste0(paste0("#remove", id), "{padding-top: 0; padding-bottom: 0;}")
... ...
@@ -609,7 +650,11 @@ shinyServer(function(input, output, session) {
609 650
       # add the files to the appropriate reactiveValues
610 651
       if (input$algoChoice == "cellRanger2") {
611 652
         id <- paste0("snewSampleCR2", allImportEntries$id_count)
612
-        entry <- list(type="cellRanger2", id=id, params=list(cellRangerDirs = dirname(samplePath), sampleDirs = basename(samplePath), sampleNames = input$sSampleID))
653
+        entry <- list(type="cellRanger2", id=id, 
654
+                      params=list(cellRangerDirs = dirname(samplePath), 
655
+                                  sampleDirs = basename(samplePath), 
656
+                                  sampleNames = input$sSampleID,
657
+                                  reference = input$cr2_s_Ref))
613 658
         allImportEntries$samples <- c(allImportEntries$samples, list(entry))
614 659
         allImportEntries$id_count <- allImportEntries$id_count + 1
615 660
       } else {
... ...
@@ -647,7 +692,9 @@ shinyServer(function(input, output, session) {
647 692
     } else {
648 693
       if (input$algoChoice == "cellRanger2") {
649 694
         id <- paste0("dnewSampleCR2", allImportEntries$id_count)
650
-        entry <- list(type="cellRanger2", id=id, params=list(dataDir = dataPath, sampleName = input$dSampleID))
695
+        entry <- list(type="cellRanger2", id=id, 
696
+                      params=list(dataDir = dataPath, 
697
+                                  sampleName = input$dSampleID))
651 698
         allImportEntries$samples <- c(allImportEntries$samples, list(entry))
652 699
         allImportEntries$id_count <- allImportEntries$id_count + 1
653 700
       } else {