Commit ec883199 authored by mmassaviol's avatar mmassaviol
Browse files

Add disabling inputs when command running

Add tryCatch arround snakemake commands
Replace DAG by RULEGRAPH
parent abd0bf5f
source("tools.R")
library(yaml)
path_yml <- "/home/mbb/Documents/waw/workflows/RNAseq/sag.yaml"
path_yml <- "/home/mbb/Documents/waw/workflows/RADseq_ref/sag.yaml"
#path_tools <- "/home/mbb/Documents/waw/tools"
......@@ -567,10 +567,12 @@ generate_pages_server <- function() {
file.replace(APP$project+"/server/opt_global.R")
res <- ""
# Event DAG
if ("DAG" %in% names(APP)){
res <- '#\' Event when use DAG button\n'
res <- res + 'observeEvent(input$DAG, {\n\n'
# Event RULEGRAPH
if ("RULEGRAPH" %in% names(APP)){
res <- '#\' Event when use RULEGRAPH button\n'
res <- res + 'observeEvent(input$RULEGRAPH, {\n\n'
res <- res + '\tinput_list <- reactiveValuesToList(input)\n'
res <- res + '\ttoggle_inputs(input_list,F,F)\n'
res <- res + '\tpath_param <- "/results/params.yml' + '"\n\n'
res <- res + '\tres <- ""'
res <- res + resG
......@@ -588,20 +590,33 @@ generate_pages_server <- function() {
res <- res + '\tsamples = yaml.load(system("python3 /workflow/get_samples.py /samples /samples/groups.csv",intern = T))\n'
res <- res + '\tc$samples = names(samples)\n'
res <- res + '\tc$names(samples) = NULL\n'
res <- res + '\tnames(samples) = NULL\n'
res <- res + '\tc$groups = unlist(samples)\n'
res <- res + '\twrite_yaml(c,"/results/params.yml",handlers=list(logical = logical))\n'
res <- res + '\ti = sample.int(1000,size = 1)\n'
res <- res + '\tsystem(paste0("snakemake -s /workflow/Snakefile --configfile /results/params.yml -d /results --dag | dot -Tsvg -Gratio=0.75 > /results/dag",i,".svg"))\n'
res <- res + '\ti = sample.int(1000,size = 1)\n\n'
res <- res + '\tsystem("rm /results/rulegraph*")\n\n'
res <- res + '\toutUI = tryCatch({\n'
res <- res + '\t\tsystem(paste0("snakemake -s /workflow/Snakefile --configfile /results/params.yml -d /results --rulegraph > /results/rulegraph",i,".dot"),intern=T)\n'
res <- res + '\t\tsystem(paste0("cat /results/rulegraph",i,".dot | dot -Tsvg -Gratio=0.75 > /results/rulegraph",i,".svg"),intern=T)\n'
res <- res + '\t\ttagList(img(src = paste0("results/rulegraph",i,".svg") ,alt = "Rulegraph of Snakemake jobs",width="100%",height="auto"))},\n'
res <- res + '\terror = function(e){return(tags$p(paste0("error : ",e$message)))},\n'
res <- res + '\twarning = function(w){return(tags$p(paste0("warning : ",w$message)))})\n'
res <- res + '\taddResourcePath("results", "/results")\n'
res <- res + 'output$DAG_svg = renderUI({tagList(img(src = paste0("results/dag",i,".svg") ,alt = "DAG of Snakemake jobs",width="100%",height="auto"))})\n'
res <- res + '\toutput$RULEGRAPH_svg = renderUI(outUI)\n'
res <- res + '\ttoggle_inputs(input_list,T,F)\n'
res <- res + '})\n'
}
# Event Run
res <- res + '#\' Event when use '+ run$shiny_button$name +' button\n'
res <- res + 'observeEvent(input$'+run$shiny_button$name+', {\n\n'
res <- res + '\tinput_list <- reactiveValuesToList(input)\n'
res <- res + '\ttoggle_inputs(input_list,F,F)\n'
panel_path <- APP$project + '/params/' + 'params_' + APP$pages[[x]]$name + '.yml'
res <- res + '\tpath_param <- "/results/' + 'params.yml' + '"\n\n'
res <- res + '\tres <- ""'
......@@ -623,7 +638,7 @@ generate_pages_server <- function() {
res <- res + '\t}\n'
res <- res + '\tsamples = yaml.load(system("python3 /workflow/get_samples.py /samples /samples/groups.csv",intern = T))\n'
res <- res + '\tc$samples = names(samples)\n'
res <- res + '\tc$names(samples) = NULL\n'
res <- res + '\tnames(samples) = NULL\n'
res <- res + '\tc$groups = unlist(samples)\n'
res <- res + '\twrite_yaml(c,"/results/params.yml",handlers=list(logical = logical))\n'
......@@ -633,7 +648,10 @@ generate_pages_server <- function() {
res <- res + '\n\n'
res <- res + '\tsystem(paste(" '
res <- res + '\toutUI = tryCatch({\n'
res <- res + '\t\tsystem(paste(" '
res <- res + run$program + '", '
......@@ -658,12 +676,18 @@ generate_pages_server <- function() {
}
res <- res + ', sep = " " ))\n\n'
res <- res + ', sep = " " ),intern=T)\n'
res <- res + '\t\ttags$iframe(src="results/report.html",width="100%", height="900px")},\n'
res <- res + '\terror = function(e){return(tags$p(paste0("error : ",e$message)))},\n'
res <- res + '\twarning = function(w){return(tags$p(paste0("warning : ",w$message)))})\n'
res <- res + 'addResourcePath("results", "/results")\n'
res <- res + 'output$report_html = renderUI(tags$iframe(src="results/report.html",width="100%", height="900px"))\n\n'
res <- res + '\taddResourcePath("results", "/results")\n'
res <- res + '\toutput$report_html = renderUI(outUI)\n\n'
res <- res + '\n\n'
res <- res + '\ttoggle_inputs(input_list,T,F)\n'
res <- res + '})\n\n'
......@@ -689,29 +713,22 @@ generate_menu <- function() {
res <- res + ' menuItem("'+menu+'", tabName="'+name+'", icon=icon("'+icon+'", lib="font-awesome"), newtab=FALSE),\n\n'
}
if("DAG" %in% names(APP)){
name <- "DAG"
if("RULEGRAPH" %in% names(APP)){
name <- "RULEGRAPH"
icon <- "gear"
menu <- "DAG"
menu <- "Rule Graph"
res <- res + ' menuItem("'+menu+'", tabName="'+name+'", icon=icon("'+icon+'", lib="font-awesome"), newtab=FALSE),\n\n'
}
if("Report" %in% names(APP)){
name <- "Report"
icon <- "file"
menu <- "Report"
res <- res + ' menuItem("'+menu+'", tabName="'+name+'", icon=icon("'+icon+'", lib="font-awesome"), newtab=FALSE),\n\n'
}
res <- res + ' tags$br(),\n\n'
res <- res + ' numericInput("cores", label = "Threads available", min = 1, max = NA, step = 1, width = "auto", value = 4),\n'
if("DAG" %in% names(APP)){
if("RULEGRAPH" %in% names(APP)){
res <- res + ' tags$br(),\n\n'
res <- res + ' actionButton("DAG", "DAG", icon("gear") , class="btn btn-info"),\n\n'
res <- res + ' actionButton("RULEGRAPH", "Rule Graph", icon("gear") , class="btn btn-info"),\n\n'
}
......@@ -719,6 +736,15 @@ generate_menu <- function() {
res <- res + ' actionButton("'+ APP$run$shiny_button$name +'", "'+ APP$run$shiny_button$label +'", icon("'+ APP$run$shiny_button$icon +'"), class="'+ APP$run$shiny_button$class +'"),\n\n'
if("Report" %in% names(APP)){
res <- res + ' tags$br(),\n'
res <- res + ' tags$br(),\n'
name <- "Report"
icon <- "file"
menu <- "Report"
res <- res + ' menuItem("'+menu+'", tabName="'+name+'", icon=icon("'+icon+'", lib="font-awesome"), newtab=FALSE),\n\n'
}
if("download" %in% names(APP)){
res <- res + ' tags$br(),\n\n'
......@@ -844,8 +870,8 @@ generate_app <- function() {
name <- APP$pages[[x]]$name
res <- res + 'source("./pages/pages_def_'+tolower(name)+'.R", local=T)\n'
}
if("DAG" %in% names(APP)){
res <- res + "tabDAG = fluidPage(box(title = 'DAG :', width = 12, status = 'primary', collapsible = TRUE, solidHeader = TRUE, uiOutput('DAG_svg')))\n"
if("RULEGRAPH" %in% names(APP)){
res <- res + "tabRULEGRAPH = fluidPage(box(title = 'Rule Graph :', width = 12, status = 'primary', collapsible = TRUE, solidHeader = TRUE, uiOutput('RULEGRAPH_svg')))\n"
}
if("Report" %in% names(APP)){
res <- res + "tabReport = fluidPage(box(title = 'Report :', width = 12, status = 'primary', collapsible = TRUE, solidHeader = TRUE, uiOutput('report_html')))\n"
......@@ -884,8 +910,8 @@ generate_app <- function() {
res <- res + "\n\n"
}
}
if("DAG" %in% names(APP)){
res <- res + '\t,tabItem(tabName = "DAG", tabDAG)'
if("RULEGRAPH" %in% names(APP)){
res <- res + '\t,tabItem(tabName = "RULEGRAPH", tabRULEGRAPH)'
}
if("Report" %in% names(APP)){
res <- res + '\t,tabItem(tabName = "Report", tabReport)'
......@@ -898,6 +924,21 @@ generate_app <- function() {
res <- res + '\n\n'
res <- res + 'server <- function( input, output, session) {\n\n'
res <- res + 'toggle_inputs <- function(input_list,enable_inputs=T,only_buttons=FALSE)\n'
res <- res + '{\n'
res <- res + '\t# Subset if only_buttons is TRUE.\n'
res <- res + '\tif(only_buttons){\n'
res <- res + '\t\tbuttons <- which(sapply(input_list,function(x) {any(grepl("Button",attr(x,"class")))}))\n'
res <- res + '\t\tinput_list = input_list[buttons]\n'
res <- res + '\t}\n\n'
res <- res + '\t# Toggle elements\n'
res <- res + '\tfor(x in names(input_list))\n'
res <- res + '\t\tif(enable_inputs){\n'
res <- res + '\t\t\tshinyjs::enable(x)} else {\n'
res <- res + '\t\t\t\tshinyjs::disable(x) }\n'
res <- res + '}\n\n'
res <- res + 'source("./server/opt_global.R", local=T)\n'
......
......@@ -199,5 +199,5 @@ App:
- {name: --configfile, type: value, value: /results/params.yml}
- {name: -d, type: value, value: /results}
- {name: --cores, type: shiny, value: cores}
DAG: null
RULEGRAPH: null
Report: null
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment