annotate DESeq_results_render.R @ 0:6f94b4b9de44 draft

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