Mercurial > repos > mingchen0919 > aurora_data
changeset 0:ebb7afcb2b75 draft default tip
planemo upload
| author | mingchen0919 |
|---|---|
| date | Tue, 17 Apr 2018 10:58:55 -0400 |
| parents | |
| children | |
| files | aurora_data.Rmd aurora_data.xml aurora_data_render.R helper.R |
| diffstat | 4 files changed, 268 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aurora_data.Rmd Tue Apr 17 10:58:55 2018 -0400 @@ -0,0 +1,111 @@ +--- +title: 'HTML report title' +output: + html_document: + highlight: pygments +--- + +```{r, echo=FALSE} +# to make the css theme to work, <link></link> tags cannot be added directly +# as <script></script> 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 +``` +<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> +<script src="vakata-jstree-3.3.5/dist/jstree.min.js"></script> + +```{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 +``` +<script> + $(function () { + // create an instance when the DOM is ready + $('#jstree').jstree().bind("select_node.jstree", function (e, data) { + window.open( data.node.a_attr.href, data.node.a_attr.target ) + }); + }); +</script> + +```{r setup, include=FALSE, warning=FALSE, message=FALSE} +knitr::opts_chunk$set(echo = TRUE, error = TRUE) +``` + + + + + + + + + + + + + + + + + + + + + +# Output + +```{bash, echo=FALSE} +# copy jstree directory to output directory +cp -r ${X_t}/vakata-jstree-3.3.5 ${X_d} +``` + +```{r, echo=FALSE} +# get the OUTPUT_DIR folder data: dataset_NUMBER_files +output_dir = tail(strsplit(opt$X_d, '/')[[1]], 1) +# define a recursive function to build html string of the file tree +file_tree = function(dir = '.'){ + 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){ + x_path = strsplit(x, paste0(output_dir, '/'))[[1]][2] + li_item = tags$li(x_path, file_tree(x)) + li_item$attribs = list('data-jstree'='{"icon":"jstree-folder"}') + li_item + }) + } + } + ) +} +``` + +```{r, echo=FALSE} +# create a div container to store the file tree interface +tags$div( + id="jstree", + file_tree(opt$X_d) +) +``` +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aurora_data.xml Tue Apr 17 10:58:55 2018 -0400 @@ -0,0 +1,51 @@ +<tool id="aurora_data" name="aurora_data" version="1.0.0"> + <description>Collect data for other aurora galaxy tools.</description> + <requirements> + <requirement type="package" version="1.15.0.6-0">pandoc</requirement> + <requirement type="package" version="1.20.0">r-getopt</requirement> + <requirement type="package" version="1.6">r-rmarkdown</requirement> + </requirements> + <stdio> + <regex match="XXX" source="stderr" level="warning" + description="Check the warnings_and_errors.txt file for more details."/> + </stdio> + <command><![CDATA[ + export TOOL_DIR='${__tool_directory__}' && + + Rscript '${__tool_directory__}/rmarkdown_report_render.R' + + -o $report + -d $report.files_path + + ]]></command> + <inputs> + <repeat name="data_repeat" title="data" min="1" default="1"> + <param type="data" name="data" label="Data from history" optional="False"/> + <param type="text" name="data_name" label="data name" optional="False" help="data name has to be unique."/> + </repeat> + </inputs> + <outputs> + <data name="report" format="html" label="${tool.name} on ${on_string}" hidden="false"/> + </outputs> + <citations> + <citation type="bibtex"><![CDATA[ + @article{allaire2016rmarkdown, + title={rmarkdown: Dynamic Documents for R, 2016}, + author={Allaire, J and Cheng, Joe and Xie, Yihui and McPherson, Jonathan and Chang, Winston and Allen, Jeff + and Wickham, Hadley and Atkins, Aron and Hyndman, Rob}, + journal={R package version 0.9}, + volume={6}, + year={2016} + } + ]]></citation> + <citation type="bibtex"><![CDATA[ + @book{xie2015dynamic, + title={Dynamic Documents with R and knitr}, + author={Xie, Yihui}, + volume={29}, + year={2015}, + publisher={CRC Press} + } + ]]></citation> + </citations> +</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/aurora_data_render.R Tue Apr 17 10:58:55 2018 -0400 @@ -0,0 +1,51 @@ +##============ Sink warnings and errors to a file ============== +## use the sink() function to wrap all code within it. +##============================================================== +zz = file('warnings_and_errors.txt') +sink(zz) +sink(zz, type = 'message') + +#------------import libraries-------------------- +options(stringsAsFactors = FALSE) + +library(getopt) +library(rmarkdown) +#------------------------------------------------ + + +#------------get arguments into R-------------------- +# load helper function +source(paste0(Sys.getenv('TOOL_DIR'), '/helper.R')) +# import getopt specification matrix from a csv file +spec_csv = paste0(Sys.getenv('TOOL_DIR'), '/getopt_specification.csv') +opt = getopt(getopt_specification_matrix(spec_csv)) +opt$X_t = Sys.getenv('TOOL_DIR') +#---------------------------------------------------- + + +#-----------using passed arguments in R +# to define system environment variables--- +do.call(Sys.setenv, opt[-1]) +#---------------------------------------------------- + +#---------- often used variables ---------------- +# OUTPUT_DIR: path to the output associated directory, which stores all outputs +# TOOL_DIR: path to the tool installation directory +OUTPUT_DIR = opt$X_d +TOOL_DIR = opt$X_t +OUTPUT_REPORT = opt$X_o +RMD_NAME = '' + +# create the output associated directory to store all outputs +dir.create(OUTPUT_DIR, recursive = TRUE) + +#-----------------render Rmd-------------- +render(paste0(TOOL_DIR, '/', RMD_NAME), output_file = OUTPUT_REPORT) +#------------------------------------------ + +#==============the end============== + + +##--------end of code rendering .Rmd templates---------------- +sink() +##=========== End of sinking output============================= \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/helper.R Tue Apr 17 10:58:55 2018 -0400 @@ -0,0 +1,55 @@ +#' \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. +file_tree = function(dir = '.'){ + 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, tags$li) + } + }, + { + if (length(dirs) > 0) { + lapply(dirs, function(x){ + tags$li(x, file_tree(x)) + + }) + } + } + ) +} \ No newline at end of file
