annotate plot_barplot.R @ 1:7e3103db022d draft default tip

planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 5653f2982dc5aeccd7701970fdfea444e3e53e3c-dirty
author bebatut
date Wed, 18 May 2016 12:26:19 -0400
parents a8e03ffaaedc
children
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',
1
7e3103db022d planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 5653f2982dc5aeccd7701970fdfea444e3e53e3c-dirty
bebatut
parents: 0
diff changeset
11 'log', 'g', 2, 'logical',
0
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
12 '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
13 '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
14 '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
15 '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
16 '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
17 '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
18 ), 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
19
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
20 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
21
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
22 header = TRUE
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
23 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
24
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
25 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
26
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
27 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
28 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
29 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
30 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
31
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
32 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
33 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
34 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
35 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
36 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
37
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
38 xlab = ""
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
39 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
40
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
41 col = "grey"
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
42 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
43
1
7e3103db022d planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 5653f2982dc5aeccd7701970fdfea444e3e53e3c-dirty
bebatut
parents: 0
diff changeset
44 log = ""
7e3103db022d planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 5653f2982dc5aeccd7701970fdfea444e3e53e3c-dirty
bebatut
parents: 0
diff changeset
45 if(!is.null(options$log) && options$log) log = "x"
7e3103db022d planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 5653f2982dc5aeccd7701970fdfea444e3e53e3c-dirty
bebatut
parents: 0
diff changeset
46
0
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
47 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
48 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
49 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
50 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
51 names.arg = data[, names_column], col = col, cex.names=0.7,
1
7e3103db022d planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 5653f2982dc5aeccd7701970fdfea444e3e53e3c-dirty
bebatut
parents: 0
diff changeset
52 cex.axis = 0.8, log = log)
0
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
53 }
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
54
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
55 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
56 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
57 plot_barplot()
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
58 dev.off()
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
59 }
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
60
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
61 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
62 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
63 plot_barplot()
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
64 dev.off()
a8e03ffaaedc planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_barplot commit 74beefba9d138c892208b103b52e706ab4313a4a-dirty
bebatut
parents:
diff changeset
65 }