Mercurial > repos > mingchen0919 > aurora_fastqc_site
diff fastqc_site_render.R @ 7:3f92c10de274 draft
planemo upload
| author | mingchen0919 |
|---|---|
| date | Mon, 30 Apr 2018 10:15:54 -0400 |
| parents | acb9908e68e4 |
| children |
line wrap: on
line diff
--- a/fastqc_site_render.R Tue Mar 13 11:33:13 2018 -0400 +++ b/fastqc_site_render.R Mon Apr 30 10:15:54 2018 -0400 @@ -1,84 +1,54 @@ ##============ Sink warnings and errors to a file ============== ## use the sink() function to wrap all code within it. ##============================================================== -zz = file('warnings_and_errors.txt') +zz = file(paste0(Sys.getenv('REPORT_FILES_PATH'), '/.r_rendering.log.txt')) sink(zz) sink(zz, type = 'message') - -library(getopt) -library(rmarkdown) -library(htmltools) -library(plyr) -library(dplyr) -library(stringr) -library(DT) -library(reshape2) -library(plotly) + +#============== preparation ==================================== options(stringsAsFactors = FALSE) - -# getopt_specification_matrix(extract_short_flags('fastqc_report.xml')) %>% -# write.table(file = 'spec.txt', sep = ',', row.names = FALSE, col.names = TRUE, quote = FALSE) - - -# get arguments into R -spec_matrix = as.matrix( - data.frame(stringsAsFactors=FALSE, - long_flags = c("X_e", "X_r", "X_n", "X_R", "X_N", "X_c", "X_l", - "X_o", "X_d", "X_s", "X_t"), - short_flags = c("e", "r", "n", "R", "N", "c", "l", "o", "d", "s", - "t"), - argument_mask_flags = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), - data_type_flags = c("character", "character", "character", "character", - "character", "character", "character", - "character", "character", "character", "character") - ) -) -opt = getopt(spec_matrix) -#---------------------------------------------------- +# import libraries +#------------------------------------------------------------------ +# ADD MORE LIBRARIES HERE IF YOUR TOOL DEPENDS ON OTHER R LIBRARIES +#------------------------------------------------------------------ +library('getopt') +library('rmarkdown') +library('htmltools') -#-----------using passed arguments in R -# to define system environment variables--- +# 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]) -#---------------------------------------------------- - -#---------- often used variables ---------------- -# OUTPUT_REPORT: path to galaxy output report -# 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 +#=============================================================== -# create the output associated directory to store all outputs -dir.create(OUTPUT_DIR, recursive = TRUE) +#======================== 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}') +# for rendering a site +system(command = 'cp -r ${TOOL_INSTALL_DIR}/_site.yml ${REPORT_FILES_PATH}') -# copy site generating materials into OUTPUT_DIR -dir.create(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE) -system(paste0('cp -r ', TOOL_DIR, '/*.Rmd ', OUTPUT_DIR, '/site_generator/')) -system(paste0('cp -r ', TOOL_DIR, '/_site.yml ', OUTPUT_DIR, '/site_generator/_site.yml')) -system(paste0('cp -r ', TOOL_DIR, '/index.Rmd ', OUTPUT_DIR, '/site_generator/index.Rmd')) -# render site to OUTPUT_DIR/_site, this is configured in the "_site.yml" file -render_site(input = paste0(OUTPUT_DIR, '/site_generator')) -# remove site generating materials from output associated directory -unlink(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE) -# move _site/* into output associated directory -move_cmd = paste0('mv ', OUTPUT_DIR, '/_site/* ', OUTPUT_DIR) -system(move_cmd) -#------------------------------------------ +#----------------BELOW IS WHERE YOU NEED TO CUSTOMIZE --------------------- +render(input = paste0(Sys.getenv('REPORT_FILES_PATH'), '/rmarkdown_report.Rmd')) +# add more lines below if there are more Rmd files to be rendered -#-----link index.html to output----- -cp_index = paste0('cp ', opt$X_d, '/index.html ', opt$X_o) -system(cp_index) -#----------------------------------- - -#==============the end============== +#=============================================================== +#============== expose outputs to galaxy history =============== +system(command = 'sh ${TOOL_INSTALL_DIR}/expose-outputs.sh') +#=============================================================== -# file.copy(paste0(opt$X_d, '/index.html'), opt$X_o, recursive = TRUE) ##--------end of code rendering .Rmd templates---------------- sink() -##=========== End of sinking output============================= \ No newline at end of file +##=========== End of sinking output=============================
