-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark.R
118 lines (92 loc) · 3.58 KB
/
benchmark.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
library(bench)
library(ggplot2)
library(ggfastman)
bench_plot <- function(x){
trash_dir <- tempfile()
dir.create(trash_dir, recursive = TRUE)
on.exit(unlink(trash_dir, recursive = TRUE))
slow_plot <- function() {
p <- fast_manhattan(x, build = "hg18", speed = "slow")
ggsave(tempfile(tmpdir = trash_dir, fileext =".png"), width = 270, height = 100, units = "mm", dpi = 300, plot = p)
NULL
}
fast_plot <- function() {
p <- fast_manhattan(x, build = "hg18", speed = "fast")
ggsave(tempfile(tmpdir = trash_dir, fileext =".png"), width = 270, height = 100, units = "mm", dpi = 300, plot = p)
NULL
}
ultrafast_plot <- function() {
p <- fast_manhattan(x, build = "hg18", speed = "ultrafast")
ggsave(tempfile(tmpdir = trash_dir, fileext =".png"), width = 270, height = 100, units = "mm", dpi = 300, plot = p)
NULL
}
fastman_plot <- function(){
png(tempfile(tmpdir = trash_dir, fileext =".png"), width = 270, height = 100, res=300, units = "mm")
fastman::fastman(x, chr = "chrom", ps = "pos", p = "pvalue")
dev.off()
NULL
}
qqman_plot <- function(){
png(tempfile(tmpdir = trash_dir, fileext =".png"), width = 270, height = 100, res=300, units = "mm")
qqman::manhattan(x, chr = "chrom", bp = "pos", p = "pvalue", snp="rsid")
dev.off()
NULL
}
bench::mark(`ggfastman: slow` = slow_plot(),
`ggfastman: fast` = fast_plot(),
`ggfastman: ultrafast` = ultrafast_plot(),
`fastman: fastman` = fastman_plot(),
`qqman: manhattan` = qqman_plot(),
min_iterations = 2)
}
bench_qqplot <- function(x,y){
trash_dir <- tempfile()
dir.create(trash_dir, recursive = TRUE)
on.exit(unlink(trash_dir, recursive = TRUE))
slow_plot <- function() {
p <- fast_qq(y, speed = "slow")
ggsave(tempfile(tmpdir = trash_dir, fileext =".png"), width = 100, height = 100, units = "mm", dpi = 300, plot = p)
NULL
}
fast_plot <- function() {
p <- fast_qq(y, speed = "fast")
ggsave(tempfile(tmpdir = trash_dir, fileext =".png"), width = 100, height = 100, units = "mm", dpi = 300, plot = p)
NULL
}
ultrafast_plot <- function() {
p <- fast_qq(y, speed = "ultrafast")
ggsave(tempfile(tmpdir = trash_dir, fileext =".png"), width = 100, height = 100, units = "mm", dpi = 300, plot = p)
NULL
}
fastman_plot <- function(){
png(tempfile(tmpdir = trash_dir, fileext =".png"), width = 100, height = 100, res=300, units = "mm")
fastman::fastqq(x, p = "pvalue")
dev.off()
NULL
}
qqman_plot <- function(){
png(tempfile(tmpdir = trash_dir, fileext =".png"), width = 270, height = 100, res=300, units = "mm")
qqman::qq(y)
dev.off()
NULL
}
bench::mark(
`ggfastman: slow` = slow_plot(),
`ggfastman: fast` = fast_plot(),
`ggfastman: ultrafast` = ultrafast_plot(),
`fastman: fastman` = fastman_plot(),
`qqman: manhattan` = qqman_plot(),
min_iterations = 2)
}
plot_bench <- function(x, funcs = c("ggfastman: slow",
"ggfastman: fast",
"ggfastman: ultrafast",
"fastman: fastman",
"qqman: manhattan")){
require(ggsignif)
p <- plot(x)
p + scale_x_discrete("", limits = rev(funcs)) +
ggsignif::geom_signif(comparisons = combn(funcs, 2, simplify = F), map_signif_level = T, step_increase = 0.2, color=1) +
theme_bw(base_size = 16) +
theme(legend.position = "bottom")
}