# HG changeset patch
# User mingchen0919
# Date 1523977135 14400
# Node ID ebb7afcb2b75357dcbde1bb920c27a9056fa980f
planemo upload
diff -r 000000000000 -r ebb7afcb2b75 aurora_data.Rmd
--- /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, 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
+```
+
+
+```{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)
+)
+```
+
diff -r 000000000000 -r ebb7afcb2b75 aurora_data.xml
--- /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 @@
+
+ Collect data for other aurora galaxy tools.
+
+ pandoc
+ r-getopt
+ r-rmarkdown
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 000000000000 -r ebb7afcb2b75 aurora_data_render.R
--- /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
diff -r 000000000000 -r ebb7afcb2b75 helper.R
--- /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