Mercurial > repos > bebatut > plot_generic_x_y_plot
comparison plot_generic_x_y_plot.R @ 0:5118d839acae draft default tip
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/plot_generic_x_y_plot commit e4da8b5a999456b2b6dabdf6b8f3bfea1eba5504-dirty
author | bebatut |
---|---|
date | Mon, 18 Apr 2016 11:11:02 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5118d839acae |
---|---|
1 library('getopt') | |
2 | |
3 option_specification = matrix(c( | |
4 'input_file', 'a', 2, 'character', | |
5 'output_pdf_file', 'b', 2, 'character', | |
6 'output_png_file', 'c', 2, 'character', | |
7 'output_svg_file', 'd', 2, 'character', | |
8 'x_column_id', 'e', 2, 'integer', | |
9 'y_column_id', 'f', 2, 'integer', | |
10 'xlog', 'g', 2, 'logical', | |
11 'ylog', 'h', 2, 'logical', | |
12 'xlab', 'i', 2, 'character', | |
13 'ylab', 'j', 2, 'character', | |
14 'col', 'k', 2, 'character', | |
15 'pch', 'l', 2, 'integer', | |
16 'lim', 'm', 2, 'logical', | |
17 'abline', 'n', 2, 'logical', | |
18 'bottom_margin', 'o', 2, 'integer', | |
19 'left_margin', 'p', 2, 'integer', | |
20 'top_margin', 'q', 2, 'integer', | |
21 'right_margin', 'r', 2, 'integer', | |
22 'header','s',2,'logical' | |
23 ), byrow=TRUE, ncol=4); | |
24 | |
25 options = getopt(option_specification); | |
26 | |
27 header = TRUE | |
28 if(!is.null(options$header)) header = options$header | |
29 | |
30 data = read.table(options$input_file, sep = '\t', h = header) | |
31 | |
32 x_column_id = 2 | |
33 if(!is.null(options$x_column_id)) x_column_id = options$x_column_id | |
34 x_axis = data[,x_column_id] | |
35 | |
36 y_column_id = 3 | |
37 if(!is.null(options$y_column_id)) y_column_id = options$y_column_id | |
38 y_axis = data[,y_column_id] | |
39 | |
40 xlim = c(min(x_axis),max(x_axis)) | |
41 ylim = c(min(y_axis),max(y_axis)) | |
42 if(!is.null(options$lim) && options$lim){ | |
43 xlim = c(min(xlim,ylim), max(xlim,ylim)) | |
44 ylim = xlim | |
45 } | |
46 | |
47 | |
48 xlab = "" | |
49 if(!is.null(options$xlab)) xlab = options$xlab | |
50 ylab = "" | |
51 if(!is.null(options$ylab)) ylab = options$ylab | |
52 | |
53 col = 'grey25' | |
54 if(!is.null(options$col)) col = options$col | |
55 | |
56 pch = 21 | |
57 if(!is.null(options$pch)) pch = options$pch | |
58 | |
59 log = "" | |
60 if(!is.null(options$xlog) && options$xlog) log = paste(log,"x",sep = '') | |
61 if(!is.null(options$ylog) && options$ylog) log = paste(log,"y",sep = '') | |
62 | |
63 margin = c(5,5,1,1) | |
64 if(!is.null(options$bottom_margin)) margin[1] = options$bottom_margin | |
65 if(!is.null(options$left_margin)) margin[2] = options$left_margin | |
66 if(!is.null(options$top_margin)) margin[3] = options$top_margin | |
67 if(!is.null(options$right_margin)) margin[4] = options$right_margin | |
68 | |
69 plot_generic_x_y_plot <- function(){ | |
70 par(mar=margin) | |
71 plot(x_axis, y_axis, xlab = xlab, ylab = ylab, | |
72 col = col, log = log, xlim = xlim, ylim = ylim, pch = pch) | |
73 if(!is.null(options$abline) && options$abline) abline(a = 0, b = 1, col = 'grey50') | |
74 } | |
75 | |
76 if(!is.null(options$output_pdf_file)){ | |
77 pdf(options$output_pdf_file) | |
78 plot_generic_x_y_plot() | |
79 dev.off() | |
80 } | |
81 | |
82 if(!is.null(options$output_svg_file)){ | |
83 svg(options$output_svg_file) | |
84 plot_generic_x_y_plot() | |
85 dev.off() | |
86 } |