comparison wgcna_preprocessing_render.R @ 0:4275479ada3a draft

planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_wgcna commit d91f269e8bc09a488ed2e005122bbb4a521f44a0-dirty
author mingchen0919
date Tue, 08 Aug 2017 12:35:50 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4275479ada3a
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 spec_list=list()
32
33 ##------- 1. input data ---------------------
34 spec_list$ECHO = c('echo', 'e', '1', 'character')
35 spec_list$EXPRESSION_DATA = c('expression_data', 'E', '1', 'character')
36
37
38 ##--------2. output report and report site directory --------------
39 spec_list$OUTPUT_HTML = c('wgcna_preprocessing_html', 'o', '1', 'character')
40 spec_list$OUTPUT_DIR = c('wgcna_preprocessing_dir', 'd', '1', 'character')
41 spec_list$PREPROCESSING_WORKSPACE = c('preprocessing_workspace', 'w', '1', 'character')
42
43 ##--------3. Rmd templates sitting in the tool directory ----------
44
45 spec_list$WGCNA_PREPROCESSING_RMD = c('wgcna_preprocessing_rmd', 'D', '1', 'character')
46
47
48
49 ##------------------------------------------------------------------
50
51 spec = t(as.data.frame(spec_list))
52 opt = getopt(spec)
53 # arguments are accessed by long flag name (the first column in the spec matrix)
54 # NOT by element name in the spec_list
55 # example: opt$help, opt$expression_file
56 ##====== End of arguments handling ==========
57
58 #------ Load libraries ---------
59 library(rmarkdown)
60 library(WGCNA)
61 library(DT)
62 library(htmltools)
63
64
65 #----- 1. create the report directory ------------------------
66 system(paste0('mkdir -p ', opt$wgcna_preprocessing_dir))
67
68
69 #----- 2. generate Rmd files with Rmd templates --------------
70 # a. templates without placeholder variables:
71 # copy templates from tool directory to the working directory.
72 # b. templates with placeholder variables:
73 # substitute variables with user input values and place them in the working directory.
74
75
76 #----- 01 wgcna_preprocessing.Rmd -----------------------
77 readLines(opt$wgcna_preprocessing_rmd) %>%
78 (function(x) {
79 gsub('ECHO', opt$echo, x)
80 }) %>%
81 (function(x) {
82 gsub('EXPRESSION_DATA', opt$expression_data, x)
83 }) %>%
84 (function(x) {
85 gsub('OUTPUT_DIR', opt$wgcna_preprocessing_dir, x)
86 }) %>%
87 (function(x) {
88 gsub('PREPROCESSING_WORKSPACE', opt$preprocessing_workspace, x)
89 }) %>%
90 (function(x) {
91 fileConn = file('wgcna_preprocessing.Rmd')
92 writeLines(x, con=fileConn)
93 close(fileConn)
94 })
95
96
97 #------ 3. render all Rmd files --------
98 render('wgcna_preprocessing.Rmd', output_file = opt$wgcna_preprocessing_html)
99
100 #-------4. manipulate outputs -----------------------------
101
102