diff w4mcorcov_output.R @ 5:50f60f94c034 draft

planemo upload for repository https://github.com/HegemanLab/w4mcorcov_galaxy_wrapper/tree/master commit aff1790e25523d038a1e9528de748191c096132f
author eschen42
date Fri, 30 Mar 2018 14:59:19 -0400
parents 23f9fad4edfc
children
line wrap: on
line diff
--- a/w4mcorcov_output.R	Sun Mar 04 14:51:42 2018 -0500
+++ b/w4mcorcov_output.R	Fri Mar 30 14:59:19 2018 -0400
@@ -0,0 +1,77 @@
+
+# turn off all plotting devices
+dev.off.all <- function() {
+  while (!is.null(dev.list())) { dev.off() }
+}
+  
+# capture plot and write to PDF; then close any devices opened in the process
+plot2pdf <- function(
+  file.name
+, plot.function
+, width = 12
+, height = 12
+) {
+  # capture plot and write to PDF
+  cur.dev <- dev.list()
+  filename <- file.name
+  pdf(file = filename, width = width, height = height)
+  plot.function()
+  # close any devices opened in the process
+  dev.off()
+  if (is.null(cur.dev)) {
+      dev.off.all()
+  } else {
+      while ( length(dev.list()) > length(cur.dev) ) { dev.off() }
+  }
+}
+
+# print and capture plot and write to PDF; then close any devices opened in the process
+#   This is needed for ggplot which does not print the plot when invoked within a function.
+print2pdf <- function(
+  file.name
+, plot.function
+, width = 12
+, height = 12
+) {
+  plot2pdf(
+    file.name = file.name
+  , width = width
+  , height = height
+  , plot.function = function() {
+      print(plot.function())
+    }
+  )
+}
+
+iso8601.znow <- function()
+{
+  strftime(as.POSIXlt(Sys.time(), "UTC"), "%Y-%m-%dT%H:%M:%SZ")
+}
+
+# pdf.name <- function(name)
+# {
+#   paste0(name, "_", iso8601.filename.fragment(), ".pdf")
+# }
+#
+# tsv.name <- function(name)
+# {
+#   paste0(name, "_", iso8601.filename.fragment(), ".tsv")
+# }
+#
+
+tsv_action_factory <- function(file, colnames, append) {
+  return (
+    function(tsv) {
+      write.table(
+        x = tsv
+      , file = file
+      , sep = "\t"
+      , quote = FALSE
+      , row.names = FALSE
+      , col.names = colnames
+      , append = append
+      )
+    }
+  )
+}
+