comparison DESeq_results_render.R @ 0:7231d7e8d3ed draft

planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_deseq2 commit 9285c2b8ad41a486dde2a87600a6b8267841c8b5-dirty
author mingchen0919
date Tue, 08 Aug 2017 10:43:18 -0400
parents
children 2f8ddef8d545
comparison
equal deleted inserted replaced
-1:000000000000 0:7231d7e8d3ed
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$DESEQ_WORKSPACE = c('deseq_workspace', 'w', '1', 'character')
36 spec_list$SAMPLE_TABLE = c('sample_table', 's', '1', 'character')
37 spec_list$CONTRAST_GROUP = c('contrast_group', 'c', '1', 'character')
38 spec_list$TREATMENT_LEVEL = c('treatment_level', 't', '1', 'character')
39 spec_list$CONDITION_LEVEL = c('condition_level', 'k', '1', 'character')
40 spec_list$CLUSTERING_GROUPS = c('clustering_groups', 'm', '1', 'character')
41
42 ##--------2. output report and report site directory --------------
43 spec_list$OUTPUT_HTML = c('deseq_results_html', 'o', '1', 'character')
44 spec_list$OUTPUT_DIR = c('deseq_results_dir', 'd', '1', 'character')
45
46 ##--------3. Rmd templates sitting in the tool directory ----------
47
48 spec_list$DESEQ_VISUALIZATION_RMD = c('deseq_results_rmd', 'D', '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(plyr)
64 library(stringr)
65 library(dplyr)
66 library(highcharter)
67 library(DT)
68 library(reshape2)
69 # library(Kmisc)
70 library(plotly)
71 library(formattable)
72 library(htmltools)
73
74
75 #----- 1. create the report directory ------------------------
76 system(paste0('mkdir -p ', opt$deseq_results_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 DESeq_results.Rmd -----------------------
87 readLines(opt$deseq_results_rmd) %>%
88 (function(x) {
89 gsub('ECHO', opt$echo, x)
90 }) %>%
91 (function(x) {
92 gsub('DESEQ_WORKSPACE', opt$deseq_workspace, x)
93 }) %>%
94 (function(x) {
95 gsub('CONTRAST_GROUP', opt$contrast_group, x)
96 }) %>%
97 (function(x) {
98 gsub('TREATMENT_LEVEL', opt$treatment_level, x)
99 }) %>%
100 (function(x) {
101 gsub('CONDITION_LEVEL', opt$condition_level, x)
102 }) %>%
103 (function(x) {
104 gsub('CLUSTERING_GROUPS', opt$clustering_groups, x)
105 }) %>%
106 (function(x) {
107 gsub('OUTPUT_DIR', opt$deseq_results_dir, x)
108 }) %>%
109 (function(x) {
110 fileConn = file('DESeq_results.Rmd')
111 writeLines(x, con=fileConn)
112 close(fileConn)
113 })
114
115
116 #------ 3. render all Rmd files --------
117 render('DESeq_results.Rmd', output_file = opt$deseq_results_html)
118
119
120 #-------4. manipulate outputs -----------------------------