annotate DESeq_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_o", "X_d", "X_s", "X_t", "X_P", "X_N",
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
30 "X_S", "X_p", "X_w"),
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
31 short_flags = c("e", "o", "d", "s", "t", "P", "N", "S", "p", "w"),
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
32 argument_mask_flags = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
33 data_type_flags = c("character", "character", "character", "character",
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
34 "character", "character", "character",
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
35 "character", "character", "character")
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
36 )
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
37 )
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
38 opt = getopt(spec_matrix)
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
39 #----------------------------------------------------
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
40
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
41
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
42 #-----------using passed arguments in R
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
43 # to define system environment variables---
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
44 do.call(Sys.setenv, opt[-1])
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
45 #----------------------------------------------------
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
46
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
47 #---------- often used variables ----------------
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
48 # OUTPUT_REPORT: path to galaxy output report
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
49 # OUTPUT_DIR: path to the output associated directory, which stores all outputs
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
50 # TOOL_DIR: path to the tool installation directory
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
51 OUTPUT_DIR = opt$X_d
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
52 TOOL_DIR = opt$X_t
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
53 OUTPUT_REPORT = opt$X_o
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
54
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
55
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
56 # create the output associated directory to store all outputs
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
57 dir.create(OUTPUT_DIR, recursive = TRUE)
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
58
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
59 #-----------------render site--------------
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
60 # copy site generating materials into OUTPUT_DIR
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
61 dir.create(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE)
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
62 command_cp = paste0('cp -r ', TOOL_DIR, '/DESeq_0*.Rmd ', OUTPUT_DIR, '/site_generator')
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
63 system(command_cp)
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
64 system(paste0('cp -r ', TOOL_DIR, '/DESeq_site.yml ', OUTPUT_DIR, '/site_generator/_site.yml'))
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
65 system(paste0('cp -r ', TOOL_DIR, '/DESeq_index.Rmd ', OUTPUT_DIR, '/site_generator/index.Rmd'))
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
66 # render site to OUTPUT_DIR/_site, this is configured in the "_site.yml" file
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
67 dir.create(paste0(OUTPUT_DIR, '/_site'))
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
68 render_site(input = paste0(OUTPUT_DIR, '/site_generator'))
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
69 # remove site generating materials from output associated directory
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
70 print(unlink(paste0(OUTPUT_DIR, '/site_generator'), recursive = TRUE))
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
71 # move _site/* into output associated directory
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
72 move_cmd = paste0('mv ', OUTPUT_DIR, '/_site/* ', OUTPUT_DIR)
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
73 system(move_cmd)
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
74 #------------------------------------------
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
75
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
76 #-----link index.html to output-----
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
77 cp_index = paste0('cp ', OUTPUT_DIR, '/index.html ', OUTPUT_REPORT)
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
78 system(cp_index)
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
79 #-----------------------------------
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
80
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
81 #==============the end==============
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
82
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
83
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
84 ##--------end of code rendering .Rmd templates----------------
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
85 sink()
6f94b4b9de44 planemo upload
mingchen0919
parents:
diff changeset
86 ##=========== End of sinking output=============================