Commit b6f1ea4f authored by mmassaviol's avatar mmassaviol
Browse files

Add results_dir verification on run and rulegraph

Remove unused close session button
parent 7b916868
......@@ -609,86 +609,97 @@ generate_pages_server <- function() {
if ("RULEGRAPH" %in% names(APP)){
res <- res + '#\' Event when use RULEGRAPH button\n'
res <- res + 'observeEvent({c(input$sidebarmenu,input$refresh_rg)}, {\n\n'
res <- res + '\tif (!dir.exists(paste0(input$results_dir,"/logs"))){\n'
res <- res + '\t\tdir.create(paste0(input$results_dir,"/logs"))\n'
res <- res + '\t}\n'
res <- res + '\tif(input$sidebarmenu=="RULEGRAPH"){\n'
res <- res + '\t\tinput_list <- reactiveValuesToList(input)\n'
res <- res + '\t\ttoggle_inputs(input_list,F,F)\n'
res <- res + '\t\tpath_param <- paste0(input$results_dir,"/params.yml")\n\n'
res <- res + '\tif (input$sidebarmenu=="RULEGRAPH" & !dir.exists(input$results_dir)){\n'
res <- res + '\t\tshowModal(modalDialog(title = "Results directory error", "You need to choose a valid results directory",easyClose = TRUE,footer = NULL))\n'
res <- res + '\t}'
res <- res + '\telse{'
res <- res + '\t\tif (dir.exists(input$results_dir) & !dir.exists(paste0(input$results_dir,"/logs"))){\n'
res <- res + '\t\t\tdir.create(paste0(input$results_dir,"/logs"))\n'
res <- res + '\t\t}\n'
res <- res + '\t\tif(input$sidebarmenu=="RULEGRAPH"){\n'
res <- res + '\t\t\tinput_list <- reactiveValuesToList(input)\n'
res <- res + '\t\t\ttoggle_inputs(input_list,F,F)\n'
res <- res + '\t\t\tpath_param <- paste0(input$results_dir,"/params.yml")\n\n'
res <- res + '\t\tsave_params(path_param)\n'
res <- res + '\t\ti = sample.int(1000,size = 1)\n\n'
res <- res + '\t\tsystem(paste0("rm ",input$results_dir,"/rulegraph*"))\n\n'
res <- res + '\t\toutUI = tryCatch({\n'
res <- res + '\t\t\tsystem(paste0("snakemake -s /workflow/Snakefile --configfile ",input$results_dir,"/params.yml -d ",input$results_dir," all --rulegraph 1> ",input$results_dir,"/rulegraph",i,".dot 2> ",input$results_dir,"/logs/rulegraph.txt"),intern=T)\n'
res <- res + '\t\t\tsystem(paste0("cat ",input$results_dir,"/rulegraph",i,".dot | dot -Tsvg -Gratio=0.75 > ",input$results_dir,"/rulegraph",i,".svg"),intern=T)\n'
res <- res + '\t\t\ttagList(img(src = paste0("results/rulegraph",i,".svg") ,alt = "Rulegraph of Snakemake jobs",style="max-width: 100%;height: auto;display: block;margin: auto"))},\n'
res <- res + '\t\terror = function(e){\n'
res <- res + '\t\t\tsystem(paste0("touch ",input$results_dir,"/logs/workflow_end.error"),wait = T)\n'
res <- res + '\t\t\treturn(tags$p(HTML(paste(readLines(paste0(input$results_dir,"/logs/rulegraph.txt"),warn=F), collapse = "<br/>"))))},\n'
res <- res + '\t\twarning = function(w){\n'
res <- res + '\t\t\tsystem(paste0("touch ",input$results_dir,"/logs/workflow_end.error"),wait = T)\n'
res <- res + '\t\t\treturn(tags$p(HTML(paste(readLines(paste0(input$results_dir,"/logs/rulegraph.txt"),warn=F), collapse = "<br/>"))))})\n'
res <- res + '\t\taddResourcePath("results", input$results_dir)\n'
res <- res + '\t\toutput$RULEGRAPH_svg = renderUI(outUI)\n'
res <- res + '\t\ttoggle_inputs(input_list,T,F)\n'
res <- res + '}})\n'
res <- res + '\t\t\tsave_params(path_param)\n'
res <- res + '\t\t\ti = sample.int(1000,size = 1)\n\n'
res <- res + '\t\t\tsystem(paste0("rm ",input$results_dir,"/rulegraph*"))\n\n'
res <- res + '\t\t\toutUI = tryCatch({\n'
res <- res + '\t\t\t\tsystem(paste0("snakemake -s /workflow/Snakefile --configfile ",input$results_dir,"/params.yml -d ",input$results_dir," all --rulegraph 1> ",input$results_dir,"/rulegraph",i,".dot 2> ",input$results_dir,"/logs/rulegraph.txt"),intern=T)\n'
res <- res + '\t\t\t\tsystem(paste0("cat ",input$results_dir,"/rulegraph",i,".dot | dot -Tsvg -Gratio=0.75 > ",input$results_dir,"/rulegraph",i,".svg"),intern=T)\n'
res <- res + '\t\t\t\ttagList(img(src = paste0("results/rulegraph",i,".svg") ,alt = "Rulegraph of Snakemake jobs",style="max-width: 100%;height: auto;display: block;margin: auto"))},\n'
res <- res + '\t\t\terror = function(e){\n'
res <- res + '\t\t\t\tsystem(paste0("touch ",input$results_dir,"/logs/workflow_end.error"),wait = T)\n'
res <- res + '\t\t\t\treturn(tags$p(HTML(paste(readLines(paste0(input$results_dir,"/logs/rulegraph.txt"),warn=F), collapse = "<br/>"))))},\n'
res <- res + '\t\t\twarning = function(w){\n'
res <- res + '\t\t\t\tsystem(paste0("touch ",input$results_dir,"/logs/workflow_end.error"),wait = T)\n'
res <- res + '\t\t\t\treturn(tags$p(HTML(paste(readLines(paste0(input$results_dir,"/logs/rulegraph.txt"),warn=F), collapse = "<br/>"))))})\n'
res <- res + '\t\t\taddResourcePath("results", input$results_dir)\n'
res <- res + '\t\t\toutput$RULEGRAPH_svg = renderUI(outUI)\n'
res <- res + '\t\t\ttoggle_inputs(input_list,T,F)\n'
res <- res + '}}})\n'
}
# Event dry_run
res <- res + 'observeEvent({c(input$sidebarmenu,input$dry_run_button)}, {\n'
res <- res + '\n'
res <- res + '\tif (!dir.exists(paste0(input$results_dir,"/logs"))){\n'
res <- res + '\t\tdir.create(paste0(input$results_dir,"/logs"))\n'
res <- res + '\t}\n'
res <- res + '\tif(input$sidebarmenu=="RULEGRAPH"){\n'
res <- res + '\t\tinput_list <- reactiveValuesToList(input)\n'
res <- res + '\t\ttoggle_inputs(input_list,F,F)\n'
res <- res + '\t\tpath_param <- paste0(input$results_dir,"/params.yml")\n'
res <- res + '\tif (input$sidebarmenu=="RULEGRAPH" & !dir.exists(input$results_dir)){\n'
res <- res + '\t\tshowModal(modalDialog(title = "Results directory error", "You need to choose a valid results directory",easyClose = TRUE,footer = NULL))\n'
res <- res + '\t}'
res <- res + '\telse{'
res <- res + '\t\tif (dir.exists(input$results_dir) & !dir.exists(paste0(input$results_dir,"/logs"))){\n'
res <- res + '\t\t\tdir.create(paste0(input$results_dir,"/logs"))\n'
res <- res + '\t\t}\n'
res <- res + '\t\tif(input$sidebarmenu=="RULEGRAPH"){\n'
res <- res + '\t\t\tinput_list <- reactiveValuesToList(input)\n'
res <- res + '\t\t\ttoggle_inputs(input_list,F,F)\n'
res <- res + '\t\t\tpath_param <- paste0(input$results_dir,"/params.yml")\n'
res <- res + '\n'
res <- res + '\t\tsave_params(path_param)\n'
res <- res + '\t\t\tsave_params(path_param)\n'
res <- res + '\n'
res <- res + '\t\tforce = force_rule(input$force_from)\n'
res <- res + '\t\tcommand = paste0("Command line to run the workflow:<br/>","snakemake -s /workflow/Snakefile --configfile ", paste0(input$results_dir,"/params.yml") ,\t" -d ", input$results_dir ,\t" --cores ", input$cores, " all ", force, " -n -p<br/>This snakemake command needs the Snakefile and the params file of the workflow (remove -n for execution)<br/><br/>What will be done :<br/>")\n'
res <- res + '\t\tdry_out = system(paste0("snakemake -s /workflow/Snakefile --configfile ", paste0(input$results_dir,"/params.yml") ,\t" -d ", input$results_dir ,\t" --cores ", input$cores, " all ", force, " -n -p"),wait = T, intern=T)\n'
res <- res + '\t\tdryUI = tags$p(HTML(paste0(command, paste(dry_out, collapse = "<br/>"))))\n'
res <- res + '\t\t\tforce = force_rule(input$force_from)\n'
res <- res + '\t\t\tcommand = paste0("Command line to run the workflow:<br/>","snakemake -s /workflow/Snakefile --configfile ", paste0(input$results_dir,"/params.yml") ,\t" -d ", input$results_dir ,\t" --cores ", input$cores, " all ", force, " -n -p<br/>This snakemake command needs the Snakefile and the params file of the workflow (remove -n for execution)<br/><br/>What will be done :<br/>")\n'
res <- res + '\t\t\tdry_out = system(paste0("snakemake -s /workflow/Snakefile --configfile ", paste0(input$results_dir,"/params.yml") ,\t" -d ", input$results_dir ,\t" --cores ", input$cores, " all ", force, " -n -p"),wait = T, intern=T)\n'
res <- res + '\t\t\tdryUI = tags$p(HTML(paste0(command, paste(dry_out, collapse = "<br/>"))))\n'
res <- res + '\n'
res <- res + '\t\toutput$dry_run_div = renderUI(dryUI)\n'
res <- res + '\t\ttoggle_inputs(input_list,T,F)\n'
res <- res + '\t}})\n'
res <- res + '\t\t\toutput$dry_run_div = renderUI(dryUI)\n'
res <- res + '\t\t\ttoggle_inputs(input_list,T,F)\n'
res <- res + '\t}}})\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 + '\trv$running = T\n'
res <- res + '\tinput_list <- reactiveValuesToList(input)\n'
res <- res + '\ttoggle_inputs(input_list,F,F)\n'
res <- res + '\tupdateTabsetPanel(session, "sidebarmenu", selected = "run_out")\n'
res <- res + '\tif (!dir.exists(input$results_dir)){\n'
res <- res + '\t\tshowModal(modalDialog(title = "Results directory error", "You need to choose a valid results directory",easyClose = TRUE,footer = NULL))\n'
res <- res + '\t}'
res <- res + '\telse{'
res <- res + '\t\trv$running = T\n'
res <- res + '\t\tinput_list <- reactiveValuesToList(input)\n'
res <- res + '\t\ttoggle_inputs(input_list,F,F)\n'
res <- res + '\t\tupdateTabsetPanel(session, "sidebarmenu", selected = "run_out")\n'
#panel_path <- output_dir + '/params/' + 'params_' + APP$pages[[x]]$name + '.yml'
res <- res + '\tpath_param <- paste0(input$results_dir,"/params.yml")\n\n'
res <- res + '\t\tpath_param <- paste0(input$results_dir,"/params.yml")\n\n'
res <- res + '\t\tsave_params(path_param)\n'
res <- res + '\t\t\tsave_params(path_param)\n'
res <- res + '\n\n'
res <- res + '\toutUI = tryCatch({\n'
res <- res + '\t\tif (!dir.exists(paste0(input$results_dir,"/logs"))){\n'
res <- res + '\t\t\tdir.create(paste0(input$results_dir,"/logs"))\n'
res <- res + '\t\t}\n'
res <- res + '\t\tif (!file.exists(paste0(input$results_dir,"/logs/runlog.txt"))){\n'
res <- res + '\t\t\tfile.create(paste0(input$results_dir,"/logs/runlog.txt"))\n'
res <- res + '\t\t}\n'
res <- res + '\t\tif (file.exists(paste0(input$results_dir,"/logs/workflow_end.ok"))){\n'
res <- res + '\t\t\tfile.remove(paste0(input$results_dir,"/logs/workflow_end.ok"))\n'
res <- res + '\t\t}\n'
res <- res + '\t\tif (file.exists(paste0(input$results_dir,"/logs/workflow_end.error"))){\n'
res <- res + '\t\t\tfile.remove(paste0(input$results_dir,"/logs/workflow_end.error"))\n'
res <- res + '\t\t}\n'
res <- res + '\t\toutUI = tryCatch({\n'
res <- res + '\t\t\tif (!dir.exists(paste0(input$results_dir,"/logs"))){\n'
res <- res + '\t\t\t\tdir.create(paste0(input$results_dir,"/logs"))\n'
res <- res + '\t\t\t}\n'
res <- res + '\t\t\tif (!file.exists(paste0(input$results_dir,"/logs/runlog.txt"))){\n'
res <- res + '\t\t\t\tfile.create(paste0(input$results_dir,"/logs/runlog.txt"))\n'
res <- res + '\t\t\t}\n'
res <- res + '\t\t\tif (file.exists(paste0(input$results_dir,"/logs/workflow_end.ok"))){\n'
res <- res + '\t\t\t\tfile.remove(paste0(input$results_dir,"/logs/workflow_end.ok"))\n'
res <- res + '\t\t\t}\n'
res <- res + '\t\t\tif (file.exists(paste0(input$results_dir,"/logs/workflow_end.error"))){\n'
res <- res + '\t\t\t\tfile.remove(paste0(input$results_dir,"/logs/workflow_end.error"))\n'
res <- res + '\t\t\t}\n'
# res <- res + '\t\tforcerun = compare_params(input$results_dir)\n'
# res <- res + '\t\tif (length(forcerun>1)){\n'
......@@ -703,29 +714,29 @@ generate_pages_server <- function() {
# res <- res + '\t\t\tforcerun = ""\n'
# res <- res + '\t\t}\n'
res <- res + '\t\tsystem(paste0("touch ",input$results_dir,"/logs/workflow.running"),wait = T)\n'
res <- res + '\t\t\tsystem(paste0("touch ",input$results_dir,"/logs/workflow.running"),wait = T)\n'
# RULEGRAPH
res <- res + '\t\t\tsystem(paste0("snakemake -s /workflow/Snakefile --configfile ",input$results_dir,"/params.yml -d ",input$results_dir," all --rulegraph | dot -Tpng -Gratio=0.75 > ",input$results_dir,"/Rule_graph_mqc.png"),wait = T)\n'
res <- res + '\t\t\t\tsystem(paste0("snakemake -s /workflow/Snakefile --configfile ",input$results_dir,"/params.yml -d ",input$results_dir," all --rulegraph | dot -Tpng -Gratio=0.75 > ",input$results_dir,"/Rule_graph_mqc.png"),wait = T)\n'
# RUN
res <- res + '\t\tforce = force_rule(input$force_from)\n'
res <- res + '\t\trerun = if (input$rerun_incomplete) "--rerun-incomplete" else ""\n'
res <- res + '\t\t\tforce = force_rule(input$force_from)\n'
res <- res + '\t\t\trerun = if (input$rerun_incomplete) "--rerun-incomplete" else ""\n'
## DRY RUN
res <- res + '\t\t\tcommand = paste0("Command line to run the workflow:<br/>","snakemake -s /workflow/Snakefile --configfile ", paste0(input$results_dir,"/params.yml") ,\t" -d ", input$results_dir ,\t" --cores ", input$cores, " all ", force, " -n -p<br/>This snakemake command needs the Snakefile and the params file of the workflow (remove -n for execution)<br/><br/>What will be done :<br/>")\n'
res <- res + '\t\t\tsystem(paste0("snakemake -s /workflow/Snakefile --configfile ", paste0(input$results_dir,"/params.yml") ," -d ", input$results_dir ," --cores ", input$cores, " all ", force, " ", rerun, " -n -p > ", input$results_dir, "/Run_Summary_mqc.html"),wait = T)\n'
res <- res + '\t\t\tsystem(paste0("sed -i \'1 i\\\\<pre>",command,"\' ",input$results_dir,"/Run_Summary_mqc.html"))\n'
res <- res + '\t\tsystem2("python3",paste0("-u -m snakemake -s /workflow/Snakefile --configfile ", paste0(input$results_dir,"/params.yml") ,\t" -d ", input$results_dir ,\t" --cores ", input$cores, " all ", force, " ",rerun),wait = FALSE, stdout = paste0(input$results_dir,"/logs/runlog.txt"), stderr = paste0(input$results_dir,"/logs/runlog.txt"))\n'
res <- res + '\t\ttags$iframe(src="results/multiqc_report.html",width="100%", height="900px")},\n'
res <- res + '\t\terror = function(e){\n'
res <- res + '\t\t\tsystem(paste0("touch ",input$results_dir,"/logs/workflow_end.error"),wait = T)\n'
res <- res + '\t\t\treturn(tags$p(paste0("error : ",e$message)))},\n'
res <- res + '\t\twarning = function(w){\n'
res <- res + '\t\t\tsystem(paste0("touch ",input$results_dir,"/logs/workflow_end.error"),wait = T)\n'
res <- res + '\t\t\treturn(tags$p(paste0("error : ",w$message)))})\n'
res <- res + '\t\t})\n\n'
res <- res + '\t\t\t\tcommand = paste0("Command line to run the workflow:<br/>","snakemake -s /workflow/Snakefile --configfile ", paste0(input$results_dir,"/params.yml") ,\t" -d ", input$results_dir ,\t" --cores ", input$cores, " all ", force, " -n -p<br/>This snakemake command needs the Snakefile and the params file of the workflow (remove -n for execution)<br/><br/>What will be done :<br/>")\n'
res <- res + '\t\t\t\tsystem(paste0("snakemake -s /workflow/Snakefile --configfile ", paste0(input$results_dir,"/params.yml") ," -d ", input$results_dir ," --cores ", input$cores, " all ", force, " ", rerun, " -n -p > ", input$results_dir, "/Run_Summary_mqc.html"),wait = T)\n'
res <- res + '\t\t\t\tsystem(paste0("sed -i \'1 i\\\\<pre>",command,"\' ",input$results_dir,"/Run_Summary_mqc.html"))\n'
res <- res + '\t\t\tsystem2("python3",paste0("-u -m snakemake -s /workflow/Snakefile --configfile ", paste0(input$results_dir,"/params.yml") ,\t" -d ", input$results_dir ,\t" --cores ", input$cores, " all ", force, " ",rerun),wait = FALSE, stdout = paste0(input$results_dir,"/logs/runlog.txt"), stderr = paste0(input$results_dir,"/logs/runlog.txt"))\n'
res <- res + '\t\t\ttags$iframe(src="results/multiqc_report.html",width="100%", height="900px")},\n'
res <- res + '\t\t\terror = function(e){\n'
res <- res + '\t\t\t\tsystem(paste0("touch ",input$results_dir,"/logs/workflow_end.error"),wait = T)\n'
res <- res + '\t\t\t\treturn(tags$p(paste0("error : ",e$message)))},\n'
res <- res + '\t\t\twarning = function(w){\n'
res <- res + '\t\t\t\tsystem(paste0("touch ",input$results_dir,"/logs/workflow_end.error"),wait = T)\n'
res <- res + '\t\t\t\treturn(tags$p(paste0("error : ",w$message)))})\n'
res <- res + '\t\t\t}})\n\n'
for(page in APP$pages){
for(box in page$boxes){
......@@ -837,8 +848,8 @@ generate_menu <- function() {
res <- res + '\tmenuItem("'+menu+'", tabName="'+name+'", icon=icon("'+icon+'", lib="font-awesome"), newtab=FALSE),\n\n'
}
res <- res + '\ttags$br(),\n'
res <- res + '\tactionButton("close_session", "Close session", icon("times"), class="btn btn-primary"),\n'
#res <- res + '\ttags$br(),\n'
#res <- res + '\tactionButton("close_session", "Close session", icon("times"), class="btn btn-primary"),\n'
res <- res + '\ttags$br(),tags$br(),\n\n'
......
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