forked from splaisan/venn-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4DVenn.R
executable file
·144 lines (128 loc) · 5.34 KB
/
4DVenn.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/RScript
# plots a 4D VENN from precomputed data
# usage: 4Dvenn.R -a .. to .. -u (see below)
# counts are expected in the order
# "0100","0010","0110",1100",
# "0011","1000","1110","0111",
# "0001","1111","1010","0101",
# "1001"
# the order is arbitrary, from top to bottom and from left to right
# extra arguments: A-label B-label C-label D-label Title (opt)
# example command:
# 4DVenn.R -a 1 -b 2 -c 3 -d 4 -e 5 -f 6 -G 7 -i 8 -j 9
# -k 10 -l 11 -m 12 -n 13 -p 14 -q 15
# -A "grA" -B "grB" -C "grC" -D "grD" -t "4way-Venn"
# -o "my_4wayVenn" -u 1 -x 1
#
# Stephane Plaisance VIB-BITS April-11-2014 v1.0
# required R-packages
# once only install.packages("grid")
# once only install.packages("optparse")
# once only install.packages("colorfulVennPlot")
suppressPackageStartupMessages(library("optparse"))
suppressPackageStartupMessages(library("grid"))
suppressPackageStartupMessages(library("colorfulVennPlot"))
#####################################
### Handle COMMAND LINE arguments ###
#####################################
# parameters
option_list <- list(
make_option(c("-a", "--a.count"), type="integer", default=0,
help="counts for A-only [default: %default]"),
make_option(c("-b", "--b.count"), type="integer", default=0,
help="counts for B-only [default: %default]"),
make_option(c("-c", "--c.count"), type="integer", default=0,
help="counts for C-only [default: %default]"),
make_option(c("-d", "--d.count"), type="integer", default=0,
help="counts for D-only [default: %default]"),
make_option(c("-e", "--ab.count"), type="integer", default=0,
help="counts for AB-intersect [default: %default]"),
make_option(c("-f", "--ac.count"), type="integer", default=0,
help="counts for ACB-intersect [default: %default]"),
make_option(c("-G", "--ad.count"), type="integer", default=0,
help="counts for AD-intersect (! use G and not g, due to a bug in RScript) [default: %default]"),
make_option(c("-j", "--bc.count"), type="integer", default=0,
help="counts for BC-intersect [default: %default]"),
make_option(c("-k", "--bd.count"), type="integer", default=0,
help="counts for BD-intersect [default: %default]"),
make_option(c("-l", "--cd.count"), type="integer", default=0,
help="counts for CD-intersect [default: %default]"),
make_option(c("-m", "--abc.count"), type="integer", default=0,
help="counts for ABC-intersect [default: %default]"),
make_option(c("-n", "--abd.count"), type="integer", default=0,
help="counts for ABD-intersect [default: %default]"),
make_option(c("-p", "--acd.count"), type="integer", default=0,
help="counts for ACD-intersect [default: %default]"),
make_option(c("-q", "--bcd.count"), type="integer", default=0,
help="counts for BCD-intersect [default: %default]"),
make_option(c("-i", "--abcd.count"), type="integer", default=0,
help="counts for ABCD-intersect [default: %default]"),
make_option(c("-A", "--a.label"), type="character", default="A",
help="label for A [default: %default]"),
make_option(c("-B", "--b.label"), type="character", default="B",
help="label for B [default: %default]"),
make_option(c("-C", "--c.label"), type="character", default="C",
help="label for C [default: %default]"),
make_option(c("-D", "--d.label"), type="character", default="D",
help="label for D [default: %default]"),
make_option(c("-t", "--title"), type="character",
help="Graph Title [default: null]"),
make_option(c("-x", "--format"), type="integer", default=1,
help="file format for output 1:PNG, 2:PDF [default: %default]"),
make_option(c("-o", "--file"), type="character", default="4Dvenn",
help="file name for output [default: %default]"),
make_option(c("-u", "--fill"), type="character", default="3",
help="fill with 1:colors, 2:greys or 3:white [default: %default]")
)
# PARSE OPTIONS
opt <- parse_args(OptionParser(option_list=option_list))
# check if arguments provided
if (length(opt) > 1) {
# data
y=c(opt$b.count, opt$c.count,
opt$bc.count,
opt$ab.count, opt$cd.count,
opt$a.count, opt$abc.count, opt$bcd.count, opt$d.count,
opt$abcd.count,
opt$ac.count, opt$bd.count,
opt$acd.count, opt$abd.count,
opt$ad.count)
names(y) <- c("0100","0010",
"0110",
"1100","0011",
"1000","1110","0111","0001",
"1111",
"1010","0101",
"1011","1101",
"1001")
# labels
labels <- c(opt$a.label, opt$b.label, opt$c.label, opt$d.label)
# colors (15)
ncol <- 15
my.colors <- rainbow(ncol)
my.greys <- rev(gray(0:32 / 32))[1:ncol]
my.whites <- rep("#FFFFFF", ncol)
my.fill <- ifelse( rep(opt$fill=="1", ncol),
my.colors,
(ifelse(rep(opt$fill=="2",ncol), my.greys, my.whites))
)
# title
my.title <- ifelse(!is.null(opt$title), opt$title, "")
# format
if (opt$format==1){
# png
filename <- paste(opt$file, ".png", sep="")
png(file = filename, bg = "transparent")
} else {
# pdf
filename <- paste(opt$file, ".pdf", sep="")
pdf(file = filename, bg = "white")
}
# plot
plot.new()
plotVenn4d(y,
labels,
Colors = my.fill,
Title = my.title)
dev.off()
}