diff 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
line wrap: on
line diff
--- a/w4mkmeans_wrapper.R	Wed Aug 09 18:06:55 2017 -0400
+++ b/w4mkmeans_wrapper.R	Mon Mar 05 12:40:17 2018 -0500
@@ -22,7 +22,7 @@
 #     slots "${GALAXY_SLOTS:-1}" \
 #     variableMetadata_out "$variableMetadata_out" \
 #     variable_metadata_path "$variableMetadata_in"
-# 
+#
 # <inputs>
 #   <param name="dataMatrix_in" label="Data matrix file" type="data" format="tabular" help="variable x sample, decimal: '.', missing: NA, mode: numerical, separator: tab" />
 #   <param name="sampleMetadata_in" label="Sample metadata file" type="data" format="tabular" help="sample x metadata columns, separator: tab" />
@@ -30,8 +30,8 @@
 #   <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'." />
 #   <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." />
 #   <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." />
-#   <param name="iter_max" label="Max number of iterations" type="text" value="10" help="The maximum number of iterations allowed; default 10." />
-#   <param name="nstart" label="Number of random sets" type="text" value="1" help="How many random sets should be chosen; default 1." />
+#   <param name="iter_max" label="Max number of iterations" type="text" value="20" help="The maximum number of iterations allowed; default 20." />
+#   <param name="nstart" label="Number of random sets" type="text" value="20" help="How many random sets should be chosen; default 20." />
 # 	<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.">
 # 	  <option value="Hartigan-Wong" selected="TRUE">Hartigan-Wong</option>
 # 	  <option value="Lloyd">Lloyd</option>
@@ -66,7 +66,7 @@
 ## Computation - source general and module-specific routines
 ##----------------------------------------------------------
 
-log_print <- function(x, ...) { 
+log_print <- function(x, ...) {
   cat(
     format(Sys.time(), "%Y-%m-%dT%H:%M:%S%z")
   , " "
@@ -77,6 +77,15 @@
   )
 }
 
+log_cat <- function(x, ...) {
+  cat(
+    c(x, ...)
+  , "\n"
+  , sep=""
+  , file=stderr()
+  )
+}
+
 # log_print(sprintf("tool_directory is %s", tool_directory))
 
 w4m_general_purpose_routines_path <- r_path("w4m_general_purpose_routines.R")
@@ -85,7 +94,7 @@
   log_print("cannot find file w4m_general_purpose_routines.R")
   q(save = "no", status = 1, runLast = TRUE)
 }
-# log_print("sourcing ",w4m_general_purpose_routines_path)
+log_print("sourcing ",w4m_general_purpose_routines_path)
 source(w4m_general_purpose_routines_path)
 if ( ! exists("prepare.data.matrix") ) {
   log_print("'prepare.data.matrix' was not read from file w4m_general_purpose_routines.R")
@@ -164,7 +173,7 @@
     expr = {
       # read in the sample metadata
       kind_string <- "sample metadata input"
-      smpl_metadata_input_env <- 
+      smpl_metadata_input_env <-
         read_data_frame(
                          file_path = env$sample_metadata_path
                        , kind_string = kind_string
@@ -178,7 +187,7 @@
 
       # read in the variable metadata
       kind_string <- "variable metadata input"
-      vrbl_metadata_input_env <- 
+      vrbl_metadata_input_env <-
         read_data_frame(
                          file_path = env$variable_metadata_path
                        , kind_string = kind_string
@@ -218,7 +227,7 @@
 }
 
 
-read_input_failure_action <- function(x, ...) { 
+read_input_failure_action <- function(x, ...) {
   log_print("Failure reading input for '", modNamC, "' Galaxy module call")
   log_print(x, ...)
 }
@@ -238,7 +247,7 @@
 
 # Set the handler for R error-handling
 options( show.error.messages = F
-       , error = function () { 
+       , error = function () {
                    log_print( "Fatal error in '", modNamC, "': ", geterrmessage() )
                    q( "no", 1, F )
                  }
@@ -283,7 +292,7 @@
 args_env$data_matrix_path       <- as.character(argVc["data_matrix_path"])
 args_env$variable_metadata_path <- as.character(argVc["variable_metadata_path"])
 args_env$sample_metadata_path   <- as.character(argVc["sample_metadata_path"])
-  
+
 # other parameters
 
 # multi-string args - split csv: "1,2,3" -> c("1","2","3")
@@ -305,20 +314,21 @@
 for (member in ls(args_env)) {
   value <- get(member, args_env)
   value <- ifelse(length(value) == 1, value, sprintf("c(%s)", paste(value, collapse=", ")))
-  
+
   log_print(sprintf("  - %s: %s", member, ifelse( !is.function(value) , value, "function" )))
 }
 log_print("")
 
 ##---------------------------------------------------------
-## Computation - attempt to read input data
+## Computation - attempt to read input data and process
 ##---------------------------------------------------------
 if ( ! read_input_data(args_env, failure_action = read_input_failure_action) ) {
   result <- -1
 } else {
-  log_print("Input data was read successfully.")
+  log_print("Input data was read.")
+  # attempt to process the data
   result <- w4mkmeans(env = args_env)
-  log_print("returned from call to w4mkmeans.")
+  log_print("Returned from call to w4mkmeans.")
 }
 
 if ( length(result) == 0 ) {
@@ -356,7 +366,6 @@
 ## Closing
 ##--------
 
-
 if (!file.exists(sampleMetadata_out)) {
   log_print(sprintf("ERROR %s::w4m_kmeans_wrapper - file '%s' was not created", modNamC, sampleMetadata_out))
 }