# HG changeset patch # User mingchen0919 # Date 1525148648 14400 # Node ID 1b637e0a30b6f2dee5e8644eaf2ccf87fe178b1d # Parent c0e57c994deb0ac9590922ed1493ae0a6b93129f planemo upload commit 61448862dc9016969191967aeefb7f7acce1e1f9-dirty diff -r c0e57c994deb -r 1b637e0a30b6 build-and-run-job-scripts.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build-and-run-job-scripts.sh Tue May 01 00:24:08 2018 -0400 @@ -0,0 +1,45 @@ +# run job scripts within the tool outputs directory +cd ${REPORT_FILES_PATH} + +#========== build and run job 1 script ============ +cat >job-1-script.sh < /dev/null 2>&1 +EOF + +# remove empty input lines +grep -v '\-M \\' temp.sh |\ + grep -v 'None' |\ + grep -v 'NO_ARGUMENT_NO' |\ + sed 's/NO_ARGUMENT_YES//g' > job-1-script.sh + +rm temp.sh + +# run job 1 script +sh job-1-script.sh + +# rename log file +if [ -e trim-trimmed.log ]; then + cp trim-trimmed.log trim-trimmed.txt +fi \ No newline at end of file diff -r c0e57c994deb -r 1b637e0a30b6 command-line-arguments.csv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/command-line-arguments.csv Tue May 01 00:24:08 2018 -0400 @@ -0,0 +1,27 @@ +short flag,argument mask,data type,variable name +o,1,character,report +d,1,character,report.files_path +A,1,character,first_reads +B,1,character,second_reads +x,1,character,adapter_first_reads +y,1,character,adapter_second_reads +m,1,character,trimming_mode +r,1,character,maximum_allowed_error_rate +D,1,character,maximum_allowed_indel_error_rate +q,1,character,quality_trimming_3_end +Q,1,character,mean_quality +l,1,character,minimum_read_length +j,1,character,advanced_options.junction_adapter +M,1,character,advanced_options.tab_adapter +b,1,character,advanced_options.barcode +c,1,character,advanced_options.cut +n,1,character,advanced_options.filter_degenerative_reads +u,1,character,advanced_options.filter_undetermined_mate_pair_reads +f,1,character,advanced_options.format +z,1,character,advanced_options.compress +E,1,character,advanced_options.qiime +F,1,character,advanced_options.quiet +i,1,character,advanced_options.intelligent +1,1,character,trimmed_r1 +2,1,character,trimmed_r2 +3,1,character,trimmed_s diff -r c0e57c994deb -r 1b637e0a30b6 expose-outputs-to-galaxy-history.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/expose-outputs-to-galaxy-history.sh Tue May 01 00:24:08 2018 -0400 @@ -0,0 +1,24 @@ +# change directory to tool outputs directory +cd ${REPORT_FILES_PATH} + +# copy outputs from tool outputs directory to corresponding galaxy output path +if [ -e "rmarkdown_report.html" ]; then + cp rmarkdown_report.html ${REPORT} +fi + +if [ -e "index.html" ]; then + cp index.html ${REPORT} +fi + + +if [ -e trim-trimmed-pair1.fastq ]; then + cp trim-trimmed-pair1.fastq ${X_1} +fi + +if [ -e trim-trimmed-pair2.fastq ]; then + cp trim-trimmed-pair2.fastq ${X_2} +fi + +if [ -e trim-trimmed.fastq ]; then + cp trim-trimmed.fastq ${X_3} +fi \ No newline at end of file diff -r c0e57c994deb -r 1b637e0a30b6 expose-outputs.sh --- a/expose-outputs.sh Thu Apr 26 14:10:58 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -# change directory to tool outputs directory -cd ${REPORT_FILES_PATH} - -# copy outputs from tool outputs directory to corresponding galaxy output path -cp skewer.html ${REPORT} - -if [ -e trim-trimmed-pair1.fastq ]; then - cp trim-trimmed-pair1.fastq ${X_1} -fi - -if [ -e trim-trimmed-pair2.fastq ]; then - cp trim-trimmed-pair2.fastq ${X_2} -fi - -if [ -e trim-trimmed.fastq ]; then - cp trim-trimmed.fastq ${X_3} -fi diff -r c0e57c994deb -r 1b637e0a30b6 getopt_specification.csv --- a/getopt_specification.csv Thu Apr 26 14:10:58 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -short flag,argument mask,data type,variable name -o,1,character,report -d,1,character,report.files_path -A,1,character,first_reads -B,1,character,second_reads -x,1,character,adapter_first_reads -y,1,character,adapter_second_reads -m,1,character,trimming_mode -r,1,character,maximum_allowed_error_rate -D,1,character,maximum_allowed_indel_error_rate -q,1,character,quality_trimming_3_end -Q,1,character,mean_quality -l,1,character,minimum_read_length -j,1,character,advanced_options.junction_adapter -M,1,character,advanced_options.tab_adapter -b,1,character,advanced_options.barcode -c,1,character,advanced_options.cut -n,1,character,advanced_options.filter_degenerative_reads -u,1,character,advanced_options.filter_undetermined_mate_pair_reads -f,1,character,advanced_options.format -z,1,character,advanced_options.compress -E,1,character,advanced_options.qiime -F,1,character,advanced_options.quiet -i,1,character,advanced_options.intelligent -1,1,character,trimmed_r1 -2,1,character,trimmed_r2 -3,1,character,trimmed_s \ No newline at end of file diff -r c0e57c994deb -r 1b637e0a30b6 helper.R --- a/helper.R Thu Apr 26 14:10:58 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -#' \code{getopt_specification_matrix} returns a getopt specification matrix. -#' -#' @param specification_file a cvs file within the \code{galaxy_tool_directory} which stores getopt specification matrix data. -#' The first column are short flags, the second column are argument masks, the third column -#' is data types. The fourth column are variable names used in the tool XML. These three columns are required. -#' @param gtg_name the name of a running GTG. -getopt_specification_matrix = function(specification_file, - gtg_name = 'gtg', - tool_dir = Sys.getenv('TOOL_DIR')) { - df = read.csv( - paste0(tool_dir, '/', specification_file), - header = TRUE, - stringsAsFactors = FALSE - ) - # check if there are duplicated short flags - short_flags = df[, 1] - if (length(unique(short_flags)) < length(short_flags)) { - cat('----Duplicated short flags found ----\n') - cat('short flags: ', df[, 1][duplicated(df[, 1])], '\n') - stop('Duplicated short flags are not allowed.') - } - - # use short flags to generate long flags - long_flags = paste0('X_', df[, 1]) - - # specification matrix - df2 = data.frame( - long_flags = long_flags, - short_flags = df[, 1], - argument_mask = df[, 2], - data_type = df[, 3] - ) - - as.matrix(df2) -} - - - -#' \code{file_tree} generate file tree of a directory in the format of HTML lists. -#' -#' @param dir the path to the directory for generating the file tree. -#' @param output_dir the REPORT_FILES_PATH folder name, which has the name style: dataset_NUMBER_files. -# define a recursive function to build html string of the file tree -file_tree = function(dir = '.') { - # get the OUTPUT_DIR folder data: dataset_NUMBER_files - report_files_path = Sys.getenv('REPORT_FILES_PATH') - output_dir = tail(strsplit(report_files_path, '/')[[1]], 1) - - files = list.files(path = dir, - recursive = FALSE, - full.names = TRUE) - # files also include directorys, need to remove directorys - files = files[!dir.exists(files)] - dirs = list.dirs(path = dir, - recursive = FALSE, - full.names = TRUE) - tags$ul({ - if (length(files) > 0) { - lapply(files, function(x) { - path_end = tail(strsplit(x, '/')[[1]], 1) - href_path = strsplit(x, paste0(output_dir, '/'))[[1]][2] - li_item = tags$li(tags$a(path_end, href = href_path)) - li_item$attribs = list('data-jstree' = '{"icon":"jstree-file"}') - li_item - }) - } - }, - { - if (length(dirs) > 0) { - lapply(dirs, function(x) { - path_end = tail(strsplit(x, '/')[[1]], 1) - # hide vakata-jstree-3.3.5 folder - if (path_end != 'vakata-jstree-3.3.5') { - # x_path = strsplit(x, paste0(output_dir, '/'))[[1]][2] - li_item = tags$li(path_end, file_tree(x)) - li_item$attribs = list('data-jstree' = '{"icon":"jstree-folder"}') - li_item - } - }) - } - }) -} diff -r c0e57c994deb -r 1b637e0a30b6 rmarkdown_report.Rmd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rmarkdown_report.Rmd Tue May 01 00:24:08 2018 -0400 @@ -0,0 +1,69 @@ +--- +title: 'Aurora Tool Report' +output: + html_document: + highlight: pygments +--- + +```{r setup, include=FALSE, warning=FALSE, message=FALSE} +knitr::opts_chunk$set(error = TRUE, echo = FALSE) +``` + +```{css echo=FALSE} +# code chunks scrollable +pre code, pre, code { + white-space: pre !important; + overflow-x: scroll !important; + word-break: keep-all !important; + word-wrap: initial !important; +} +``` + + +```{r, echo=FALSE} +# to make the css theme to work, tags cannot be added directly +# as tags as below. +# it has to be added using a code chunk with the htmltool functions!!! +css_link = tags$link() +css_link$attribs = list(rel="stylesheet", href="vakata-jstree-3.3.5/dist/themes/default/style.min.css") +css_link +``` + +```{r, eval=FALSE, echo=FALSE} +# this code chunk is purely for adding comments +# below is to add jQuery and jstree javascripts +``` + + + +--- +# javascript code below is to build the file tree interface +# see this for how to implement opening hyperlink: https://stackoverflow.com/questions/18611317/how-to-get-i-get-leaf-nodes-in-jstree-to-open-their-hyperlink-when-clicked-when +--- + + +--- +# ADD YOUR DATA ANALYSIS CODE AND MARKUP TEXT BELOW TO EXTEND THIS R MARKDOWN FILE +--- + +## Job script + +```{bash echo=FALSE} +sh ${TOOL_INSTALL_DIR}/build-and-run-job-scripts.sh +``` + +```{r echo=FALSE,warning=FALSE,results='asis'} +# display content of the job-script.sh file. +cat('```bash\n') +cat(readLines(paste0(Sys.getenv('REPORT_FILES_PATH'), '/job-1-script.sh')), sep = '\n') +cat('\n```') +``` + + diff -r c0e57c994deb -r 1b637e0a30b6 rmarkdown_report.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rmarkdown_report.xml Tue May 01 00:24:08 2018 -0400 @@ -0,0 +1,161 @@ + + A fast and accurate adapter trimmer for next-generation sequencing single or paired end reads. + + + pandoc + r-getopt + r-rmarkdown + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+
+ + + + `_ if you are not sure what parameter values to use.]]> + + + + + +
diff -r c0e57c994deb -r 1b637e0a30b6 rmarkdown_report_render.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rmarkdown_report_render.R Tue May 01 00:24:08 2018 -0400 @@ -0,0 +1,157 @@ +##============ Sink warnings and errors to a file ============== +## use the sink() function to wrap all code within it. +##============================================================== +zz = file(paste0(Sys.getenv('REPORT_FILES_PATH'), '/.r_rendering.log.txt')) +sink(zz) +sink(zz, type = 'message') + +#============== preparation ==================================== +# import libraries +#------------------------------------------------------------------ +# ADD MORE LIBRARIES HERE IF YOUR TOOL DEPENDS ON OTHER R LIBRARIES +#------------------------------------------------------------------ +library('getopt') +library('rmarkdown') +library('htmltools') +#------------------------------------------------------------------ +options(stringsAsFactors = FALSE) + + +# define two helper functions +#-----: helper function 1 +#' \code{getopt_specification_matrix} returns a getopt specification matrix. +#' +#' @param specification_file a cvs file within the \code{galaxy_tool_directory} which stores getopt specification matrix data. +#' The first column are short flags, the second column are argument masks, the third column +#' is data types. The fourth column are variable names used in the tool XML. These three columns are required. +#' @param gtg_name the name of a running GTG. +getopt_specification_matrix = function(specification_file, + gtg_name = 'gtg', + tool_dir = Sys.getenv('TOOL_INSTALL_DIR')) { + df = read.csv( + paste0(tool_dir, '/', specification_file), + header = TRUE, + stringsAsFactors = FALSE + ) + # check if there are duplicated short flags + short_flags = df[, 1] + if (length(unique(short_flags)) < length(short_flags)) { + cat('----Duplicated short flags found ----\n') + cat('short flags: ', df[, 1][duplicated(df[, 1])], '\n') + stop('Duplicated short flags are not allowed.') + } + + # use short flags to generate long flags + long_flags = paste0('X_', df[, 1]) + + # specification matrix + df2 = data.frame( + long_flags = long_flags, + short_flags = df[, 1], + argument_mask = df[, 2], + data_type = df[, 3] + ) + + as.matrix(df2) +} + +#-----: helper function 2 +#' \code{file_tree} generate file tree of a directory in the format of HTML lists. +#' +#' @param dir the path to the directory for generating the file tree. +#' @param output_dir the REPORT_FILES_PATH folder name, which has the name style: dataset_NUMBER_files. +# define a recursive function to build html string of the file tree +file_tree = function(dir = '.') { + # get the OUTPUT_DIR folder data: dataset_NUMBER_files + report_files_path = Sys.getenv('REPORT_FILES_PATH') + output_dir = tail(strsplit(report_files_path, '/')[[1]], 1) + + files = list.files(path = dir, + recursive = FALSE, + full.names = TRUE) + # files also include directorys, need to remove directorys + files = files[!dir.exists(files)] + dirs = list.dirs(path = dir, + recursive = FALSE, + full.names = TRUE) + tags$ul({ + if (length(files) > 0) { + lapply(files, function(x) { + path_end = tail(strsplit(x, '/')[[1]], 1) + href_path = strsplit(x, paste0(output_dir, '/'))[[1]][2] + li_item = tags$li(tags$a(path_end, href = href_path)) + li_item$attribs = list('data-jstree' = '{"icon":"jstree-file"}') + li_item + }) + } + }, + { + if (length(dirs) > 0) { + lapply(dirs, function(x) { + path_end = tail(strsplit(x, '/')[[1]], 1) + # hide vakata-jstree-3.3.5 folder + if (path_end != 'vakata-jstree-3.3.5') { + # x_path = strsplit(x, paste0(output_dir, '/'))[[1]][2] + li_item = tags$li(path_end, file_tree(x)) + li_item$attribs = list('data-jstree' = '{"icon":"jstree-folder"}') + li_item + } + }) + } + }) +} +#----------------- end of help functions ------------------------- + + +# import getopt specification matrix from a csv file +opt = getopt(getopt_specification_matrix('command-line-arguments.csv', + tool_dir = Sys.getenv('TOOL_INSTALL_DIR'))) +# define environment variables for all input values. this is useful when we +# want to use input values by other programming language in r markdown +do.call(Sys.setenv, opt[-1]) +#=============================================================== + + +#======================== render Rmd files ========================= +# copy jstree javascript library to tool output directory +file.copy( + from = paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/vakata-jstree-3.3.5'), + to = Sys.getenv('REPORT_FILES_PATH'), + recursive = TRUE +) + +# if '_site.yml' file exists, this tool is assumed to render a website. +# otherwise, it renders a single html. +if (file.exists(paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/_site.yml'))) { + # render a website + system(command = 'cp -r ${TOOL_INSTALL_DIR}/*.Rmd ${REPORT_FILES_PATH}') + system(command = 'cp -r ${TOOL_INSTALL_DIR}/_site.yml ${REPORT_FILES_PATH}') + render_site(input = Sys.getenv('REPORT_FILES_PATH')) +} else { + # render a single html + system(command = 'cp -r ${TOOL_INSTALL_DIR}/rmarkdown_report.Rmd ${REPORT_FILES_PATH}') + # add a few lines to 'rmarkdown_report.Rmd' to generate file tree outputs + jstree_lines = ' +## Outputs + +```{r, echo=FALSE} +tags$div(id="jstree", file_tree(Sys.getenv(\'REPORT_FILES_PATH\'))) +```' + write( + x = jstree_lines, + append = TRUE, + file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/rmarkdown_report.Rmd') + ) + render(input = paste0(Sys.getenv('REPORT_FILES_PATH'), '/rmarkdown_report.Rmd')) +} +#=============================================================== + + +#============== expose outputs to galaxy history =============== +system(command = 'sh ${TOOL_INSTALL_DIR}/expose-outputs-to-galaxy-history.sh') +#=============================================================== + + +##--------end of code rendering .Rmd templates---------------- +sink() +##=========== End of sinking output============================= diff -r c0e57c994deb -r 1b637e0a30b6 shell-script-template.sh --- a/shell-script-template.sh Thu Apr 26 14:10:58 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -# SHELL_SCRIPT file name -SHELL_SCRIPT='skewer.sh' - -# run SHELL_SCRIPT within tool outputs directory -cd ${REPORT_FILES_PATH} - -# build job-script.sh -cat >temp.sh < /dev/null 2>&1 -EOF - -# remove empty input lines -grep -v '\-M \\' temp.sh |\ - grep -v 'None' |\ - grep -v 'NO_ARGUMENT_NO' |\ - sed 's/NO_ARGUMENT_YES//g' > ${SHELL_SCRIPT} - -rm temp.sh - -# run SHELL_SCRIPT -sh ${SHELL_SCRIPT} - -# rename log file -if [ -e trim-trimmed.log ]; then - cp trim-trimmed.log trim-trimmed.txt -fi \ No newline at end of file diff -r c0e57c994deb -r 1b637e0a30b6 skewer.Rmd --- a/skewer.Rmd Thu Apr 26 14:10:58 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ ---- -title: 'Skewer report' -output: - html_document: - highlight: pygments ---- - -```{r setup, include=FALSE, warning=FALSE, message=FALSE} -knitr::opts_knit$set(progress = FALSE) -knitr::opts_chunk$set(error = TRUE, echo = FALSE) -``` - -```{r, echo=FALSE} -# to make the css theme to work, tags cannot be added directly -# as tags as below. -# it has to be added using a code chunk with the htmltool functions!!! -css_link = tags$link() -css_link$attribs = list(rel="stylesheet", href="vakata-jstree-3.3.5/dist/themes/default/style.min.css") -css_link -``` - -```{r, eval=FALSE, echo=FALSE} -# this code chunk is purely for adding comments -# below is to add jQuery and jstree javascripts -``` - - - -```{r, eval=FALSE, echo=FALSE} -# this code chunk is purely for adding comments -# javascript code below is to build the file tree interface -# see this for how to implement opening hyperlink: https://stackoverflow.com/questions/18611317/how-to-get-i-get-leaf-nodes-in-jstree-to-open-their-hyperlink-when-clicked-when -``` - - -```{css} -# code chunks scrollable -pre code, pre, code { - white-space: pre !important; - overflow-x: scroll !important; - word-break: keep-all !important; - word-wrap: initial !important; -} -``` ------------------------------------------ - -## Job script - -```{bash echo=FALSE} -sh ${TOOL_INSTALL_DIR}/shell-script-template.sh -``` - -```{r echo=FALSE,warning=FALSE,results='asis'} -# display content of the job-script.sh file. -cat('```bash\n') -cat(readLines(paste0(Sys.getenv('REPORT_FILES_PATH'), '/skewer.sh')), sep = '\n') -cat('\n```') -``` - - ------------------------------------------ -## Output - -```{r, echo=FALSE} -# create a div container to store the file tree interface -tags$div( - id="jstree", - file_tree(Sys.getenv('REPORT_FILES_PATH')) -) -``` - diff -r c0e57c994deb -r 1b637e0a30b6 skewer.xml --- a/skewer.xml Thu Apr 26 14:10:58 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,165 +0,0 @@ - - A fast and accurate adapter trimmer for next-generation sequencing single or paired end reads. - - - pandoc - r-getopt - r-rmarkdown - skewer - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
-
- - - - `_ if you are not sure what parameter values to use.]]> - - - - - -
diff -r c0e57c994deb -r 1b637e0a30b6 skewer_render.R --- a/skewer_render.R Thu Apr 26 14:10:58 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -##============ Sink warnings and errors to a file ============== -## use the sink() function to wrap all code within it. -##============================================================== -zz = file(paste0(Sys.getenv('REPORT_FILES_PATH'), '/.r_rendering.log.txt')) -sink(zz) -sink(zz, type = 'message') - -#============== preparation ==================================== -options(stringsAsFactors = FALSE) -# import libraries -#------------------------------------------------------------------ -# ADD MORE LIBRARIES HERE IF YOUR TOOL DEPENDS ON OTHER R LIBRARIES -#------------------------------------------------------------------ -library('getopt') -library('rmarkdown') -library('htmltools') - - -# load helper functions -source(paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/helper.R')) -# import getopt specification matrix from a csv file -opt = getopt(getopt_specification_matrix('getopt_specification.csv', - tool_dir=Sys.getenv('TOOL_INSTALL_DIR'))) -# define environment variables for all input values. this is useful when we -# want to use input values by other programming language in r markdown -do.call(Sys.setenv, opt[-1]) -#=============================================================== - - -#======================== render Rmd files ========================= -# NOTICE: -# we should copy all rmarkdown files from tool install directory to REPORT_FILES_PATH directory. -# and render rmarkdown files in the REPORT_FILES_PATH directory. -file.copy(from = paste0(Sys.getenv('TOOL_INSTALL_DIR'), '/vakata-jstree-3.3.5'), - to = Sys.getenv('REPORT_FILES_PATH'), recursive = TRUE) -system(command = 'cp -r ${TOOL_INSTALL_DIR}/*.Rmd ${REPORT_FILES_PATH}') - -#----------------BELOW IS WHERE YOU NEED TO CUSTOMIZE --------------------- -render(input = paste0(Sys.getenv('REPORT_FILES_PATH'), '/skewer.Rmd')) -# add more lines below if there are more Rmd files to be rendered - -#=============================================================== - - -#============== expose outputs to galaxy history =============== -system(command = 'sh ${TOOL_INSTALL_DIR}/expose-outputs.sh') -#=============================================================== - - -##--------end of code rendering .Rmd templates---------------- -sink() -##=========== End of sinking output============================= \ No newline at end of file