diff charts.r @ 1:344ac3ca7557 draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/charts/ commit 4494db13b69987fbc97d47177d2a5956e46e927b"
author iuc
date Wed, 17 Nov 2021 09:06:59 +0000
parents a87a3773d8ed
children
line wrap: on
line diff
--- a/charts.r	Fri Mar 09 08:23:08 2018 -0500
+++ b/charts.r	Wed Nov 17 09:06:59 2021 +0000
@@ -1,13 +1,13 @@
 #!/usr/bin/Rscript
 
 # load getopt library
-library('getopt');
+library("getopt");
 
 # convert multi parameter string (i.e. key1: value, key2: value, ...) to object
-split <- function(argument){
+split <- function(argument) {
     # process parameter string
     options <- list()
-    list <- gsub("\\s","", argument)
+    list <- gsub("\\s", "", argument)
     list <- strsplit(list, ",")
     if (length(list) > 0) {
         list <- list[[1]]
@@ -25,92 +25,92 @@
 }
 
 # get options, using the spec as defined by the enclosed list.
-spec = matrix(c(
-    'workdir',  'w', 1, 'character', 'Work directory',
-    'module',   'm', 1, 'character', 'Module name',
-    'input',    'i', 1, 'character', 'Input tabular file',
-    'columns',  'c', 1, 'character', 'Columns string',
-    'settings', 's', 1, 'character', 'Settings string',
-    'output',   'o', 1, 'character', 'Output tabular file',
-    'help',     'h', 0, '',          'Help',
-    'verbose',  'v', 0, '',          'Verbose'
-), byrow=TRUE, ncol=5);
-opt = getopt(spec);
+spec <- matrix(c(
+    "workdir",  "w", 1, "character", "Work directory",
+    "module",   "m", 1, "character", "Module name",
+    "input",    "i", 1, "character", "Input tabular file",
+    "columns",  "c", 1, "character", "Columns string",
+    "settings", "s", 1, "character", "Settings string",
+    "output",   "o", 1, "character", "Output tabular file",
+    "help",     "h", 0, "",          "Help",
+    "verbose",  "v", 0, "",          "Verbose"
+), byrow = TRUE, ncol = 5);
+opt <- getopt(spec);
 
 # show help
-if ( !is.null(opt$help) ||
+if (!is.null(opt$help) ||
     is.null(opt$module) ||
     is.null(opt$input) ||
     is.null(opt$columns) ||
     is.null(opt$output)) {
-    cat(getopt(spec, usage=TRUE))
-    q(status=1);
+    cat(getopt(spec, usage = TRUE))
+    q(status = 1);
 }
 
 # read columns/settings
-columns = split(opt$columns)
-settings = split(opt$settings)
+columns <- split(opt$columns)
+settings <- split(opt$settings)
 
 # read table
-table <- read.table(opt$input, comment.char='#', fill=TRUE)
+table <- read.table(opt$input, comment.char = "#", fill = TRUE)
 
 # identify module file
-module_file = paste(opt$workdir, opt$module, '.r', sep='')
+module_file <- paste(opt$workdir, opt$module, ".r", sep = "")
 
 # source module
 source(module_file)
 
 # run module
-l = wrapper (table, columns, settings)
+l <- wrapper(table, columns, settings)
 
 # header
-header_title <- '# title - Chart Utilities (charts)'
-header_date <- paste('# date -', Sys.time(), sep=' ')
-header_module <- paste('# module -', opt$module, sep=' ')
-header_settings <- paste('# settings -', opt$settings, sep=' ')
-header_columns <- paste('# columns -', opt$columns, sep=' ')
+header_title <- "# title - Chart Utilities (charts)"
+header_date <- paste("# date -", Sys.time(), sep = " ")
+header_module <- paste("# module -", opt$module, sep = " ")
+header_settings <- paste("# settings -", opt$settings, sep = " ")
+header_columns <- paste("# columns -", opt$columns, sep = " ")
 
 # check result
 if (length(l) > 0) {
     # print details
     if (!is.null(opt$verbose)) {
-        print ('Columns:')
-        print (columns)
-        print ('Settings:')
-        print (settings)
-        print ('Result:')
-        print (l)
+        print("Columns:")
+        print(columns)
+        print("Settings:")
+        print(settings)
+        print("Result:")
+        print(l)
     }
 
     # create output file
-    output <- file(opt$output, open='wt')
-    
+    output <- file(opt$output, open = "wt")
+
     # write header
-    writeLines('#', output)
+    writeLines("#", output)
     writeLines(header_title, output)
     writeLines(header_date, output)
     writeLines(header_module, output)
     writeLines(header_settings, output)
     writeLines(header_columns, output)
-    writeLines('#', output)
-    
+    writeLines("#", output)
+
     # pad columns
     rows <- max(unlist(lapply(l, length)))
     padded <- lapply(l, function(col) {
-        length(col) = rows;
+        length(col) <- rows;
         col
     })
-    
+
     # write table
-    write.table(padded, file=output, row.names=FALSE, col.names = FALSE, quote=FALSE, sep='\t')
-    
+    write.table(padded, file = output, row.names = FALSE, col.names  =  FALSE, quote = FALSE, sep = "\t")
+
     # close file
     close(output)
 } else {
     # print details
-    print ('Columns:')
-    print (columns)
-    print ('Settings:')
-    print (settings)
-    print ('No output generated.')
+    print("Columns:")
+    print(columns)
+    print("Settings:")
+    print(settings)
+    print("No output generated.")
 }
\ No newline at end of file