annotate aurora_wgcna_render.R @ 7:120af5453b14 draft

Uploaded
author spficklin
date Fri, 06 Dec 2019 10:54:58 -0500
parents 9e8788803adc
children 66fe92fa79f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
9e8788803adc Uploaded
spficklin
parents:
diff changeset
1 # ------------------------------------------------------------------
9e8788803adc Uploaded
spficklin
parents:
diff changeset
2 # Set options and load libraries.
9e8788803adc Uploaded
spficklin
parents:
diff changeset
3 # ------------------------------------------------------------------
9e8788803adc Uploaded
spficklin
parents:
diff changeset
4
9e8788803adc Uploaded
spficklin
parents:
diff changeset
5 # setup R error handline to go to stderr
9e8788803adc Uploaded
spficklin
parents:
diff changeset
6 options(show.error.messages=FALSE, error=function() {
9e8788803adc Uploaded
spficklin
parents:
diff changeset
7 cat(geterrmessage(), file=stderr())
9e8788803adc Uploaded
spficklin
parents:
diff changeset
8 quit("no", 1, F)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
9 })
9e8788803adc Uploaded
spficklin
parents:
diff changeset
10
9e8788803adc Uploaded
spficklin
parents:
diff changeset
11 # We need to not crash galaxy with an UTF8 error on German LC settings.
9e8788803adc Uploaded
spficklin
parents:
diff changeset
12 loc = Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
9e8788803adc Uploaded
spficklin
parents:
diff changeset
13
9e8788803adc Uploaded
spficklin
parents:
diff changeset
14 options(warn = -1)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
15 args = commandArgs(trailingOnly=TRUE)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
16
9e8788803adc Uploaded
spficklin
parents:
diff changeset
17 suppressPackageStartupMessages({
9e8788803adc Uploaded
spficklin
parents:
diff changeset
18 library(rmarkdown)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
19 library(getopt)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
20 library(WGCNA)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
21 library(caret)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
22 library(ggplot2)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
23 library(reshape2)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
24 # Uncomment for HTML-based reports.
9e8788803adc Uploaded
spficklin
parents:
diff changeset
25 #library(DT)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
26 #library(htmltools)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
27 })
9e8788803adc Uploaded
spficklin
parents:
diff changeset
28
9e8788803adc Uploaded
spficklin
parents:
diff changeset
29
9e8788803adc Uploaded
spficklin
parents:
diff changeset
30 # ------------------------------------------------------------------
9e8788803adc Uploaded
spficklin
parents:
diff changeset
31 # Handle arguments from command line
9e8788803adc Uploaded
spficklin
parents:
diff changeset
32 # ------------------------------------------------------------------
9e8788803adc Uploaded
spficklin
parents:
diff changeset
33
9e8788803adc Uploaded
spficklin
parents:
diff changeset
34 # Get the tool arguments.
9e8788803adc Uploaded
spficklin
parents:
diff changeset
35 spec = matrix(c(
9e8788803adc Uploaded
spficklin
parents:
diff changeset
36 # Input Files
9e8788803adc Uploaded
spficklin
parents:
diff changeset
37 'trait_data', 't', 2, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
38 'expression_data', 'e', 1, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
39
9e8788803adc Uploaded
spficklin
parents:
diff changeset
40 # Input Arguments
9e8788803adc Uploaded
spficklin
parents:
diff changeset
41 'missing_value1', 'i', 1, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
42 'missing_value2', 'o', 2, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
43 'sname_col', 'c', 2, 'integer',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
44 'min_cluster_size', 's', 1, 'integer',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
45 'height_cut', 'h', 2, 'double',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
46 'power', 'p', 2, 'double',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
47 'block_size', 'b', 1, 'integer',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
48 'hard_threshold', 'j', 1, 'double',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
49 'one_hot_cols', 'y', 2, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
50 'ignore_cols', 'x', 2, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
51
9e8788803adc Uploaded
spficklin
parents:
diff changeset
52 # Output Files
9e8788803adc Uploaded
spficklin
parents:
diff changeset
53 'gene_module_file', 'k', 1, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
54 'network_edges_file', 'w', 1, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
55 'gene_association_file', 'g', 2, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
56 'module_association_file', 'm', 2, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
57 'module_association_report', 'q', 2, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
58 'network_construction_report', 'r', 1, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
59 'updated_trait_matrix', 'z', 2, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
60 'r_data', 'a', 1, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
61 'render_log_file', 'l', 1, 'character',
9e8788803adc Uploaded
spficklin
parents:
diff changeset
62 'filtered_GEM', 'd', 1, 'character'
9e8788803adc Uploaded
spficklin
parents:
diff changeset
63 ),
9e8788803adc Uploaded
spficklin
parents:
diff changeset
64 byrow=TRUE, ncol=4)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
65
9e8788803adc Uploaded
spficklin
parents:
diff changeset
66 opt = getopt(spec)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
67
9e8788803adc Uploaded
spficklin
parents:
diff changeset
68 # We have to have values for the one_hot_cols and ignore_cols but the
9e8788803adc Uploaded
spficklin
parents:
diff changeset
69 # fact these are optional means that we might not get a value for them and the
9e8788803adc Uploaded
spficklin
parents:
diff changeset
70 # getopt function will then leave them out. So, we need to make sure they are
9e8788803adc Uploaded
spficklin
parents:
diff changeset
71 # there.
9e8788803adc Uploaded
spficklin
parents:
diff changeset
72 if (!"one_hot_cols" %in% names(opt)) {
9e8788803adc Uploaded
spficklin
parents:
diff changeset
73 opt[["one_hot_cols"]] <- ''
9e8788803adc Uploaded
spficklin
parents:
diff changeset
74 }
9e8788803adc Uploaded
spficklin
parents:
diff changeset
75 if (!"ignore_cols" %in% names(opt)) {
9e8788803adc Uploaded
spficklin
parents:
diff changeset
76 opt[["ignore_cols"]] <- ''
9e8788803adc Uploaded
spficklin
parents:
diff changeset
77 }
9e8788803adc Uploaded
spficklin
parents:
diff changeset
78
9e8788803adc Uploaded
spficklin
parents:
diff changeset
79 # Define environment variables for all input values. This will allow use
9e8788803adc Uploaded
spficklin
parents:
diff changeset
80 # of the input arguments in the Rmarkdown template file.
9e8788803adc Uploaded
spficklin
parents:
diff changeset
81 do.call(Sys.setenv, opt[-1])
9e8788803adc Uploaded
spficklin
parents:
diff changeset
82
9e8788803adc Uploaded
spficklin
parents:
diff changeset
83 # ------------------------------------------------------------------
9e8788803adc Uploaded
spficklin
parents:
diff changeset
84 # Render Rmd files
9e8788803adc Uploaded
spficklin
parents:
diff changeset
85 # ------------------------------------------------------------------
9e8788803adc Uploaded
spficklin
parents:
diff changeset
86 tool_directory = Sys.getenv('TOOL_INSTALL_DIR')
9e8788803adc Uploaded
spficklin
parents:
diff changeset
87
9e8788803adc Uploaded
spficklin
parents:
diff changeset
88
9e8788803adc Uploaded
spficklin
parents:
diff changeset
89 # We don't want the Rmarkdown STDOUT to show up in Galaxy, so save it to a file.
9e8788803adc Uploaded
spficklin
parents:
diff changeset
90 zz = file(opt$render_log_file)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
91 sink(zz)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
92 sink(zz, type = 'message')
9e8788803adc Uploaded
spficklin
parents:
diff changeset
93
9e8788803adc Uploaded
spficklin
parents:
diff changeset
94 # Print the options
9e8788803adc Uploaded
spficklin
parents:
diff changeset
95 print(opt)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
96
9e8788803adc Uploaded
spficklin
parents:
diff changeset
97 # Next render the R markdown template file.
9e8788803adc Uploaded
spficklin
parents:
diff changeset
98 system(command = paste0('cp ', tool_directory, '/aurora_wgcna.Rmd ./'))
9e8788803adc Uploaded
spficklin
parents:
diff changeset
99 render(input = 'aurora_wgcna.Rmd', output_file = opt$network_construction_report)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
100
9e8788803adc Uploaded
spficklin
parents:
diff changeset
101 # If the trait data was provided then we'll continue the
9e8788803adc Uploaded
spficklin
parents:
diff changeset
102 # analysis.
9e8788803adc Uploaded
spficklin
parents:
diff changeset
103 if (!is.null(opt$trait_data)) {
9e8788803adc Uploaded
spficklin
parents:
diff changeset
104 system(command = paste0('cp ', tool_directory, '/aurora_wgcna_trait.Rmd ./'))
9e8788803adc Uploaded
spficklin
parents:
diff changeset
105 render(input = 'aurora_wgcna_trait.Rmd', output_file = opt$module_association_report)
9e8788803adc Uploaded
spficklin
parents:
diff changeset
106 }
9e8788803adc Uploaded
spficklin
parents:
diff changeset
107
9e8788803adc Uploaded
spficklin
parents:
diff changeset
108 sink()