diff w4mcorcov_wrapper.R @ 6:7bd523ca1f9a draft

planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit cafda5095a79ce2376325b57337302f95137195d
author eschen42
date Wed, 18 Jul 2018 12:35:55 -0400
parents 50f60f94c034
children 342570ad880c
line wrap: on
line diff
--- a/w4mcorcov_wrapper.R	Fri Mar 30 14:59:19 2018 -0400
+++ b/w4mcorcov_wrapper.R	Wed Jul 18 12:35:55 2018 -0400
@@ -33,7 +33,7 @@
 ##---------
 
 my_log <- function(x, ...) { cat(paste(iso8601.znow(), " ", x, ..., nl, sep=""))}
-my_fatal <- function(x, ...) { 
+my_fatal <- function(x, ...) {
   my_log("ERROR: ", x, ...)
   quit(save = "no", status = 11, runLast = TRUE)
 }
@@ -72,6 +72,9 @@
 my_env$levCSV             <- as.character(argVc["levCSV"])
 my_env$matchingC          <- as.character(argVc["matchingC"])
 my_env$labelFeatures      <- as.character(argVc["labelFeatures"]) # number of features to label at each extreme of the loadings or 'ALL'
+my_env$cplot_o            <- as.logical(argVc["cplot_o"]) # TRUE if orthogonal C-plot is requested
+my_env$cplot_p            <- as.logical(argVc["cplot_p"]) # TRUE if parallel C-plot is requested
+my_env$cplot_y            <- as.character(argVc["cplot_y"]) # Choice of covariance/correlation for Y-axis on C-plot
 
 label_features <- my_env$labelFeatures
 labelfeatures_check <- TRUE
@@ -128,24 +131,70 @@
 
   # compute and plot the correlation_vs_covariance details plot
   #   The parameter settings here are generally taken from bioconductor ropls::plot.opls source.
-  marVn <- c(4.6, 4.1, 2.6, 1.6)
-  old_par <- par(
-    font      = 2         # bold font face
-  , font.axis = 2         # bold font face for axis
-  , font.lab  = 2         # bold font face for x and y labels
-  , lwd       = 2         # line-width - interpretation is device spcific
-  , mar       = marVn     # margins
-  , pch       = 18        # black diamond plot-character, see help for graphics::points
-  # , mfrow     = c(2,2)    # two rows by two columns
-  , pty       = "s"       # force plots to be square
-  )
+  if ( my_env$cplot_p || my_env$cplot_o ) {
+    old_par <- par(
+      font        = 2         # bold font face
+    , font.axis   = 2         # bold font face for axis
+    , font.lab    = 2         # bold font face for x and y labels
+    , lwd         = 2         # line-width - interpretation is device spcific
+    , pch         = 18        # black diamond plot-character, see help for graphics::points
+    , pty         = "m"       # do not force plots to be square
+    , no.readonly = TRUE      # only save writable parameters
+    )
+    pdf_height <- 12
+    pdf_width  <- 8
+    my_layout <- function() {
+      # lay out 2 columns by 3 rows with extra width at the margin of individual plots
+      layout(
+        matrix(
+          # blank row  plot 1 & 2  blank row  plot 3 & 4  blank row  plot 5 & 6 blank row
+          c(0,0,0,0,0, 0,1,0,2,0,  0,0,0,0,0, 0,3,0,4,0,  0,0,0,0,0, 0,5,0,6,0, 0,0,0,0,0)
+        , nrow = 7
+        , ncol = 5
+        , byrow = TRUE
+        )
+        # slim columns 1, 3, and 5
+      , widths  = c(0.1, 0.9, 0.1, 0.9, 0.1)
+        # slim rows 1, 3, 5, and 7
+      , heights = c(0.1, 0.9, 0.1, 0.9, 0.1, 0.9, 0.1)
+      )
+    }
+  } else {
+    old_par <- par(
+      font        = 2         # bold font face
+    , font.axis   = 2         # bold font face for axis
+    , font.lab    = 2         # bold font face for x and y labels
+    , lwd         = 2         # line-width - interpretation is device spcific
+    , pch         = 18        # black diamond plot-character, see help for graphics::points
+    , pty         = "m"       # do not force plots to be square
+    , no.readonly = TRUE      # only save writable parameters
+    )
+    pdf_height <- 8
+    pdf_width  <- 8
+    my_layout <- function() {
+      # lay out 2 columns by 2 rows with extra width at the margin of individual plots
+      layout(
+        matrix(
+          # blank row  plot 1 & 2  blank row  plot 3 & 4  blank row
+          c(0,0,0,0,0, 0,1,0,2,0,  0,0,0,0,0, 0,3,0,4,0,  0,0,0,0,0)
+        , nrow = 5
+        , ncol = 5
+        , byrow = TRUE
+        )
+        # slim columns 1, 3, and 5
+      , widths  = c(0.1, 0.9, 0.1, 0.9, 0.1)
+        # slim rows 1, 3, and 5
+      , heights = c(0.1, 0.9, 0.1, 0.9, 0.1)
+      )
+    }
+  }
   plot2pdf(
     file.name = my_env$contrast_detail
-  , width  = 8
-  , height = 8
+  , width  = pdf_width
+  , height = pdf_height
   , plot.function = function() {
-      # plot layout four plots per page
-      layout(matrix(1:4, byrow = TRUE, nrow = 2))
+      # plot layout four or six plots per page
+      my_layout()
       my_result <<- corcov_calc(
           calc_env            = my_env
         , failure_action      = my_fatal
@@ -156,7 +205,7 @@
     }
   )
   par(old_par)
-  
+
   my_log( "--------------------------  Finished data processing  --------------------------")
 }