comparison ggplotscriptviolin.R @ 1:c7db13bd4c85 draft

Uploaded
author moheydarian
date Wed, 22 Feb 2017 22:36:41 -0500
parents
children
comparison
equal deleted inserted replaced
0:74f4588a15e6 1:c7db13bd4c85
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 'ggfill', 's', 2, 'character',
23 'ggcolor', 'z', 2, 'character',
24 'xlab', 'x', 2, 'character',
25 'ylab', 'y', 2, 'character',
26 'drawquartiles', 'a', 2, 'character',
27 'transform', 'w', 2, 'character',
28 'xaxismin', 'e', 2, 'integer',
29 'xaxismax', 'f', 2, 'integer',
30 'yaxismin', 'g', 2, 'integer',
31 'yaxismax', 'h', 2, 'integer',
32 'scaling', 'b', 2, 'character',
33 'output', 'o', 2, 'character'
34 ), byrow=TRUE, ncol=4);
35
36 # Parse options
37 options = getopt(option_specification);
38
39
40
41 # Print options to see what is going on
42 cat("\n input: ",options$input)
43 cat("\n title: ",options$title)
44 #cat("\n size: ",options$size)
45 cat("\n xlab: ",options$xlab)
46 cat("\n ylab: ",options$ylab)
47 cat("\n output: ",options$output)
48
49
50 if(options$scaling == "Automatic"){
51 gg_scaley = NULL
52 } else {
53 gg_scaley = ylim(options$yaxismin,options$yaxismax)
54 cat("\n yaxismin: ",options$yaxismin)
55 cat("\n yaxismax: ",options$yaxismax)
56 }
57
58
59 integrated <- read.csv(options$input,sep='\t',header=TRUE)
60 input <- melt(integrated)
61
62
63
64 if(options$transform == "log2"){
65 input["value"] <- log2(input["value"])
66 }else if(options$transform == "log2plus1"){
67 input["value"] <- log2(input["value"]+1)
68 }else if(options$transform == "log10"){
69 input["value"] <- log10(input["value"])
70 }else if(options$transform == "log10plus1"){
71 input["value"] <- log10(input["value"]+1)
72 }else{
73 }
74
75 if(options$drawquartiles == "none"){
76 gg_quartile = NULL
77 } else {
78 gg_quartile = c(0.25, 0.5, 0.75)
79 }
80
81
82
83 ggplot(input,aes(variable,value)) +geom_violin(scale = "area", colour = options$ggcolor, fill = options$ggfill, draw_quantiles = gg_quartile) +
84 gg_scaley+theme_bw()+xlab(options$xlab)+ylab(options$ylab)+ggtitle(options$title)
85
86 ggsave(file=options$output)