annotate vennerable/Vennerable.R @ 1:2d8c23e32839 default tip

2015-04-21 fixed <NA> values bug
author eric
date Wed, 22 Apr 2015 10:35:33 +0200
parents f21d51d28d8d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
1 #!/usr/bin/R
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
2
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
3 # R script to call Vennerable package from galaxy
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
4 # info: alex.bossers@wur.nl
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
5 #
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
6 # version:
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
7 # 2015-04-21 fixed <NA> values bug
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
8 # .......... Initial version
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
9 #
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
10
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
11 # R --slave --vanilla --file=PlotBar.R --args inputFile x_data weighting outputFile plottype resolution imagetype
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
12 # 1 2 3 4 5 6 7 8 9 10 11 12
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
13
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
14 #get cmd line args
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
15 args <- commandArgs()
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
16 in.file <- args[6]
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
17 xData <- args[7] # data labels xData of format "a, b, c" and can include spaces
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
18 weighting <- args[8]
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
19 out.file <- args[9]
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
20 plottype <- args[10]
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
21 resolution <- args[11] # in dpi
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
22 imagetype <- args[12] # svg, pdf or png
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
23
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
24 #open lib
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
25 library(Vennerable)
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
26 options(bitmapType='cairo')
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
27
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
28 # for labels of bars or bar groups presume column names from data
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
29 if (xData != "default") {
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
30 # read without header input file (must be tabular)
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
31 a_data <- read.delim(in.file, header=F, na.strings="") # replace empty by <NA> for TAB delimited file
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
32 colnames (a_data) <- strsplit(xData,",")[[1]] # insert headers from galaxy input
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
33 annot_data <- lapply(a_data, na.omit) # remove empty values for counting
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
34 Vannot <- Venn(annot_data)
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
35 } else {
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
36 # read with header input file (must be tabular)
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
37 a_data <- read.delim(in.file, na.strings="") # replace any empty values by <NA> for AB delimited headered file
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
38 annot_data <- lapply(a_data, na.omit) # remove empty values for counting
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
39 Vannot <- Venn(annot_data)
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
40 }
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
41
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
42 #set output imagetype (svg pdf or png)
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
43 #R 3.0.2 and default cairo libs should handle it all ok
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
44 #it could be that X11 should be loaded for non-pdf
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
45 if (imagetype == "svg") {
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
46 svg(out.file)
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
47 } else if (imagetype == "png") {
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
48 png(out.file, width = 1600, height = 1600, res = resolution)
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
49 } else {
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
50 pdf(out.file)
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
51 }
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
52
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
53 # plot it
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
54 if (plottype == "ChowRuskey") {
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
55 plot(Vannot, type = plottype)
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
56
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
57 } else if (plottype == "AWFE") {
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
58 plot(Vannot, doWeights = weighting, type = plottype)
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
59
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
60 } else if (plottype == "circles") {
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
61 plot(Vannot)
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
62
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
63 } else if (plottype == "ellipses"){
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
64 plot(Vannot, type = "ellipses")
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
65
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
66 } else if (plottype == "squares"){
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
67 plot(Vannot, type = "squares")
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
68
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
69 } else if (plottype == "battle"){
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
70 plot(Vannot, type = "battle")
0
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
71 }
f21d51d28d8d initial commit on Vennerable on toolshed
eric
parents:
diff changeset
72
1
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
73 cat ("Wrapper version 1.2c (empty value bug fixed), running Vennerable v3.0-82\n Info/bugs: alex.bossers@wur.nl\n")
2d8c23e32839 2015-04-21 fixed <NA> values bug
eric
parents: 0
diff changeset
74 dev.off()