annotate plot_barplot.R @ 0:a8e03ffaaedc draft

planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
author bebatut
date Mon, 18 Apr 2016 10:35:54 -0400
parents
children 7e3103db022d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
1 library('getopt')
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
2
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
3 option_specification = matrix(c(
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
4 'input_file', 'i', 2, 'character',
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
5 'output_pdf_file', 'p', 2, 'character',
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
6 'output_png_file', 'o', 2, 'character',
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
7 'output_svg_file', 's', 2, 'character',
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
8 'data_column', 'd', 2, 'integer',
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
9 'names_column', 'n', 2, 'integer',
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
10 'xlab', 'x', 2, 'character',
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
11 'col', 'c', 2, 'character',
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
12 'bottom_margin', 'b', 2, 'integer',
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
13 'left_margin', 'l', 2, 'integer',
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
14 'top_margin', 't', 2, 'integer',
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
15 'right_margin', 'r', 2, 'integer',
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
16 'header','y',2,'logical'
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
17 ), byrow=TRUE, ncol=4);
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
18
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
19 options = getopt(option_specification);
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
20
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
21 header = TRUE
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
22 if(!is.null(options$header)) header = options$header
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
23
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
24 data = read.table(options$input_file, sep = '\t', h = header)
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
25
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
26 data_column = 2
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
27 if(!is.null(options$data_column)) data_column = options$data_column
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
28 names_column = 1
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
29 if(!is.null(options$names_column)) names_column = options$names_column
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
30
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
31 margin = c(5,19,1,1)
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
32 if(!is.null(options$bottom_margin)) margin[1] = options$bottom_margin
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
33 if(!is.null(options$left_margin)) margin[2] = options$left_margin
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
34 if(!is.null(options$top_margin)) margin[3] = options$top_margin
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
35 if(!is.null(options$right_margin)) margin[4] = options$right_margin
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
36
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
37 xlab = ""
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
38 if(!is.null(options$xlab)) xlab = options$xlab
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
39
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
40 col = "grey"
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
41 if(!is.null(options$col)) col = options$col
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
42
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
43 plot_barplot <- function(){
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
44 par(las=2)
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
45 par(mar=margin)
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
46 barplot(data[, data_column], horiz = T, xlab = xlab,
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
47 names.arg = data[, names_column], col = col, cex.names=0.7,
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
48 cex.axis = 0.8)
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
49 }
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
50
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
51 if(!is.null(options$output_pdf_file)){
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
52 pdf(options$output_pdf_file)
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
53 plot_barplot()
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
54 dev.off()
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
55 }
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
56
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
57 if(!is.null(options$output_svg_file)){
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
58 svg(options$output_svg_file)
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
59 plot_barplot()
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
60 dev.off()
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
61 }