Mercurial > repos > mingchen0919 > rmarkdown_deseq2
comparison DESeq_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$COUNT_FILES = c('count_files', 'c', '1', 'character') | |
35 spec_list$ECHO = c('echo', 'e', '1', 'character') | |
36 spec_list$SAMPLE_TABLE = c('sample_table', 's', '1', 'character') | |
37 spec_list$DESIGN_FORMULA = c('design_formula', 'p', '1', 'character') | |
38 | |
39 ##--------2. output report and report site directory -------------- | |
40 spec_list$OUTPUT_HTML = c('deseq_html', 'o', '1', 'character') | |
41 spec_list$OUTPUT_DIR = c('deseq_dir', 'd', '1', 'character') | |
42 spec_list$WORKSPACE = c('deseq_workspace', 'w', '1', 'character') | |
43 | |
44 ##--------3. Rmd templates sitting in the tool directory ---------- | |
45 | |
46 spec_list$DESEQ_RMD = c('deseq_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_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.Rmd ----------------------- | |
85 readLines(opt$deseq_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('DESIGN_FORMULA', opt$design_formula, x) | |
94 }) %>% | |
95 (function(x) { | |
96 gsub('OUTPUT_DIR', opt$deseq_dir, x) | |
97 }) %>% | |
98 (function(x) { | |
99 fileConn = file('DESeq.Rmd') | |
100 writeLines(x, con=fileConn) | |
101 close(fileConn) | |
102 }) | |
103 | |
104 | |
105 #------ 3. render all Rmd files -------- | |
106 render('DESeq.Rmd', output_file = opt$deseq_html) | |
107 | |
108 | |
109 #-------4. manipulate outputs ----------------------------- | |
110 # document file | |
111 # file.copy('DESeq.html', opt$deseq_html, recursive = TRUE) | |
112 | |
113 |