Mercurial > repos > bebatut > plot_barplot
comparison 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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a8e03ffaaedc |
|---|---|
| 1 library('getopt') | |
| 2 | |
| 3 option_specification = matrix(c( | |
| 4 'input_file', 'i', 2, 'character', | |
| 5 'output_pdf_file', 'p', 2, 'character', | |
| 6 'output_png_file', 'o', 2, 'character', | |
| 7 'output_svg_file', 's', 2, 'character', | |
| 8 'data_column', 'd', 2, 'integer', | |
| 9 'names_column', 'n', 2, 'integer', | |
| 10 'xlab', 'x', 2, 'character', | |
| 11 'col', 'c', 2, 'character', | |
| 12 'bottom_margin', 'b', 2, 'integer', | |
| 13 'left_margin', 'l', 2, 'integer', | |
| 14 'top_margin', 't', 2, 'integer', | |
| 15 'right_margin', 'r', 2, 'integer', | |
| 16 'header','y',2,'logical' | |
| 17 ), byrow=TRUE, ncol=4); | |
| 18 | |
| 19 options = getopt(option_specification); | |
| 20 | |
| 21 header = TRUE | |
| 22 if(!is.null(options$header)) header = options$header | |
| 23 | |
| 24 data = read.table(options$input_file, sep = '\t', h = header) | |
| 25 | |
| 26 data_column = 2 | |
| 27 if(!is.null(options$data_column)) data_column = options$data_column | |
| 28 names_column = 1 | |
| 29 if(!is.null(options$names_column)) names_column = options$names_column | |
| 30 | |
| 31 margin = c(5,19,1,1) | |
| 32 if(!is.null(options$bottom_margin)) margin[1] = options$bottom_margin | |
| 33 if(!is.null(options$left_margin)) margin[2] = options$left_margin | |
| 34 if(!is.null(options$top_margin)) margin[3] = options$top_margin | |
| 35 if(!is.null(options$right_margin)) margin[4] = options$right_margin | |
| 36 | |
| 37 xlab = "" | |
| 38 if(!is.null(options$xlab)) xlab = options$xlab | |
| 39 | |
| 40 col = "grey" | |
| 41 if(!is.null(options$col)) col = options$col | |
| 42 | |
| 43 plot_barplot <- function(){ | |
| 44 par(las=2) | |
| 45 par(mar=margin) | |
| 46 barplot(data[, data_column], horiz = T, xlab = xlab, | |
| 47 names.arg = data[, names_column], col = col, cex.names=0.7, | |
| 48 cex.axis = 0.8) | |
| 49 } | |
| 50 | |
| 51 if(!is.null(options$output_pdf_file)){ | |
| 52 pdf(options$output_pdf_file) | |
| 53 plot_barplot() | |
| 54 dev.off() | |
| 55 } | |
| 56 | |
| 57 if(!is.null(options$output_svg_file)){ | |
| 58 svg(options$output_svg_file) | |
| 59 plot_barplot() | |
| 60 dev.off() | |
| 61 } |
