comparison bdss_client_sra_render.R @ 21:a709a705ce09 draft

planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_bdss_client commit 813dcaa22f297814dd6d6a8c4c5ff01664942aa6-dirty
author mingchen0919
date Sat, 14 Oct 2017 19:54:57 -0400
parents
children 89cc5b026494
comparison
equal deleted inserted replaced
20:531c00a2acbf 21:a709a705ce09
1 library(getopt)
2 library(rmarkdown)
3 library(htmltools)
4 library(dplyr)
5 library(RCurl)
6
7
8 ##============ Sink warnings and errors to a file ==============
9 ## use the sink() function to wrap all code within it.
10 ##==============================================================
11 zz = file('warnings_and_errors.txt')
12 sink(zz)
13 sink(zz, type = 'message')
14 ##---------below is the code for rendering .Rmd templates-----
15
16 ##=============STEP 1: handle command line arguments==========
17 ##
18 ##============================================================
19 # column 1: the long flag name
20 # column 2: the short flag alias. A SINGLE character string
21 # column 3: argument mask
22 # 0: no argument
23 # 1: argument required
24 # 2: argument is optional
25 # column 4: date type to which the flag's argument shall be cast.
26 # possible values: logical, integer, double, complex, character.
27 #-------------------------------------------------------------
28 #++++++++++++++++++++ Best practice ++++++++++++++++++++++++++
29 # 1. short flag alias should match the flag in the command section in the XML file.
30 # 2. long flag name can be any legal R variable names
31 # 3. two names in args_list can have common string but one name should not be a part of another name.
32 # for example, one name is "ECHO", if another name is "ECHO_XXX", it will cause problems.
33 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34 ##------- 1. input data ---------------------
35 args_list=list()
36 args_list$SRA_IDS_SE = c('sra_ids_se', 'i', '1', 'character')
37 args_list$SRA_IDS_PE = c('sra_ids_pe', 'i', '1', 'character')
38 args_list$ECHO = c('echo', 'e', '1', 'character')
39 ##--------2. output report and outputs --------------
40 args_list$REPORT_HTML = c('report_html', 'r', '1', 'character')
41 args_list$REPORT_DIR = c('report_dir', 'd', '1', 'character')
42 args_list$SINK_OUTPUT = c('sink_message', 's', '1', 'character')
43 ##--------3. Rmd templates in the tool directory ----------
44 args_list$BDSS_CLIENT_RMD = c('bdss_client_rmd', 't', '1', 'character')
45
46 opt = getopt(t(as.data.frame(args_list)))
47
48
49 ##=======STEP 2: create report directory (optional)==========
50 ##
51 ##===========================================================
52 dir.create(opt$report_dir)
53
54 ##=STEP 3: replace placeholders in .Rmd with argument values=
55 ##
56 ##===========================================================
57 #++ need to replace placeholders with args values one by one+
58 #----- 01 bdss_client.Rmd -----------------------
59 readLines(opt$bdss_client_rmd) %>%
60 (function(x) {
61 gsub('SRA_IDS_SE', opt$sra_ids_se, x)
62 }) %>%
63 (function(x) {
64 gsub('SRA_IDS_PE', opt$sra_ids_pe, x)
65 }) %>%
66 (function(x) {
67 gsub('FORMAT', opt$format, x)
68 }) %>%
69 (function(x) {
70 gsub('ECHO', opt$echo, x)
71 }) %>%
72 (function(x) {
73 gsub('REPORT_DIR', opt$report_dir, x)
74 }) %>%
75 (function(x) {
76 fileConn = file('bdss_client.Rmd')
77 writeLines(x, con=fileConn)
78 close(fileConn)
79 })
80
81 ##=============STEP 4: render .Rmd templates=================
82 ##
83 ##===========================================================
84 render('bdss_client.Rmd', output_file = opt$report_html)
85
86
87 ##--------end of code rendering .Rmd templates----------------
88 sink()
89 ##=========== End of sinking output=============================