Repository 'w4mcorcov'
hg clone https://toolshed.g2.bx.psu.edu/repos/eschen42/w4mcorcov

Changeset 11:ddcc33ff3205 (2018-09-05)
Previous changeset 10:9a52306991b3 (2018-09-01) Next changeset 12:ddaf84e15d06 (2018-11-08)
Commit message:
planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit 4428e3252d54c8a8e0e5d85e8eaaeb13e9b21de7
modified:
w4mcorcov.xml
w4mcorcov_calc.R
w4mcorcov_lib.R
w4mcorcov_util.R
w4mcorcov_wrapper.R
b
diff -r 9a52306991b3 -r ddcc33ff3205 w4mcorcov.xml
--- a/w4mcorcov.xml Sat Sep 01 11:33:03 2018 -0400
+++ b/w4mcorcov.xml Wed Sep 05 22:31:21 2018 -0400
[
@@ -1,4 +1,4 @@
-<tool id="w4mcorcov" name="OPLS-DA_Contrasts" version="0.98.14">
+<tool id="w4mcorcov" name="OPLS-DA_Contrasts" version="0.98.15">
     <description>OPLS-DA Contrasts of Univariate Results</description>
     <macros>
         <xml name="paramPairSigFeatOnly">
@@ -419,20 +419,20 @@
           <has_text text="vip4o" />
           <!-- first matched line -->
           <has_text text="M349.2383T700" />
-          <has_text text="-0.37867079" />
-          <has_text text="-37.71066" />
-          <has_text text="0.5246766" />
-          <has_text text="0.0103341" />
+          <has_text text="0.43361563" />
+          <has_text text="37.76875778" />
+          <has_text text="0.54672558" />
+          <has_text text="0.3920409" />
           <!-- second matched line -->
           <has_text text="M207.9308T206" />
-          <has_text text="0.31570433" />
-          <has_text text="5.86655640" />
-          <has_text text="0.2111623" />
-          <has_text text="0.0488654" />
+          <has_text text="-0.3365475" />
+          <has_text text="-6.337903" />
+          <has_text text="0.270297" />
+          <has_text text="0.037661" />
         </assert_contents>
       </output>
     </test>
-    <!-- test #6 -->
+    <!-- test #6 - issue 6 -->
     <test>
       <param name="dataMatrix_in" value="input_dataMatrix.tsv"/>
       <param name="sampleMetadata_in" value="issue6_input_sampleMetadata.tsv"/>
@@ -461,6 +461,32 @@
         </assert_contents>
       </output>
     </test>
+    <!-- test #6 - issue 8 -->
+    <test>
+      <param name="dataMatrix_in" value="input_dataMatrix.tsv"/>
+      <param name="sampleMetadata_in" value="issue8_input_sampleMetadata.tsv"/>
+      <param name="variableMetadata_in" value="input_variableMetadata.tsv"/>
+      <param name="tesC" value="none"/>
+      <param name="facC" value="k._10"/>
+      <param name="labelFeatures" value="3"/>
+      <param name="levCSV" value="k_3,k-4"/>
+      <param name="matchingC" value="none"/>
+      <output name="contrast_corcov">
+        <assert_contents>
+          <!-- column-labels line -->
+          <has_text text="featureID" />
+          <has_text text="factorLevel1" />
+          <has_text text="factorLevel2" />
+          <has_text text="correlation" />
+          <has_text text="covariance" />
+          <has_text text="vip4p" />
+          <has_text text="vip4o" />
+          <!-- k1 rejected by levCSV, leaving only k_3 and k-4 -->
+          <not_has_text text="k1" />
+          <not_has_text text="other" />
+        </assert_contents>
+      </output>
+    </test>
   </tests>
   <help><![CDATA[
 
b
diff -r 9a52306991b3 -r ddcc33ff3205 w4mcorcov_calc.R
--- a/w4mcorcov_calc.R Sat Sep 01 11:33:03 2018 -0400
+++ b/w4mcorcov_calc.R Wed Sep 05 22:31:21 2018 -0400
[
b'@@ -71,7 +71,9 @@\n       # print("str(my_cor_vs_cov)")\n       # str(my_cor_vs_cov)\n       if (is.null(my_cor_vs_cov) || sum(!is.na(my_cor_vs_cov$tsv1$covariance)) < 2) {\n-        x_progress("No cor_vs_cov data produced")\n+        if (is.null(cor_vs_cov_x)) {\n+          x_progress("No cor_vs_cov data produced")\n+        }\n         plot(x=1, y=1, xaxt="n", yaxt="n", xlab="", ylab="", type="n")\n         text(x=1, y=1, labels="too few covariance data")\n         return(my_cor_vs_cov)\n@@ -561,7 +563,8 @@\n       plot_action <- function(fctr_lvl_1, fctr_lvl_2) {\n         progress_action(\n           sprintf("calculating/plotting contrast of %s vs. %s"\n-                 , fctr_lvl_1, fctr_lvl_2))\n+                 , fctr_lvl_1, fctr_lvl_2)\n+        )\n         predictor <- sapply(\n           X = chosen_facC\n         , FUN = function(fac) if ( fac == fctr_lvl_1 ) fctr_lvl_1 else fctr_lvl_2\n@@ -569,7 +572,7 @@\n         my_cor_cov <- do_detail_plot(\n           x_dataMatrix  = my_matrix\n         , x_predictor   = predictor\n-        , x_is_match    = is_match\n+        , x_is_match    = TRUE\n         , x_algorithm   = algoC\n         , x_prefix      = if (pairSigFeatOnly) {\n                             "Significantly contrasting features"\n@@ -582,7 +585,7 @@\n         , x_env         = calc_env\n         )\n         if ( is.null(my_cor_cov) ) {\n-          progress_action("NOTHING TO PLOT.")\n+          progress_action("NOTHING TO PLOT")\n         } else {\n           my_tsv <- my_cor_cov$tsv1\n           my_tsv$mz <- mz_lookup(my_tsv$featureID)\n@@ -619,57 +622,72 @@\n           fctr_lvl_2        <- col_match[3]               #                ^^      # Factor-level 2\n           # only process this column if both factors are members of lvlCSV\n           is_match <- isLevelSelected(fctr_lvl_1) && isLevelSelected(fctr_lvl_2)\n-          progress_action(\n-            sprintf("calculating/plotting contrast of %s vs. %s"\n-                   , fctr_lvl_1, fctr_lvl_2))\n-          # choose only samples with one of the two factors for this column\n-          chosen_samples <- smpl_metadata_facC %in% c(fctr_lvl_1, fctr_lvl_2)\n-          predictor <- smpl_metadata_facC[chosen_samples]\n-          # extract only the significantly-varying features and the chosen samples\n-          fully_significant   <- 1 == vrbl_metadata[,vrbl_metadata_col] *\n-            ( if (intersample_sig_col %in% colnames(vrbl_metadata)) {\n-                vrbl_metadata[,intersample_sig_col]\n-              } else {\n-                1\n-              }\n+          if (is_match) {\n+            progress_action(\n+              sprintf("calculating/plotting contrast of %s vs. %s."\n+                     , fctr_lvl_1, fctr_lvl_2\n+              )\n             )\n-          col_selector <- vrbl_metadata_names[\n-            if ( pairSigFeatOnly ) fully_significant else overall_significant\n-          ]\n-          my_matrix <- tdm[ chosen_samples, col_selector, drop = FALSE ]\n-          my_cor_cov <- do_detail_plot(\n-            x_dataMatrix  = my_matrix\n-          , x_predictor   = predictor\n-          , x_is_match    = is_match\n-          , x_algorithm   = algoC\n-          , x_prefix      = if (pairSigFeatOnly) {\n-                              "Significantly contrasting features"\n-                            } else {\n-                              "Significant features"\n-                            }\n-          , x_show_labels = labelFeatures\n-          , x_progress    = progress_action\n-          , x_crossval_i  = min(7, length(chosen_samples))\n-          , x_env         = calc_env\n-          )\n-          if ( is.null(my_cor_cov) ) {\n-            progress_action("NOTHING TO PLOT.")\n+            # choose only samples with one of the two factors for this column\n+            chosen_samples <- smpl_metadata_facC %in% c(fctr_lvl_1, fctr_lvl_2)\n+            predictor <- smpl_metadata_facC[chosen_samples]\n+            # extract only the significantly-varying features and the chosen samples\n+            fully_signi'..b'env         = calc_env\n+                )\n+                if ( is.null(my_cor_cov) ) {\n+                  progress_action("NOTHING TO PLOT...")\n+                } else {\n+                  tsv <- my_cor_cov$tsv1\n+                  tsv$mz <- mz_lookup(tsv$featureID)\n+                  tsv$rt <- rt_lookup(tsv$featureID)\n+                  corcov_tsv_action(tsv)\n+                  did_plot <<- TRUE\n+                }\n               } else {\n-                tsv <- my_cor_cov$tsv1\n-                tsv$mz <- mz_lookup(tsv$featureID)\n-                tsv$rt <- rt_lookup(tsv$featureID)\n-                corcov_tsv_action(tsv)\n-                did_plot <<- TRUE\n               }\n             }\n             "dummy" # need to return a value; otherwise combn fails with an error\n@@ -738,43 +762,56 @@\n           fctr_lvl_1 <- x[1]\n           fctr_lvl_2 <- x[2]\n           chosen_samples <- smpl_metadata_facC %in% c(fctr_lvl_1, fctr_lvl_2)\n-          progress_action(\n-            sprintf("calculating/plotting contrast of %s vs. %s"\n-                   , fctr_lvl_1, fctr_lvl_2))\n           if (length(unique(chosen_samples)) < 1) {\n-            progress_action("NOTHING TO PLOT...")\n+            progress_action(\n+              sprintf("Skipping contrast of %s vs. %s. - There are no chosen samples."\n+                     , fctr_lvl_1, fctr_lvl_2\n+              )\n+            )\n           } else {\n             chosen_facC <- as.character(smpl_metadata_facC[chosen_samples])\n             predictor <- chosen_facC\n             my_matrix <- tdm[ chosen_samples, , drop = FALSE ]\n             # only process this column if both factors are members of lvlCSV\n             is_match <- isLevelSelected(fctr_lvl_1) && isLevelSelected(fctr_lvl_2)\n-            my_cor_cov <- do_detail_plot(\n-              x_dataMatrix  = my_matrix\n-            , x_predictor   = predictor\n-            , x_is_match    = is_match\n-            , x_algorithm   = algoC\n-            , x_prefix      = "Features"\n-            , x_show_labels = labelFeatures\n-            , x_progress    = progress_action\n-            , x_crossval_i  = min(7, length(chosen_samples))\n-            , x_env         = calc_env\n-            )\n-            if ( is.null(my_cor_cov) ) {\n-              progress_action("NOTHING TO PLOT")\n+            if (is_match) {\n+              progress_action(\n+                sprintf("Calculating/plotting contrast of %s vs. %s."\n+                       , fctr_lvl_1, fctr_lvl_2)\n+                )\n+              my_cor_cov <- do_detail_plot(\n+                x_dataMatrix  = my_matrix\n+              , x_predictor   = predictor\n+              , x_is_match    = is_match\n+              , x_algorithm   = algoC\n+              , x_prefix      = "Features"\n+              , x_show_labels = labelFeatures\n+              , x_progress    = progress_action\n+              , x_crossval_i  = min(7, length(chosen_samples))\n+              , x_env         = calc_env\n+              )\n+              if ( is.null(my_cor_cov) ) {\n+                progress_action("NOTHING TO PLOT.....")\n+              } else {\n+                tsv <- my_cor_cov$tsv1\n+                tsv$mz <- mz_lookup(tsv$featureID)\n+                tsv$rt <- rt_lookup(tsv$featureID)\n+                corcov_tsv_action(tsv)\n+                did_plot <<- TRUE\n+              }\n             } else {\n-              tsv <- my_cor_cov$tsv1\n-              tsv$mz <- mz_lookup(tsv$featureID)\n-              tsv$rt <- rt_lookup(tsv$featureID)\n-              corcov_tsv_action(tsv)\n-              did_plot <<- TRUE\n+              progress_action(\n+                sprintf("Skipping contrast of %s vs. %s."\n+                       , fctr_lvl_1, fctr_lvl_2\n+                )\n+              )\n             }\n           }\n           "dummy" # need to return a value; otherwise combn fails with an error\n         }\n       )\n     } else {\n-      progress_action("NOTHING TO PLOT....")\n+      progress_action("NOTHING TO PLOT......")\n     }\n   }\n   if (!did_plot) {\n'
b
diff -r 9a52306991b3 -r ddcc33ff3205 w4mcorcov_lib.R
--- a/w4mcorcov_lib.R Sat Sep 01 11:33:03 2018 -0400
+++ b/w4mcorcov_lib.R Wed Sep 05 22:31:21 2018 -0400
[
@@ -1,12 +1,3 @@
 suppressMessages(library(batch))
-# suppressMessages(library(foreach))
 suppressMessages(library(ropls))
 suppressMessages(library(methods))
-
-# cat("Installed packages:",stderr())
-# write.table((installed.packages(.Library, priority = "high"))[, c(1,3:5)], stderr())
-# cat("Loaded packages:",stderr())
-# write(.packages(), stderr())
-
-print(sessionInfo())
-
b
diff -r 9a52306991b3 -r ddcc33ff3205 w4mcorcov_util.R
--- a/w4mcorcov_util.R Sat Sep 01 11:33:03 2018 -0400
+++ b/w4mcorcov_util.R Wed Sep 05 22:31:21 2018 -0400
b
@@ -21,10 +21,54 @@
   return (retval)
 }
 
+errorSink <- function(which_function, ...) {
+  var_args <- "..."
+  tryCatch(
+    var_args <<- (deparse(..., width.cutoff = 60))
+  , error = function(e) {print(e$message)}
+  )
+  if (var_args == "...")
+    return
+  # format error for logging
+  format_error <- function(e) {
+    sprintf(
+      "Error\n{  message: %s\n, arguments: %s\n}\n"
+    , e$message
+    , Reduce(f = paste, x = var_args)
+    )
+  }
+  format_warning <- function(e) {
+    sprintf(
+      "Warning\n{  message: %s\n, arguments: %s\n}\n"
+    , e$message
+    , Reduce(f = paste, x = var_args)
+    )
+  }
+  sink_number <- sink.number()
+  sink(stderr())
+  tryCatch(
+    var_args <- (deparse(..., width.cutoff = 60))
+  , expr = {
+      retval <- which_function(...)
+    }
+    , error = function(e) cat(format_error(e), file = stderr())
+    , warning = function(w) cat(format_warning(w), file = stderr())
+  )
+  while (sink.number() > sink_number) {
+    sink()
+  }
+}
+errorPrint <- function(...) {
+  errorSink(which_function = print, ...)
+}
+errorCat <- function(...) {
+  errorSink(which_function = cat, ..., "\n")
+}
+
 
 # # pseudo-inverse - computational inverse of non-square matrix a
 # p.i <- function(a) {
 #   solve(t(a) %*% a) %*% t(a)
 # } 
 
-
+# vim: sw=2 ts=2 et ai :
b
diff -r 9a52306991b3 -r ddcc33ff3205 w4mcorcov_wrapper.R
--- a/w4mcorcov_wrapper.R Sat Sep 01 11:33:03 2018 -0400
+++ b/w4mcorcov_wrapper.R Wed Sep 05 22:31:21 2018 -0400
b
@@ -72,7 +72,12 @@
 # MAIN #
 ########
 
+errorPrint(sessionInfo())
+
 argVc <- unlist(parseCommandArgs(evaluate=FALSE))
+errorCat("\n\n---\n\nArguments that were passed to R are as follows:\n")
+errorPrint(argVc)
+
 my_env <- new.env()
 
 ##------------------------------