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