comparison phonR_tool.R @ 3:24f05f509f09 draft

planemo upload commit e4adec77d8b4e6385b7db85ebbe01cfb85ed8de2
author stevecassidy
date Fri, 14 Oct 2016 15:07:25 -0400
parents 3d068b7441be
children
comparison
equal deleted inserted replaced
2:3e7b945648a4 3:24f05f509f09
2 # Galaxy tool that plots Vowels using the phonR package. 2 # Galaxy tool that plots Vowels using the phonR package.
3 # Accepts 8 inputs of the form <tsv data file> <output file name> <column1> <column2> <optPretty> <optEllipse> <optTokens> <optMeans> 3 # Accepts 8 inputs of the form <tsv data file> <output file name> <column1> <column2> <optPretty> <optEllipse> <optTokens> <optMeans>
4 # Created by Michael Bauer 4 # Created by Michael Bauer
5 # 5 #
6 library(phonR) 6 library(phonR)
7 library('getopt') 7 library(getopt)
8 8
9 #create options 9 #create options
10 option_specification = matrix(c( 10 option_specification = matrix(c(
11 'outdir', 'f', 1, 'character', 11 'pdffile', 'h', 1, 'character',
12 'htmlfile', 'h', 1, 'character',
13 'inputfile', 'i', 1, 'character', 12 'inputfile', 'i', 1, 'character',
14 'column1', 'y', 1, 'integer', 13 'column1', 'y', 1, 'integer',
15 'column2', 'z', 1, 'integer', 14 'column2', 'z', 1, 'integer',
16 'columnvowels', 'x', 1, 'integer', 15 'columnvowels', 'x', 1, 'integer',
17 'pretty', 'p', 1, 'logical', 16 'pretty', 'p', 1, 'logical',
24 ), byrow=TRUE, ncol=4); 23 ), byrow=TRUE, ncol=4);
25 24
26 # Parse options 25 # Parse options
27 options = getopt(option_specification); 26 options = getopt(option_specification);
28 27
29 if (!is.null(options$outdir)) { 28 pdffile <- gsub("[ ]+", "", paste(options$pdffile))
30 # Create the directory
31 dir.create(options$outdir,FALSE)
32 }
33
34 pngfile <- gsub("[ ]+", "", paste(options$outdir,"/pngfile.png"))
35 htmlfile <- gsub("[ ]+", "", paste(options$htmlfile))
36 29
37 data = read.table(options$inputfile,sep="\t", header=TRUE); 30 data = read.table(options$inputfile,sep="\t", header=TRUE);
38 31
39 png(pngfile); 32 pdf(pdffile);
40 33
41 plotVowels(data[,options$column1], data[,options$column2], data[,options$columnvowels], plot.tokens = options$tokens, 34 plotVowels(data[,options$column1], data[,options$column2], data[,options$columnvowels], plot.tokens = options$tokens,
42 pch.tokens = data[,options$columnvowels], cex.tokens = options$cextokens, alpha.tokens = options$alphatokens, 35 pch.tokens = data[,options$columnvowels], cex.tokens = options$cextokens, alpha.tokens = options$alphatokens,
43 plot.means = options$means, pch.means = data[,options$columnvowels], cex.means = options$cexmeans, 36 plot.means = options$means, pch.means = data[,options$columnvowels], cex.means = options$cexmeans,
44 var.col.by = data[,options$columnvowels], ellipse.line = options$ellipse, pretty = options$pretty) 37 var.col.by = data[,options$columnvowels], ellipse.line = options$ellipse, pretty = options$pretty)
45 dev.off(); 38 dev.off();
46
47 htmlfile_handle <- file(htmlfile)
48 html_output = c('<html><body>',
49 '<h3>Result:</h3><img src="pngfile.png"/>',
50 '</html></body>');
51 writeLines(html_output, htmlfile_handle);
52 close(htmlfile_handle);