comparison DESeq_visualization_render.R @ 4:665daa8b8bdb draft

Uploaded
author mingchen0919
date Mon, 07 Aug 2017 18:11:15 -0400
parents
children
comparison
equal deleted inserted replaced
3:ab57855151b1 4:665daa8b8bdb
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$INTGROUPS_PCA = c('intgroups_pca', 'p', '1', 'character')
38 spec_list$INTGROUPS_MDS = c('intgroups_mds', 'm', '1', 'character')
39
40 ##--------2. output report and report site directory --------------
41 spec_list$OUTPUT_HTML = c('deseq_visualization_html', 'o', '1', 'character')
42 spec_list$OUTPUT_DIR = c('deseq_visualization_dir', 'd', '1', 'character')
43
44 ##--------3. Rmd templates sitting in the tool directory ----------
45
46 spec_list$DESEQ_VISUALIZATION_RMD = c('deseq_visualization_rmd', 'D', '1', 'character')
47
48
49
50 ##------------------------------------------------------------------
51
52 spec = t(as.data.frame(spec_list))
53 opt = getopt(spec)
54 # arguments are accessed by long flag name (the first column in the spec matrix)
55 # NOT by element name in the spec_list
56 # example: opt$help, opt$expression_file
57 ##====== End of arguments handling ==========
58
59 #------ Load libraries ---------
60 library(rmarkdown)
61 library(plyr)
62 library(stringr)
63 library(dplyr)
64 library(highcharter)
65 library(DT)
66 library(reshape2)
67 # library(Kmisc)
68 library(plotly)
69 library(formattable)
70 library(htmltools)
71
72
73 #----- 1. create the report directory ------------------------
74 system(paste0('mkdir -p ', opt$deseq_visualization_dir))
75
76
77 #----- 2. generate Rmd files with Rmd templates --------------
78 # a. templates without placeholder variables:
79 # copy templates from tool directory to the working directory.
80 # b. templates with placeholder variables:
81 # substitute variables with user input values and place them in the working directory.
82
83
84 #----- 01 DESeq_visualization.Rmd -----------------------
85 readLines(opt$deseq_visualization_rmd) %>%
86 (function(x) {
87 gsub('ECHO', opt$echo, x)
88 }) %>%
89 (function(x) {
90 gsub('DESEQ_WORKSPACE', opt$deseq_workspace, x)
91 }) %>%
92 (function(x) {
93 gsub('INTGROUPS_PCA', opt$intgroups_pca, x)
94 }) %>%
95 (function(x) {
96 gsub('INTGROUPS_MDS', opt$intgroups_mds, x)
97 }) %>%
98 (function(x) {
99 gsub('OUTPUT_DIR', opt$deseq_visualization_dir, x)
100 }) %>%
101 (function(x) {
102 fileConn = file('DESeq_visualization.Rmd')
103 writeLines(x, con=fileConn)
104 close(fileConn)
105 })
106
107
108 #------ 3. render all Rmd files --------
109 render('DESeq_visualization.Rmd', output_file = opt$deseq_visualization_html)
110
111
112 #-------4. manipulate outputs -----------------------------