Mercurial > repos > mingchen0919 > rmarkdown_i_adhore
comparison i_adhore_configure_render.R @ 0:9755ce6ac4d5 draft
planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_i_adhore commit b6ef011f29d6c75775be9cc0e0abe53e19981d1d-dirty
author | mingchen0919 |
---|---|
date | Tue, 08 Aug 2017 12:53:57 -0400 |
parents | |
children | f8bedb407e5c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9755ce6ac4d5 |
---|---|
1 | |
2 ##======= Handle arguments from command line ======== | |
3 # setup R error handline to go to stderr | |
4 options(show.error.messages=FALSE, | |
5 error=function(){ | |
6 cat(geterrmessage(), file=stderr()) | |
7 quit("no", 1, F) | |
8 }) | |
9 | |
10 # we need that to not crash galaxy with an UTF8 error on German LC settings. | |
11 loc = Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") | |
12 | |
13 # suppress warning | |
14 options(warn = -1) | |
15 | |
16 options(stringsAsFactors=FALSE, useFancyQuotes=FALSE) | |
17 args = commandArgs(trailingOnly=TRUE) | |
18 | |
19 suppressPackageStartupMessages({ | |
20 library(getopt) | |
21 library(tools) | |
22 }) | |
23 | |
24 # column 1: the long flag name | |
25 # column 2: the short flag alias. A SINGLE character string | |
26 # column 3: argument mask | |
27 # 0: no argument | |
28 # 1: argument required | |
29 # 2: argument is optional | |
30 # column 4: date type to which the flag's argument shall be cast. | |
31 # possible values: logical, integer, double, complex, character. | |
32 spec_list=list() | |
33 | |
34 | |
35 ##------- 1. input data --------------------- | |
36 spec_list$ECHO = c('echo', 'e', '1', 'character') | |
37 spec_list$G_ANALYSIS_FILES = c('g_analysis_files', 'G', '1', 'character') | |
38 spec_list$BLAST_TABLE = c('blast_table', 'b', '1', 'character') | |
39 spec_list$GAP_SIZE = c('gap_size', 'g', '1', 'character') | |
40 spec_list$CLUSTER_GAP = c('cluster_gap', 'c', '1', 'character') | |
41 spec_list$Q_VALUE = c('q_value', 'q', '1', 'character') | |
42 spec_list$PROB_CUTOFF = c('prob_cutoff', 'p', '1', 'character') | |
43 spec_list$ANCHOR_POINTS = c('anchor_points', 'a', '1', 'character') | |
44 spec_list$ALIGNMENT_METHOD = c('alignment_method', 'm', '1', 'character') | |
45 spec_list$LEVEL2ONLY = c('level2only', 'l', '1', 'character') | |
46 spec_list$TABLE_TYPE = c('table_type', 'T', '1', 'character') | |
47 spec_list$MULTI_HYPOTHESIS_CORRECTION = c('multi_hypothesis_correction', 'h', '1', 'character') | |
48 | |
49 | |
50 ##--------2. output report and report site directory -------------- | |
51 spec_list$I_ADHORE_CONFIGURE_TXT = c('i_adhore_configure_txt', 'x', '1', 'character') | |
52 spec_list$OUTPUT_HTML = c('i_adhore_configure_html', 'o', '1', 'character') | |
53 spec_list$OUTPUT_DIR = c('i_adhore_configure_dir', 'd', '1', 'character') | |
54 | |
55 | |
56 ##--------3. Rmd templates sitting in the tool directory ---------- | |
57 spec_list$I_ADHORE_CONFIGURE_RMD = c('i_adhore_configure_rmd', '-t', '1', 'character') | |
58 | |
59 | |
60 spec = t(as.data.frame(spec_list)) | |
61 opt = getopt(spec) | |
62 # arguments are accessed by long flag name (the first column in the spec matrix) | |
63 # NOT by element name in the spec_list | |
64 # example: opt$help, opt$expression_file | |
65 ##====== End of arguments handling ========== | |
66 | |
67 #------ Load libraries --------- | |
68 library(rmarkdown) | |
69 library(plyr) | |
70 library(dplyr) | |
71 | |
72 | |
73 #----- 1. create the report directory ------------------------ | |
74 system(paste0('mkdir -p ', opt$i_adhore_configure_dir)) | |
75 # set working directory to output files directory | |
76 setwd(opt$i_adhore_configure_dir) | |
77 | |
78 | |
79 #----- 2. generate Rmd files with Rmd templates -------------- | |
80 # a. templates without placeholder variables: | |
81 # copy templates from tool directory to the working directory. | |
82 # b. templates with placeholder variables: | |
83 # substitute variables with user input values and place them in the working directory. | |
84 | |
85 | |
86 #----- 01 i_adhore_configure.Rmd ----------------------- | |
87 readLines(opt$i_adhore_configure_rmd) %>% | |
88 (function(x) { | |
89 gsub('ECHO', opt$echo, x) | |
90 }) %>% | |
91 (function(x) { | |
92 gsub('I_ADHORE_CONFIGURE_TXT', opt$i_adhore_configure_txt, x) | |
93 }) %>% | |
94 (function(x) { | |
95 fileConn = file('i_adhore_configure.Rmd') | |
96 writeLines(x, con=fileConn) | |
97 close(fileConn) | |
98 }) | |
99 | |
100 | |
101 #------ 3. render all Rmd files -------- | |
102 render('i_adhore_configure.Rmd', output_file = opt$i_adhore_configure_html) |