|
1
|
1 # Setup R error handling to go to stderr
|
|
|
2 options(show.error.messages=F, error=function(){cat(geterrmessage(),file=stderr());q("no",1,F)})
|
|
|
3
|
|
|
4 # We need to not crash galaxy with an UTF8 error on German LC settings.
|
|
|
5 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
|
|
|
6
|
|
|
7
|
|
|
8 # Import library
|
|
|
9 library("getopt")
|
|
|
10 library("reshape2")
|
|
|
11 library("ggplot2")
|
|
|
12 options(stringAsfactors = FALSE, useFancyQuotes = FALSE)
|
|
|
13 # Take in trailing command line arguments
|
|
|
14 args <- commandArgs(trailingOnly = TRUE)
|
|
|
15
|
|
|
16
|
|
|
17 # get options, using the spec as defined by the enclosed list.
|
|
|
18 # we read the options from the default: commandArgs(TRUE).
|
|
|
19 option_specification = matrix(c(
|
|
|
20 'input', 'i', 2, 'character',
|
|
|
21 'title', 't',2, 'character',
|
|
|
22 'size', 's', 2, 'double',
|
|
|
23 'xlab', 'x', 2, 'character',
|
|
|
24 'ylab', 'y', 2, 'character',
|
|
|
25 'binwidth', 'b', 2, 'double',
|
|
|
26 'xaxismin', 'e', 2, 'integer',
|
|
|
27 'xaxismax', 'f', 2, 'integer',
|
|
|
28 'yaxismin', 'g', 2, 'integer',
|
|
|
29 'yaxismax', 'h', 2, 'integer',
|
|
|
30 'colors', 'q', 2, 'character',
|
|
|
31 'colorscheme', 'z', 2, 'character',
|
|
|
32 'colororder', 'r', 2, 'integer',
|
|
|
33 'facet', 'a', 2, 'character',
|
|
|
34 'transform', 'c', 2, 'character',
|
|
|
35 'woutputdim', 'w', 2, 'integer',
|
|
|
36 'houtputdim', 'd', 2, 'integer',
|
|
|
37 'dim', 'k', 2, 'character',
|
|
|
38 'scaling', 'j', 2, 'character',
|
|
5
|
39 'legend', 'l', 2, 'character',
|
|
1
|
40 'output', 'o', 2, 'character'
|
|
|
41 ), byrow=TRUE, ncol=4);
|
|
|
42
|
|
|
43 # Parse options
|
|
|
44 options = getopt(option_specification);
|
|
|
45
|
|
|
46
|
|
|
47
|
|
|
48 # Print options to see what is going on
|
|
|
49 cat("\n input: ",options$input)
|
|
|
50 cat("\n title: ",options$title)
|
|
|
51 cat("\n size: ",options$size)
|
|
|
52 cat("\n transform: ",options$alpha)
|
|
|
53 cat("\n xlab: ",options$xlab)
|
|
|
54 cat("\n xlab: ",options$xlab)
|
|
|
55 cat("\n binwidth: ",options$binwidth)
|
|
|
56 cat("\n output: ",options$output)
|
|
|
57
|
|
|
58 integrated <- read.csv(options$input,sep='\t',header=TRUE)
|
|
|
59 input <- melt(integrated)
|
|
|
60
|
|
9
|
61 #Show/hide legend
|
|
|
62 if(options$legend == "TRUE"){
|
|
|
63 gg_legend = NULL
|
|
|
64 } else {options$legend == "FALSE"
|
|
|
65 gg_legend = theme(legend.position="none")
|
|
|
66 }
|
|
1
|
67
|
|
|
68 #Choose between automatically scaled x and y axis or user defined
|
|
|
69 if(options$scaling == "Automatic"){
|
|
|
70 gg_scalex = NULL
|
|
|
71 gg_scaley = NULL
|
|
|
72 } else {
|
|
|
73 gg_scalex = xlim(options$xaxismin,options$xaxismax)
|
|
|
74 gg_scaley = ylim(options$yaxismin,options$yaxismax)
|
|
|
75 cat("\n xaxismin: ",options$xaxismin)
|
|
|
76 cat("\n xaxismax: ",options$xaxismax)
|
|
|
77 cat("\n yaxismin: ",options$yaxismin)
|
|
|
78 cat("\n yaxismax: ",options$yaxismax)
|
|
|
79 }
|
|
|
80
|
|
|
81 #Choose dimensions of output pdf
|
|
|
82 if(options$dim == "Default"){
|
|
|
83 gg_width = 7
|
|
|
84 gg_height = 7
|
|
|
85 } else {
|
|
|
86 gg_width = options$woutputdim
|
|
|
87 gg_height = options$houtputdim
|
|
|
88 }
|
|
|
89
|
|
|
90
|
|
|
91 if(options$transform == "log2"){
|
|
|
92 input["value"] <- log2(input["value"])
|
|
|
93 }else if(options$transform == "log2plus1"){
|
|
|
94 input["value"] <- log2(input["value"]+1)
|
|
|
95 }else if(options$transform == "log10"){
|
|
|
96 input["value"] <- log10(input["value"])
|
|
|
97 }else if(options$transform == "log10plus1"){
|
|
|
98 input["value"] <- log10(input["value"]+1)
|
|
|
99 }else{
|
|
|
100 }
|
|
|
101
|
|
|
102
|
|
|
103 if(options$facet == "facet"){
|
|
|
104 gg_facet = facet_wrap(~ variable)
|
|
|
105 } else {
|
|
|
106 gg_facet = NULL
|
|
|
107 }
|
|
|
108
|
|
|
109 if(options$colorscheme == "Default"){
|
|
|
110 gg_colorscale = NULL
|
|
|
111 } else {
|
|
|
112 gg_colorscale = scale_color_brewer(palette=options$colors, direction=options$colororder)
|
|
|
113 }
|
|
|
114
|
|
|
115 ggplot(input,aes(value,color=variable)) +
|
|
|
116 geom_freqpoly(binwidth=options$binwidth,size=options$size)+gg_facet+gg_colorscale+
|
|
5
|
117 gg_scalex+gg_scaley+theme_bw()+xlab(options$xlab)+ylab(options$ylab)+gg_legend+
|
|
1
|
118 ggtitle(options$title)
|
|
|
119
|
|
|
120 ggsave(file=options$output)
|