Commit 49b678c8 authored by ziegenhain@bio.lmu.de's avatar ziegenhain@bio.lmu.de
Browse files

update shiny app

parent cf69a1d0
Loading
Loading
Loading
Loading
+181 −119
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ library(yaml)
ui <- fluidPage(
  # Application title
  titlePanel("zUMIs-config: Generate yaml file"),
   navlistPanel(widths = c(2, 10),
  navlistPanel(id = "mainNav",widths = c(2, 10),
               tabPanel("Mandatory Parameters",
                        #set basic things
                        fluidRow(
@@ -97,7 +97,7 @@ ui <- fluidPage(
                            textInput("downsamp",label = "Number of reads to downsample to. This value can be a fixed number of reads (e.g. 10000) or a desired range (e.g. 10000-20000). 0 invokes adaptive downsampling.",value = "0"),
                            selectInput("strand",label = "Is the library stranded?",choices = c("unstranded" = 0, "positively stranded" = 1, "negatively stranded" = 2),selected = "unstranded",multiple = F),
                            numericInput("HamDist","Hamming distance collapsing of UMI sequences:",value=0,min=0,max=5,step=1),
       checkboxInput("doVelocity",label="Generate velocyto-compatible counting of intron-exon spanning reads",value = F),
                            checkboxInput("doVelocity",label="Generate velocyto-compatible counting of intron-exon spanning reads. ATTENTION! This option is currently not implemented!",value = F),
                            checkboxInput("countPrimary",label="Count the primary Hits of multimapping reads towards gene expression levels?",value = T),
                            checkboxInput("twoPass",label="Perform basic STAR twoPass mapping?",value = T)
                          )),
@@ -115,11 +115,12 @@ tabPanel("Generate YAML!",
                        p(strong("Your YAML is nearly ready...")),
                        uiOutput("saveUI"),
                        actionButton(inputId = "SaveYAML",label = "Save YAML!")
# ),
# tabPanel("Load YAML",
#   p(strong("You can load an existing YAML for zUMIs here")),
#   textInput(inputId="inYAML", label="Full path to YAML file", placeholder="eg: /path/to.yaml"),
#   actionButton(inputId = "LoadYAML",label = "Load YAML!")
                         ),
                         tabPanel("Load YAML",
                           p(strong("You can load an existing YAML for zUMIs here")),
                           textInput(inputId="inYAML", label="Full path to YAML file", placeholder="eg: /path/to.yaml"),
                           actionButton(inputId = "LoadYAML",label = "Load YAML!"),
                           p(strong("Please click the Load button twice for all options to be properly set in shiny! Sorry for the inconvenience."))
               )
  ))

@@ -273,8 +274,20 @@ server <- function(input, output, session) {
  }

  observeEvent(input$LoadYAML, {

    if(file.exists(input$inYAML)){
      ya <- read_yaml(file = input$inYAML)
      print(paste("Loading",input$inYAML))
      loading_func(input$inYAML)
      updateNavlistPanel(session = session, inputId = "mainNav",selected = "Mandatory Parameters")
      }else{
        print("File doesn't exist!")
      }

  })

  loading_func <- function(myYAML){

      ya <- read_yaml(file = myYAML)
      updateTextInput(session = session,inputId = "runID",value = ya$project)
      updateTextInput(session = session,inputId = "outDir",value = ya$out_dir)
      updateTextInput(session = session,inputId = "STARpath",value = ya$reference$STAR_index)
@@ -284,14 +297,63 @@ server <- function(input, output, session) {
      if(length(ya$reference$additional_files)>0){
        for(i in 1:length(ya$reference$additional_files)){
          updateTextInput(session = session,inputId = paste0("FA_",i), value = ya$reference$additional_files[i])
          print(input[[paste0("FA_",i)]])
        }
      }
      updateSliderInput(session = session, inputId = "nfiles", value = length(ya$sequence_files))
      for(i in 1:length(ya$sequence_files)){
        updateTextInput(session = session,inputId = paste0("fqpath_",i), value = ya$sequence_files[[i]]$name)

        if(any(grepl("BC",ya$sequence_files[[i]]$base_definition))){
          bc_string <- grep("BC",ya$sequence_files[[i]]$base_definition,value = T)
          bc_string <- substr(bc_string,start = 4, stop = nchar(bc_string)-1)
          updateTextInput(session = session,inputId = paste0("BC_",i), value = bc_string)
        }
        if(any(grepl("UMI",ya$sequence_files[[i]]$base_definition))){
          umi_string <- grep("UMI",ya$sequence_files[[i]]$base_definition,value = T)
          umi_string <- substr(umi_string,start = 5, stop = nchar(umi_string)-1)
          updateTextInput(session = session,inputId = paste0("UMI_",i), value = umi_string)
        }
        if(any(grepl("cDNA",ya$sequence_files[[i]]$base_definition))){
          cdna_string <- grep("cDNA",ya$sequence_files[[i]]$base_definition,value = T)
          cdna_string <- substr(cdna_string,start = 6, stop = nchar(cdna_string)-1)
          updateTextInput(session = session,inputId = paste0("cDNA_",i), value = cdna_string)
        }

      }

      updateNumericInput(session = session, inputId = "BCbases", value = ya$filter_cutoffs$BC_filter$num_bases)
      updateNumericInput(session = session, inputId = "BCphred", value = ya$filter_cutoffs$BC_filter$phred)
      updateNumericInput(session = session, inputId = "UMIbases", value = ya$filter_cutoffs$UMI_filter$num_bases)
      updateNumericInput(session = session, inputId = "UMIphred", value = ya$filter_cutoffs$UMI_filter$phred)
      updateNumericInput(session = session, inputId = "numThreads", value = ya$num_threads)
      updateNumericInput(session = session, inputId = "memLimit", value = ya$mem_limit)
      updateCheckboxInput(session = session, inputId = "makeStats", value = ya$make_stats)
      updateCheckboxInput(session = session, inputId = "useSLURM", value = ya$use_SLURM)
      updateSelectInput(session = session, inputId = "whichStage", selected = ya$which_Stage)
      updateCheckboxInput(session = session, inputId = "countIntrons", value = ya$counting_opts$introns)
      updateTextInput(session = session, inputId = "downsamp", value = ya$counting_opts$downsampling)
      updateSelectInput(session = session, inputId = "strand", selected = ya$counting_opts$strand)
      updateNumericInput(session = session, inputId = "HamDist", value = ya$counting_opts$Ham_Dist)
      updateCheckboxInput(session = session, inputId = "doVelocity", value = ya$counting_opts$velocyto)
      updateCheckboxInput(session = session, inputId = "countPrimary", value = ya$counting_opts$primaryHit)
      updateCheckboxInput(session = session, inputId = "twoPass", value = ya$counting_opts$twoPass)
      if (is.null(ya$barcodes$barcode_num & ya$barcodes$barcode_file)) {
        updateRadioButtons(session = session, inputId = "barcodeChoice", selected = "Automatic")
      }
      if (!is.null(ya$barcodes$barcode_file)){
        updateRadioButtons(session = session, inputId = "barcodeChoice", selected = "Barcod whitelist")
        updateTextInput(session = session, inputId = "BCfile", value = ya$barcodes$barcode_file)
      }
      if (!is.null(ya$barcodes$barcode_num)){
        updateRadioButtons(session = session, inputId = "barcodeChoice", selected = "Number of top Barcodes")
        updateNumericInput(session = session, inputId = "BCnum", value = ya$barcodes$barcode_num)
      }

      updateNumericInput(session = session, inputId = "HamBC", value = ya$barcodes$BarcodeBinning)
      updateNumericInput(session = session, inputId = "nReadsBC", value = ya$barcodes$nReadsperCell)


    }else{
      print("File doesn't exist!")
  }
  })

}