comparison DESeq_results_render.R @ 0:6f94b4b9de44 draft

planemo upload
author mingchen0919
date Tue, 27 Feb 2018 23:57:53 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:6f94b4b9de44
1 ##============ Sink warnings and errors to a file ==============
2 ## use the sink() function to wrap all code within it.
3 ##==============================================================
4 zz = file('warnings_and_errors.txt')
5 sink(zz)
6 sink(zz, type = 'message')
7
8 #------------import libraries--------------------
9 options(stringsAsFactors = FALSE)
10
11 library(getopt)
12 library(rmarkdown)
13 library(DESeq2)
14 library(pheatmap)
15 library(DT)
16 library(ggplot2)
17 library(genefilter)
18 library(RColorBrewer)
19 #------------------------------------------------
20
21
22 #------------get arguments into R--------------------
23 # getopt_specification_matrix(extract_short_flags('fastqc_report.xml')) %>%
24 # write.table(file = 'spec.txt', sep = ',', row.names = FALSE, col.names = TRUE, quote = FALSE)
25
26
27 spec_matrix = as.matrix(
28 data.frame(stringsAsFactors=FALSE,
29 long_flags = c("X_e", "X_W", "X_C", "X_T", "X_K", "X_M", "X_o",
30 "X_d", "X_s", "X_R", "X_t"),
31 short_flags = c("e", "W", "C", "T", "K", "M", "o", "d", "s", "R",
32 "t"),
33 argument_mask_flags = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
34 data_type_flags = c("character", "character", "character", "character",
35 "character", "character", "character",
36 "character", "character", "character", "character")
37 )
38 )
39 opt = getopt(spec_matrix)
40 opt
41 #----------------------------------------------------
42
43
44 #-----------using passed arguments in R
45 # to define system environment variables---
46 do.call(Sys.setenv, opt[-1])
47 #----------------------------------------------------
48
49 #---------- often used variables ----------------
50 # OUTPUT_REPORT: path to galaxy output report
51 # OUTPUT_DIR: path to the output associated directory, which stores all outputs
52 # TOOL_DIR: path to the tool installation directory
53 OUTPUT_DIR = opt$X_d
54 TOOL_DIR = opt$X_t
55 OUTPUT_REPORT = opt$X_o
56
57
58 # create the output associated directory to store all outputs
59 dir.create(OUTPUT_DIR, recursive = TRUE)
60
61 #-----------------render site--------------
62 # copy site generating materials into OUTPUT_DIR
63 dir.create(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE)
64 command_cp = paste0('cp -r ', TOOL_DIR, '/DESeq_results_*.Rmd ', OUTPUT_DIR, '/site_generator')
65 system(command_cp)
66 system(paste0('cp -r ', TOOL_DIR, '/DESeq_results_site.yml ', OUTPUT_DIR, '/site_generator/_site.yml'))
67 system(paste0('cp -r ', TOOL_DIR, '/DESeq_results_index.Rmd ', OUTPUT_DIR, '/site_generator/index.Rmd'))
68 # render site to OUTPUT_DIR/_site, this is configured in the "_site.yml" file
69 dir.create(paste0(OUTPUT_DIR, '/_site'))
70 render_site(input = paste0(OUTPUT_DIR, '/site_generator'))
71 # remove site generating materials from output associated directory
72 print(unlink(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE))
73 # move _site/* into output associated directory
74 move_cmd = paste0('mv ', OUTPUT_DIR, '/_site/* ', OUTPUT_DIR)
75 system(move_cmd)
76 #------------------------------------------
77
78 #-----link index.html to output-----
79 cp_index = paste0('cp ', OUTPUT_DIR, '/index.html ', OUTPUT_REPORT)
80 system(cp_index)
81 #-----------------------------------
82
83 #==============the end==============
84
85
86 ##--------end of code rendering .Rmd templates----------------
87 sink()
88 ##=========== End of sinking output=============================