Mercurial > repos > mingchen0919 > rmarkdown_bdss_client_main
comparison bdss_client_sra_render.R @ 0:1cc0ed4567e1 draft default tip
planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_bdss_client_main commit d9ab791a7ce12362dc6e28c0a518a3f23dd581fe-dirty
author | mingchen0919 |
---|---|
date | Tue, 17 Oct 2017 14:07:18 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1cc0ed4567e1 |
---|---|
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', 'p', '1', 'character') | |
38 args_list$FORMAT = c('format', 'f', '1', 'character') | |
39 args_list$ECHO = c('echo', 'e', '1', 'character') | |
40 ##--------2. output report and outputs -------------- | |
41 args_list$REPORT_HTML = c('report_html', 'r', '1', 'character') | |
42 args_list$REPORT_DIR = c('report_dir', 'd', '1', 'character') | |
43 args_list$SINK_OUTPUT = c('sink_message', 's', '1', 'character') | |
44 ##--------3. Rmd templates in the tool directory ---------- | |
45 args_list$BDSS_CLIENT_RMD = c('bdss_client_rmd', 't', '1', 'character') | |
46 | |
47 opt = getopt(t(as.data.frame(args_list))) | |
48 | |
49 | |
50 ##=======STEP 2: create report directory (optional)========== | |
51 ## | |
52 ##=========================================================== | |
53 dir.create(opt$report_dir) | |
54 | |
55 ##=STEP 3: replace placeholders in .Rmd with argument values= | |
56 ## | |
57 ##=========================================================== | |
58 #++ need to replace placeholders with args values one by one+ | |
59 #----- 01 bdss_client.Rmd ----------------------- | |
60 readLines(opt$bdss_client_rmd) %>% | |
61 (function(x) { | |
62 gsub('SRA_IDS_SE', opt$sra_ids_se, x) | |
63 }) %>% | |
64 (function(x) { | |
65 gsub('SRA_IDS_PE', opt$sra_ids_pe, x) | |
66 }) %>% | |
67 (function(x) { | |
68 gsub('FORMAT', opt$format, x) | |
69 }) %>% | |
70 (function(x) { | |
71 gsub('ECHO', opt$echo, x) | |
72 }) %>% | |
73 (function(x) { | |
74 gsub('REPORT_DIR', opt$report_dir, x) | |
75 }) %>% | |
76 (function(x) { | |
77 fileConn = file('bdss_client.Rmd') | |
78 writeLines(x, con=fileConn) | |
79 close(fileConn) | |
80 }) | |
81 | |
82 ##=============STEP 4: render .Rmd templates================= | |
83 ## | |
84 ##=========================================================== | |
85 render('bdss_client.Rmd', output_file = opt$report_html) | |
86 | |
87 | |
88 ##--------end of code rendering .Rmd templates---------------- | |
89 sink() | |
90 ##=========== End of sinking output============================= |