comparison w4mkmeans_wrapper.R @ 2:c415b7dc6f37 draft default tip

planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 3e916537da6bb37e6f3927d7a11e98e0ab6ef5ec
author eschen42
date Mon, 05 Mar 2018 12:40:17 -0500
parents 02cafb660b72
children
comparison
equal deleted inserted replaced
1:02cafb660b72 2:c415b7dc6f37
20 # sample_metadata_path "$sampleMetadata_in" \ 20 # sample_metadata_path "$sampleMetadata_in" \
21 # scores_out "$scores_out" \ 21 # scores_out "$scores_out" \
22 # slots "${GALAXY_SLOTS:-1}" \ 22 # slots "${GALAXY_SLOTS:-1}" \
23 # variableMetadata_out "$variableMetadata_out" \ 23 # variableMetadata_out "$variableMetadata_out" \
24 # variable_metadata_path "$variableMetadata_in" 24 # variable_metadata_path "$variableMetadata_in"
25 # 25 #
26 # <inputs> 26 # <inputs>
27 # <param name="dataMatrix_in" label="Data matrix file" type="data" format="tabular" help="variable x sample, decimal: '.', missing: NA, mode: numerical, separator: tab" /> 27 # <param name="dataMatrix_in" label="Data matrix file" type="data" format="tabular" help="variable x sample, decimal: '.', missing: NA, mode: numerical, separator: tab" />
28 # <param name="sampleMetadata_in" label="Sample metadata file" type="data" format="tabular" help="sample x metadata columns, separator: tab" /> 28 # <param name="sampleMetadata_in" label="Sample metadata file" type="data" format="tabular" help="sample x metadata columns, separator: tab" />
29 # <param name="variableMetadata_in" label="Variable metadata file" type="data" format="tabular" help="variable x metadata columns, separator: tab" /> 29 # <param name="variableMetadata_in" label="Variable metadata file" type="data" format="tabular" help="variable x metadata columns, separator: tab" />
30 # <param name="categoricalPrefix" label="prefix for cluster names " type="text" value="k" help="Some tools require non-numeric values to discern categorical; e.g., enter 'k' here to prepend 'k' to cluster numbers in the output; default 'k'." /> 30 # <param name="categoricalPrefix" label="prefix for cluster names " type="text" value="k" help="Some tools require non-numeric values to discern categorical; e.g., enter 'k' here to prepend 'k' to cluster numbers in the output; default 'k'." />
31 # <param name="kfeatures" label="K value(s) for features" type="text" value="0" help="Single or min,max value(s) for K for features (variables), or 0 for none." /> 31 # <param name="kfeatures" label="K value(s) for features" type="text" value="0" help="Single or min,max value(s) for K for features (variables), or 0 for none." />
32 # <param name="ksamples" label="K value(s) for samples" type="text" value="0" help="Single or min,max value(s) for K for samples, or 0 for none." /> 32 # <param name="ksamples" label="K value(s) for samples" type="text" value="0" help="Single or min,max value(s) for K for samples, or 0 for none." />
33 # <param name="iter_max" label="Max number of iterations" type="text" value="10" help="The maximum number of iterations allowed; default 10." /> 33 # <param name="iter_max" label="Max number of iterations" type="text" value="20" help="The maximum number of iterations allowed; default 20." />
34 # <param name="nstart" label="Number of random sets" type="text" value="1" help="How many random sets should be chosen; default 1." /> 34 # <param name="nstart" label="Number of random sets" type="text" value="20" help="How many random sets should be chosen; default 20." />
35 # <param name="algorithm" label="Algorithm for clustering" type="select" value = "Hartigan-Wong" help="K-means clustering algorithm, default 'Hartigan-Wong'; alternatives 'Lloyd', 'MacQueen'; 'Forgy' is a synonym for 'Lloyd', see stats::kmeans reference for further info and references."> 35 # <param name="algorithm" label="Algorithm for clustering" type="select" value = "Hartigan-Wong" help="K-means clustering algorithm, default 'Hartigan-Wong'; alternatives 'Lloyd', 'MacQueen'; 'Forgy' is a synonym for 'Lloyd', see stats::kmeans reference for further info and references.">
36 # <option value="Hartigan-Wong" selected="TRUE">Hartigan-Wong</option> 36 # <option value="Hartigan-Wong" selected="TRUE">Hartigan-Wong</option>
37 # <option value="Lloyd">Lloyd</option> 37 # <option value="Lloyd">Lloyd</option>
38 # <option value="MacQueen">MacQueen</option> 38 # <option value="MacQueen">MacQueen</option>
39 # <option value="Forgy">Forgy</option> 39 # <option value="Forgy">Forgy</option>
64 64
65 ##---------------------------------------------------------- 65 ##----------------------------------------------------------
66 ## Computation - source general and module-specific routines 66 ## Computation - source general and module-specific routines
67 ##---------------------------------------------------------- 67 ##----------------------------------------------------------
68 68
69 log_print <- function(x, ...) { 69 log_print <- function(x, ...) {
70 cat( 70 cat(
71 format(Sys.time(), "%Y-%m-%dT%H:%M:%S%z") 71 format(Sys.time(), "%Y-%m-%dT%H:%M:%S%z")
72 , " " 72 , " "
73 , c(x, ...) 73 , c(x, ...)
74 , "\n" 74 , "\n"
75 , sep="" 75 , sep=""
76 , file=stderr() 76 , file=stderr()
77 ) 77 )
78 } 78 }
79 79
80 log_cat <- function(x, ...) {
81 cat(
82 c(x, ...)
83 , "\n"
84 , sep=""
85 , file=stderr()
86 )
87 }
88
80 # log_print(sprintf("tool_directory is %s", tool_directory)) 89 # log_print(sprintf("tool_directory is %s", tool_directory))
81 90
82 w4m_general_purpose_routines_path <- r_path("w4m_general_purpose_routines.R") 91 w4m_general_purpose_routines_path <- r_path("w4m_general_purpose_routines.R")
83 # log_print(sprintf("w4m_general_purpose_routines_path is %s", w4m_general_purpose_routines_path)) 92 # log_print(sprintf("w4m_general_purpose_routines_path is %s", w4m_general_purpose_routines_path))
84 if ( ! file.exists(w4m_general_purpose_routines_path) ) { 93 if ( ! file.exists(w4m_general_purpose_routines_path) ) {
85 log_print("cannot find file w4m_general_purpose_routines.R") 94 log_print("cannot find file w4m_general_purpose_routines.R")
86 q(save = "no", status = 1, runLast = TRUE) 95 q(save = "no", status = 1, runLast = TRUE)
87 } 96 }
88 # log_print("sourcing ",w4m_general_purpose_routines_path) 97 log_print("sourcing ",w4m_general_purpose_routines_path)
89 source(w4m_general_purpose_routines_path) 98 source(w4m_general_purpose_routines_path)
90 if ( ! exists("prepare.data.matrix") ) { 99 if ( ! exists("prepare.data.matrix") ) {
91 log_print("'prepare.data.matrix' was not read from file w4m_general_purpose_routines.R") 100 log_print("'prepare.data.matrix' was not read from file w4m_general_purpose_routines.R")
92 q(save = "no", status = 1, runLast = TRUE) 101 q(save = "no", status = 1, runLast = TRUE)
93 } 102 }
162 kind_string <- "none" 171 kind_string <- "none"
163 tryCatch( 172 tryCatch(
164 expr = { 173 expr = {
165 # read in the sample metadata 174 # read in the sample metadata
166 kind_string <- "sample metadata input" 175 kind_string <- "sample metadata input"
167 smpl_metadata_input_env <- 176 smpl_metadata_input_env <-
168 read_data_frame( 177 read_data_frame(
169 file_path = env$sample_metadata_path 178 file_path = env$sample_metadata_path
170 , kind_string = kind_string 179 , kind_string = kind_string
171 , failure_action = failure_action 180 , failure_action = failure_action
172 ) 181 )
176 } 185 }
177 env$sampleMetadata <- smpl_metadata_input_env$data 186 env$sampleMetadata <- smpl_metadata_input_env$data
178 187
179 # read in the variable metadata 188 # read in the variable metadata
180 kind_string <- "variable metadata input" 189 kind_string <- "variable metadata input"
181 vrbl_metadata_input_env <- 190 vrbl_metadata_input_env <-
182 read_data_frame( 191 read_data_frame(
183 file_path = env$variable_metadata_path 192 file_path = env$variable_metadata_path
184 , kind_string = kind_string 193 , kind_string = kind_string
185 , failure_action = failure_action 194 , failure_action = failure_action
186 ) 195 )
216 ) 225 )
217 return ( TRUE ) 226 return ( TRUE )
218 } 227 }
219 228
220 229
221 read_input_failure_action <- function(x, ...) { 230 read_input_failure_action <- function(x, ...) {
222 log_print("Failure reading input for '", modNamC, "' Galaxy module call") 231 log_print("Failure reading input for '", modNamC, "' Galaxy module call")
223 log_print(x, ...) 232 log_print(x, ...)
224 } 233 }
225 234
226 ##-------------------------- 235 ##--------------------------
236 ## options 245 ## options
237 ##-------- 246 ##--------
238 247
239 # Set the handler for R error-handling 248 # Set the handler for R error-handling
240 options( show.error.messages = F 249 options( show.error.messages = F
241 , error = function () { 250 , error = function () {
242 log_print( "Fatal error in '", modNamC, "': ", geterrmessage() ) 251 log_print( "Fatal error in '", modNamC, "': ", geterrmessage() )
243 q( "no", 1, F ) 252 q( "no", 1, F )
244 } 253 }
245 , warn = -1 254 , warn = -1
246 ) 255 )
281 scores_out <- as.character(argVc["scores_out"]) 290 scores_out <- as.character(argVc["scores_out"])
282 ## input files 291 ## input files
283 args_env$data_matrix_path <- as.character(argVc["data_matrix_path"]) 292 args_env$data_matrix_path <- as.character(argVc["data_matrix_path"])
284 args_env$variable_metadata_path <- as.character(argVc["variable_metadata_path"]) 293 args_env$variable_metadata_path <- as.character(argVc["variable_metadata_path"])
285 args_env$sample_metadata_path <- as.character(argVc["sample_metadata_path"]) 294 args_env$sample_metadata_path <- as.character(argVc["sample_metadata_path"])
286 295
287 # other parameters 296 # other parameters
288 297
289 # multi-string args - split csv: "1,2,3" -> c("1","2","3") 298 # multi-string args - split csv: "1,2,3" -> c("1","2","3")
290 args_env$kfeatures <- strsplit(x = as.character(argVc['kfeatures']), split = ",", fixed = TRUE)[[1]] 299 args_env$kfeatures <- strsplit(x = as.character(argVc['kfeatures']), split = ",", fixed = TRUE)[[1]]
291 args_env$ksamples <- strsplit(x = as.character(argVc['ksamples' ]), split = ",", fixed = TRUE)[[1]] 300 args_env$ksamples <- strsplit(x = as.character(argVc['ksamples' ]), split = ",", fixed = TRUE)[[1]]
303 312
304 log_print("PARAMETERS (parsed):") 313 log_print("PARAMETERS (parsed):")
305 for (member in ls(args_env)) { 314 for (member in ls(args_env)) {
306 value <- get(member, args_env) 315 value <- get(member, args_env)
307 value <- ifelse(length(value) == 1, value, sprintf("c(%s)", paste(value, collapse=", "))) 316 value <- ifelse(length(value) == 1, value, sprintf("c(%s)", paste(value, collapse=", ")))
308 317
309 log_print(sprintf(" - %s: %s", member, ifelse( !is.function(value) , value, "function" ))) 318 log_print(sprintf(" - %s: %s", member, ifelse( !is.function(value) , value, "function" )))
310 } 319 }
311 log_print("") 320 log_print("")
312 321
313 ##--------------------------------------------------------- 322 ##---------------------------------------------------------
314 ## Computation - attempt to read input data 323 ## Computation - attempt to read input data and process
315 ##--------------------------------------------------------- 324 ##---------------------------------------------------------
316 if ( ! read_input_data(args_env, failure_action = read_input_failure_action) ) { 325 if ( ! read_input_data(args_env, failure_action = read_input_failure_action) ) {
317 result <- -1 326 result <- -1
318 } else { 327 } else {
319 log_print("Input data was read successfully.") 328 log_print("Input data was read.")
329 # attempt to process the data
320 result <- w4mkmeans(env = args_env) 330 result <- w4mkmeans(env = args_env)
321 log_print("returned from call to w4mkmeans.") 331 log_print("Returned from call to w4mkmeans.")
322 } 332 }
323 333
324 if ( length(result) == 0 ) { 334 if ( length(result) == 0 ) {
325 log_print("no results were produced") 335 log_print("no results were produced")
326 # exit with status code non-zero to indicate error 336 # exit with status code non-zero to indicate error
354 364
355 ##-------- 365 ##--------
356 ## Closing 366 ## Closing
357 ##-------- 367 ##--------
358 368
359
360 if (!file.exists(sampleMetadata_out)) { 369 if (!file.exists(sampleMetadata_out)) {
361 log_print(sprintf("ERROR %s::w4m_kmeans_wrapper - file '%s' was not created", modNamC, sampleMetadata_out)) 370 log_print(sprintf("ERROR %s::w4m_kmeans_wrapper - file '%s' was not created", modNamC, sampleMetadata_out))
362 } 371 }
363 372
364 if (!file.exists(variableMetadata_out)) { 373 if (!file.exists(variableMetadata_out)) {