comparison w4mclstrpeakpics_wrapper.R @ 0:caf0ce49b638 draft

planemo upload for repository https://github.com/HegemanLab/w4mclstrpeakpics_galaxy_wrapper/tree/master commit 7ff527179eab946dd860be6b6a3e2c01b77d7dee
author eschen42
date Sun, 18 Jun 2017 23:25:58 -0400
parents
children 17356c5fe43e
comparison
equal deleted inserted replaced
-1:000000000000 0:caf0ce49b638
1 #!/usr/bin/env Rscript
2
3 library(batch) ## parseCommandArgs
4
5 ########
6 # MAIN #
7 ########
8
9 argVc <- unlist(parseCommandArgs(evaluate=FALSE))
10
11 ##------------------------------
12 ## Initializing
13 ##------------------------------
14
15 ## options
16 ##--------
17
18 strAsFacL <- options()$stringsAsFactors
19 options(stringsAsFactors = FALSE)
20
21 ## libraries
22 ##----------
23
24 # begin HACK - suppress " Can't find a usable init.tcl ... probably means that Tcl wasn't installed properly" issue
25 library("gsubfn")
26 options(gsubfn.engine = "R")
27 # end HACK
28
29 r_package_archive <- as.character(argVc["r_package_archive"])
30 install.packages(r_package_archive, repos = NULL, type = "source")
31 suppressMessages( library("w4mclstrpeakpics") )
32
33 ## constants
34 ##----------
35
36 modNamC <- "w4mclsltrpeakpics" ## module name
37
38 topEnvC <- environment()
39 flgC <- "\n"
40
41 ## functions
42 ##----------
43
44
45 ## log file
46 ##---------
47
48 my_print <- function(x, ...) { cat(c(x, ...))}
49
50 my_print("\nStart of the '", modNamC, "' Galaxy module call: ",
51 format(Sys.time(), "%a %d %b %Y %X"), "\n", sep="")
52
53 ## arguments
54 ##----------
55
56 # files
57
58 output_pdf <- as.character(argVc["output_pdf"])
59 output_tsv <- as.character(argVc["output_tsv"])
60 output_rdata <- as.character(argVc["output_rdata"])
61 data_matrix_path <- as.character(argVc["data_matrix_path"])
62 variable_metadata_path <- as.character(argVc["variable_metadata_path"])
63 sample_metadata_path <- as.character(argVc["sample_metadata_path"])
64
65 # other parameters
66
67 sample_selector_column_name <- as.character(argVc["sample_selector_column_name"])
68 sample_selector_value <- as.character(argVc["sample_selector_value"])
69
70 ##------------------------------
71 ## Computation
72 ##------------------------------
73
74 # from 'demo(error.catching)'
75 tryCatch.W.E <- function(expr) {
76 W <- NULL
77 w.handler <- function(w){
78 # warning handler
79 W <<- w
80 invokeRestart("muffleWarning")
81 }
82 list(
83 value = withCallingHandlers(
84 tryCatch(expr, error = function(e) e)
85 , warning = w.handler
86 )
87 , warning = W
88 )
89 }
90
91 result <- cluster_peak_assessment(
92 sample_selector_column_name = sample_selector_column_name
93 , sample_selector_value = sample_selector_value
94 , sample_metadata_path = sample_metadata_path
95 , variable_metadata_path = variable_metadata_path
96 , data_matrix_path = data_matrix_path
97 , output_pdf = output_pdf
98 , output_tsv = output_tsv
99 , output_rdata = output_rdata
100 , failure_action = my_print
101 )
102
103
104 my_print("\nResult of '", modNamC, "' Galaxy module call to 'w4mclassfilter::w4m_filter_by_sample_class' R function: ",
105 as.character(result), "\n", sep = "")
106
107 ##--------
108 ## Closing
109 ##--------
110
111 my_print("\nEnd of '", modNamC, "' Galaxy module call: ",
112 as.character(Sys.time()), "\n", sep = "")
113
114 #sink()
115
116 if (!file.exists(output_pdf)) {
117 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, output_pdf))
118 }
119
120 if (!file.exists(output_tsv)) {
121 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, output_tsv))
122 }
123
124 if (!file.exists(output_rdata)) {
125 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, output_rdata))
126 }
127
128 # 'stop' causes Rscript to return a non-zero exit code
129 if( !result ) {
130 stop(sprintf("ERROR %s::w4m_filter_by_sample_class - method failed", modNamC))
131 }
132
133 # exit with status code zero
134 q(save = "no", status = 0, runLast = FALSE)