comparison collection_paired_render.R @ 6:a0c8b2b25774 draft

planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_collection_builder commit 88ca36a41aa577ba888cee39cf81b176bf7e68db
author mingchen0919
date Tue, 26 Sep 2017 13:33:22 -0400
parents
children
comparison
equal deleted inserted replaced
5:66022ba24ac7 6:a0c8b2b25774
1 ##======= Handle arguments from command line ========
2 # setup R error handline to go to stderr
3 options(show.error.messages=FALSE,
4 error=function(){
5 cat(geterrmessage(), file=stderr())
6 quit("no", 1, F)
7 })
8
9 # we need that to not crash galaxy with an UTF8 error on German LC settings.
10 loc = Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
11
12 # suppress warning
13 options(warn = -1)
14
15 options(stringsAsFactors=FALSE, useFancyQuotes=FALSE)
16 args = commandArgs(trailingOnly=TRUE)
17
18 suppressPackageStartupMessages({
19 library(getopt)
20 library(tools)
21 })
22
23 # column 1: the long flag name
24 # column 2: the short flag alias. A SINGLE character string
25 # column 3: argument mask
26 # 0: no argument
27 # 1: argument required
28 # 2: argument is optional
29 # column 4: date type to which the flag's argument shall be cast.
30 # possible values: logical, integer, double, complex, character.
31 ##------- 1. input data ---------------------
32 spec_list=list()
33 spec_list$FORWARD_INPUT = c('forward_input', 'L', '1', 'character')
34 spec_list$REVERSE_INPUT = c('reverse_input', 'R', '1', 'character')
35 spec_list$ECHO = c('echo', 'e', '1', 'character')
36 spec_list$FORMAT = c('format', 'f', '1', 'character')
37 ##--------2. output report and outputs --------------
38 spec_list$OUTPUT_HTML = c('paired_collection_html', 'r', '1', 'character')
39 spec_list$OUTPUT_DIR = c('paired_collection_dir', 'd', '1', 'character')
40 ##--------3. Rmd templates in the tool directory ----------
41 spec_list$PAIRED_COLLECTION_RMD = c('paired_collection_rmd', 't', '1', 'character')
42
43 spec = t(as.data.frame(spec_list))
44 opt = getopt(spec)
45 ##====== End of arguments handling ==========
46
47 #------ Load libraries ---------
48 library(rmarkdown)
49 library(htmltools)
50 library(dplyr)
51
52 #----- 1. create the report directory ------------------------
53 system(paste0('mkdir -p ', opt$paired_collection_dir))
54
55 #----- 2. generate Rmd files with Rmd templates --------------
56 # a. templates without placeholder variables:
57 # copy templates from tool directory to the working directory.
58 # b. templates with placeholder variables:
59 # substitute variables with user input values and place them in the working directory.
60
61 #----- 01 paired_collection.Rmd -----------------------
62 readLines(opt$paired_collection_rmd) %>%
63 (function(x) {
64 gsub('ECHO', opt$echo, x)
65 }) %>%
66 (function(x) {
67 gsub('FORMAT', opt$format, x)
68 }) %>%
69 (function(x) {
70 gsub('FORWARD_INPUT', opt$forward_input, x)
71 }) %>%
72 (function(x) {
73 gsub('REVERSE_INPUT', opt$reverse_input, x)
74 }) %>%
75 (function(x) {
76 gsub('OUTPUT_DIR', opt$paired_collection_dir, x)
77 }) %>%
78 (function(x) {
79 fileConn = file('paired_collection.Rmd')
80 writeLines(x, con=fileConn)
81 close(fileConn)
82 })
83
84 #------ 3. render all Rmd files --------
85 render('paired_collection.Rmd', output_file = opt$paired_collection_html)
86
87
88 #-------4. manipulate outputs -----------------------------