comparison masigpro.R @ 0:c8c290f3ea7d draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/masigpro commit 5798bd978553dee97521c39920d263dd750e0755
author iuc
date Mon, 15 May 2017 07:29:03 -0400
parents
children cc96abdef027
comparison
equal deleted inserted replaced
-1:000000000000 0:c8c290f3ea7d
1 #!/usr/bin/env Rscript
2
3 # A command-line interface to maSigPro for use with Galaxy
4 # written by Clemens Blank.
5 # Thanks to Bjoern Gruening and Michael Love for their DESeq2
6 # wrapper as a basis to build upon.
7
8 # setup R error handling to go to stderr
9 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
10
11 # we need that to not crash galaxy with an UTF8 error on German LC settings.
12 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
13
14 suppressPackageStartupMessages({
15 library("maSigPro")
16 library("optparse")
17 library("mclust")
18 })
19
20 options(stringAsFactors = FALSE, useFancyQuotes = FALSE)
21 args <- commandArgs(trailingOnly = TRUE)
22
23 # specify our desired options in a list
24 # by default OptionParser will add an help option equivalent to
25 # make_option(c("-h", "--help"), action="store_true", default=FALSE,
26 # help="Show this help message and exit")
27 option_list <- list(
28 make_option(c("-q", "--quiet"), action="store_false",
29 dest="verbose", help="Print little output"),
30 make_option(c("-e", "--edesign"), type="character"),
31 make_option(c("-d", "--data"), type="character"),
32 make_option(c("-o", "--outfile"), type="character"),
33 make_option("--degree", type="integer", default=1),
34 make_option("--time_col", type="integer", default=1),
35 make_option("--repl_col", type="integer", default=2),
36 make_option("--qvalue", type="double", default=0.05),
37 make_option("--min_obs", type="integer", default=6),
38 make_option("--step_method", type="character", default="backward"),
39 make_option("--nvar_correction", type="logical", default=FALSE),
40 make_option("--alfa", type="double", default=0.05),
41 make_option("--rsq", type="double", default=0.7),
42 make_option("--vars", type="character", default="groups"),
43 make_option("--significant_intercept", type="character", default="dummy"),
44 make_option("--cluster_data", type="integer", default=1),
45 make_option(c("-k", "--k"), type="integer", default=9),
46 make_option("--cluster_method", type="character", default="hclust"),
47 make_option("--distance", type="character", default="cor"),
48 make_option("--agglo_method", type="character", default="ward.D"),
49 make_option("--iter_max", type="integer", default=500),
50 make_option("--color_mode", type="character", default="rainbow"),
51 make_option("--show_fit", type="logical", default=TRUE),
52 make_option("--show_lines", type="logical", default=TRUE),
53 make_option("--cexlab", type="double", default=0.8),
54 make_option("--legend", type="logical", default=TRUE)
55 )
56
57 # get command line options, if help option encountered print help and exit,
58 # otherwise if options not found on command line then set defaults
59 opt <- parse_args(OptionParser(option_list=option_list))
60
61 # enforce the following required arguments
62 if (is.null(opt$edesign)) {
63 cat("'edesign' is required\n")
64 q(status=1)
65 }
66 if (is.null(opt$data)) {
67 cat("'data' is required\n")
68 q(status=1)
69 }
70 if (is.null(opt$outfile)) {
71 cat("'outfile' is required\n")
72 q(status=1)
73 }
74
75 verbose <- if (is.null(opt$quiet)) {
76 TRUE
77 } else {
78 FALSE
79 }
80
81 edesign <- as.matrix(read.table(opt$edesign, header=TRUE, row.names = 1))
82
83 data <- read.table(opt$data, header=TRUE)
84
85 results <- maSigPro(data, edesign, degree = opt$degree, time.col = opt$time_col,
86 repl.col = opt$repl_col, Q = opt$qvalue, min.obs = opt$min_obs,
87 step.method = opt$step_method, nvar.correction = opt$nvar_correction,
88 alfa = opt$alfa, rsq = opt$rsq, vars = opt$vars,
89 significant.intercept = opt$significant_intercept,
90 cluster.data = opt$cluster_data, k = opt$k,
91 cluster.method = opt$cluster_method, distance = opt$distance,
92 agglo.method = opt$agglo_method, iter.max = opt$iter_max,
93 color.mode = opt$color_mode, show.fit = opt$show_fit,
94 show.lines = opt$show_lines, cexlab = opt$cexlab,
95 legend = opt$legend)
96
97 filename <- opt$outfile
98
99 write.table((results$summary), file=filename, sep="\t", quote=FALSE,
100 row.names=FALSE, col.names=TRUE)
101
102 cat("Session information:\n\n")
103
104 sessionInfo()