comparison wgcna_eigengene_visualization_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$CONSTRUCT_NETWORK_WORKSPACE = c('construct_network_workspace', 'w', '1', 'character')
36 spec_list$SOFT_THRESHOLD_POWER = c('soft_threshold_power', 'p', '2', 'double')
37 spec_list$PLOT_GENES = c('plot_genes', 'n', '1', 'integer')
38
39
40 ##--------2. output report and report site directory --------------
41 spec_list$OUTPUT_HTML = c('wgcna_eigengene_visualization_html', 'o', '1', 'character')
42 spec_list$OUTPUT_DIR = c('wgcna_eigengene_visualization_dir', 'd', '1', 'character')
43
44
45
46 ##--------3. Rmd templates in the tool directory ----------
47
48 spec_list$WGCNA_EIGENGENE_VISUALIZATION_RMD = c('wgcna_eigengene_visualization_rmd', 'M', '1', 'character')
49
50
51
52 ##------------------------------------------------------------------
53
54 spec = t(as.data.frame(spec_list))
55 opt = getopt(spec)
56 # arguments are accessed by long flag name (the first column in the spec matrix)
57 # NOT by element name in the spec_list
58 # example: opt$help, opt$expression_file
59 ##====== End of arguments handling ==========
60
61 #------ Load libraries ---------
62 library(rmarkdown)
63 library(WGCNA)
64 library(DT)
65 library(htmltools)
66 library(ggplot2)
67
68
69 #----- 1. create the report directory ------------------------
70 system(paste0('mkdir -p ', opt$wgcna_eigengene_visualization_dir))
71
72
73 #----- 2. generate Rmd files with Rmd templates --------------
74 # a. templates without placeholder variables:
75 # copy templates from tool directory to the working directory.
76 # b. templates with placeholder variables:
77 # substitute variables with user input values and place them in the working directory.
78
79
80 #----- 01 wgcna_eigengene_visualization.Rmd -----------------------
81 readLines(opt$wgcna_eigengene_visualization_rmd) %>%
82 (function(x) {
83 gsub('ECHO', opt$echo, x)
84 }) %>%
85 (function(x) {
86 gsub('CONSTRUCT_NETWORK_WORKSPACE', opt$construct_network_workspace, x)
87 }) %>%
88 (function(x) {
89 gsub('SOFT_THRESHOLD_POWER', opt$soft_threshold_power, x)
90 }) %>%
91 (function(x) {
92 gsub('PLOT_GENES', opt$plot_genes, x)
93 }) %>%
94 (function(x) {
95 gsub('OUTPUT_DIR', opt$wgcna_eigengene_visualization_dir, x)
96 }) %>%
97 (function(x) {
98 fileConn = file('wgcna_eigengene_visualization.Rmd')
99 writeLines(x, con=fileConn)
100 close(fileConn)
101 })
102
103
104 #------ 3. render all Rmd files --------
105 render('wgcna_eigengene_visualization.Rmd', output_file = opt$wgcna_eigengene_visualization_html)
106
107 #-------4. manipulate outputs -----------------------------
108
109