-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplot_benchmark_results.Rmd
More file actions
349 lines (286 loc) · 10.4 KB
/
plot_benchmark_results.Rmd
File metadata and controls
349 lines (286 loc) · 10.4 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
---
title: "pyranges benchmark"
output: html_document
date: "2025-04-24"
---
# Plots for pyranges v1 paper 2025
Import libraries
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(data.table)
library(ggplot2)
library(cowplot)
library(scales)
library(ggsci)
```
Load data
```{r }
df1 = data.table(read.csv('collected_results.w_status.20.7.25.csv'))
df2 = data.table(read.csv('collected_results.w_status.23.7.25.csv'))
df3 = data.table(read.csv('collected_results.w_status.24.7.25.csv'))
df1$replicate = 1
df2$replicate = 2
df3$replicate = 3
df=rbind(df1, df2, df3)
df$nrows <- as.integer(gsub("_", "", df$nrows))
# levels in reverse alphabetical: pyranges first, and bedtools last, so colors are consistent if bedtools is removed
df$library=factor(df$library, levels=sort(unique(df$library), decreasing=T) )
# renaming, ordering levels
df[genome=="hg38", genome:="genome"]
df[operation=="intersection", operation:="overlap"]
ops <- unique(df$operation)
df$operation <- factor(df$operation,
levels = c("overlap", sort(ops[ops != "overlap"])))
# useful vars
libs <- as.character(unique(df$library))
libs_other <- setdiff(libs, "pyranges") # all competitors
df
```
Do mean across the three replicates
```{r}
## -------------------------------------------------------------
## 1. Identify the columns you *don’t* want in the “design” key
## -------------------------------------------------------------
avg_cols <- c(
"s", "max_pss", "max_rss", "max_uss", "max_vms", "mean_load",
"cpu_time", "cpu_usage", "io_in", "io_out"
)
drop_cols <- c("replicate", "jobid", "h.m.s") # never part of the key
dt=copy(df)
dt[, (drop_cols) := NULL]
key_cols <- setdiff(names(dt), c(avg_cols, drop_cols))
## -------------------------------------------------------------
## 2. Collapse replicates
## -------------------------------------------------------------
mdf <- dt[
,
lapply(.SD, mean),
by = key_cols,
.SDcols = avg_cols
]
setcolorder(mdf, setdiff(names(dt), drop_cols)) # original order, minus drop_cols
#coll
mdf = mdf[order(nrows, library, maxlength, operation, genome)]
mdf
```
Wide tables: time_* and mem_*. Excluding failed jobs
```{r}
z=mdf[status=="ok"]
time_wide <- dcast(
z,
operation + genome + nrows + maxlength ~ library,
value.var = "cpu_time",
fun.aggregate = mean
)
#time_wide
setnames(time_wide, libs, paste0("time_", libs))
mem_wide <- dcast(
z ,
operation + genome + nrows + maxlength ~ library,
value.var = "max_rss",
fun.aggregate = mean
)
setnames(mem_wide, libs, paste0("mem_", libs))
cond_cols = setdiff(names(mem_wide), paste0("mem_", libs))
#cond_cols
## Combined table: one row per condition
bench_wide <- merge(time_wide, mem_wide, by = cond_cols, all = TRUE)
time_cols <- grep("^time_", names(bench_wide), value = TRUE)
mem_cols <- grep("^mem_", names(bench_wide), value = TRUE)
pyr_time_col <- "time_pyranges"
pyr_mem_col <- "mem_pyranges"
time_other <- setdiff(time_cols, pyr_time_col)
mem_other <- setdiff(mem_cols, pyr_mem_col)
# helper that returns a list(best_value, best_library) over .SD
best_other <- function(mat, strip) {
idx <- apply(mat, 1, function(x) if (all(is.na(x))) NA_integer_ else which.min(x))
best_val <- mat[cbind(seq_len(nrow(mat)), idx)]
best_lib <- gsub(strip, "", colnames(mat)[idx])
list(best_val, best_lib)
}
# ────────────────────────────────────────────────────────────────
# Per-library fold-change vs. PyRanges
# (>1 ⇒ PyRanges faster / leaner than that library)
# ────────────────────────────────────────────────────────────────
# Time fold-changes
for (lib in libs_other) {
bench_wide[, (paste0("fold_change_time_", lib)) :=
get(paste0("time_", lib)) / get(pyr_time_col)]
}
# Memory fold-changes
for (lib in libs_other) {
bench_wide[, (paste0("fold_change_mem_", lib)) :=
get(paste0("mem_", lib)) / get(pyr_mem_col)]
}
bench_wide
```
Calculating mean performances for big datasets, 10^6 or more rows
```{r}
row_subset <- bench_wide[nrows >= 1e6] #note: bench_wide has already excluded fail status jobs
# [,.( mFCtime= mean(fold_change_time), deltaMem = mean(delta_pct_mem, na.rm=T) )]
mean_fc <- function(prefix) {
sapply(
libs_other,
function(lib)
mean(row_subset[[paste0(prefix, lib)]], na.rm = TRUE)
)
}
# ----- compute averages -----------------------------------------------------
avg_time <- mean_fc("fold_change_time_") # speed-up averages
avg_mem <- mean_fc("fold_change_mem_") # RAM-ratio averages
# ----- assemble tidy summary -----------------------------------------------
avg_fold_changes <- data.table(
library = libs_other,
avg_fold_change_time = avg_time,
avg_fold_change_mem = avg_mem
)
avg_fold_changes [, delta_mem:=(1-1/avg_fold_change_mem)]
print(avg_fold_changes)
```
Concise plot: only maxlength==100
```{r fig.height=7, fig.width=6}
sdf=mdf[maxlength==100][status=='ok']
point_alpha=0.7
named_color_scale = ggsci::pal_npg()(4)
names(named_color_scale) = levels(sdf$library)
color_scale = scale_color_manual(values=named_color_scale)
time_plot_combined <- ggplot(sdf, aes(nrows, cpu_time, color = library)) +
geom_line(alpha=point_alpha) +
geom_point(alpha=point_alpha) +
facet_grid(genome ~ operation, scales = 'free') +
scale_x_log10(
labels = trans_format("log10", math_format(10^.x))
) +
color_scale+
scale_y_log10(labels = label_number()) +
scale_shape_manual(values=c(8, 19))+
xlab('Number of intervals') +
ylab('Running time (sec)') +
theme_bw() +
theme(
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
plot.title = element_text(hjust = 0.5),
# Legend styling
legend.position = "top",
legend.background = element_rect(fill = "white", color = "black"),
# Facet strip styling
strip.background = element_rect(fill = "lightgrey", color = NA),
strip.text = element_text(face = "bold")
)
mem_plot_combined <- ggplot(sdf, aes(nrows, max_rss/1024, color = library)) +
geom_line(alpha=point_alpha) +
geom_point(alpha=point_alpha) +
facet_grid(genome ~ operation, scales = 'free') +
scale_x_log10(labels = trans_format("log10", math_format(10^.x)) ) +
scale_y_log10() +
color_scale+
xlab('Number of intervals') +
ylab('Maximum memory used (GB)') +
theme_bw() +
theme(
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
plot.title = element_text(hjust = 0.5),
# Legend styling
legend.position = "top",
legend.background = element_rect(fill = "white", color = "black"),
# Facet strip styling
strip.background = element_rect(fill = "lightgrey", color = NA),
strip.text = element_text(face = "bold")
)
combo_plot =
plot_grid(get_legend(time_plot_combined),
time_plot_combined + theme(legend.position = 'none') + xlab(''),
mem_plot_combined + theme(legend.position = 'none'),
ncol=1,
rel_heights = c(0.2, 1, 1),
labels = c('', 'a', 'b')
)
combo_plot
suppressMessages(ggsave('combo_plot.pdf', combo_plot, width = 6))
suppressMessages(ggsave('combo_plot.png', combo_plot, width = 6))
#time_plot_combined
```
Full plots, including failed jobs and all maxlength
```{r fig.height=15, fig.width=10}
addx=0.93
addy=0.98
addtext="MaxLength"
supp_time_plot_combined <- ggplot(mdf, aes(nrows, cpu_time, color = library)) +
geom_line(alpha=point_alpha) +
geom_point(aes(shape=status), alpha=point_alpha) +
facet_grid(genome + maxlength ~ operation , scales = 'free') +
scale_x_log10(
labels = trans_format("log10", math_format(10^.x))
) +
color_scale+
scale_y_log10(labels = label_number()) +
scale_shape_manual(values=c(8, 19))+
xlab('Number of intervals') +
ylab('Running time (sec)') +
theme_bw() +
theme(
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
plot.title = element_text(hjust = 0.5),
# Legend styling
legend.position = "top",
legend.background = element_rect(fill = "white", color = "black"),
# Facet strip styling
strip.background = element_rect(fill = "lightgrey", color = NA),
strip.text = element_text(face = "bold"),
strip.text.y = element_text(face = "bold", angle = 0)
)
the_legend = get_legend(supp_time_plot_combined)
supp_time_plot_combined = supp_time_plot_combined + theme(legend.position = 'none') + xlab('')
supp_time_plot_combined <- ggdraw(supp_time_plot_combined) +
draw_label(
addtext,
x = addx, # near right edge
y = addy, # near top edge
hjust = 1, vjust = 1,
fontface = "bold",
size=9
)
supp_mem_plot_combined <- ggplot(mdf, aes(nrows, max_rss/1024, color = library)) +
geom_line(alpha=point_alpha) +
geom_point(aes(shape=status), alpha=point_alpha) +
facet_grid(genome + maxlength ~ operation, scales = 'free') +
scale_x_log10(labels = trans_format("log10", math_format(10^.x)) ) +
scale_y_log10() +
color_scale+
scale_shape_manual(values=c(8, 19))+
xlab('Number of intervals') +
ylab('Maximum memory used (GB)') +
theme_bw() +
theme(
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
plot.title = element_text(hjust = 0.5),
# Legend styling
legend.position = "top",
legend.background = element_rect(fill = "white", color = "black"),
# Facet strip styling
strip.background = element_rect(fill = "lightgrey", color = NA),
strip.text = element_text(face = "bold"),
strip.text.y = element_text(face = "bold", angle = 0)
)
supp_mem_plot_combined = supp_mem_plot_combined + theme(legend.position = 'none')
supp_mem_plot_combined <- ggdraw(supp_mem_plot_combined) +
draw_label(
addtext,
x = addx, # near right edge
y = addy, # near top edge
hjust = 1, vjust = 1,
fontface = "bold",
size=9
)
full_combo_plot =
plot_grid(the_legend,
supp_time_plot_combined ,
supp_mem_plot_combined ,
ncol=1,
rel_heights = c(0.2, 1, 1),
labels = c('', 'a', 'b')
)
full_combo_plot
suppressMessages(ggsave('combo_plot.full.pdf', full_combo_plot, width = 10, height = 15))
suppressMessages(ggsave('combo_plot.full.png', full_combo_plot, width = 10, height = 15))
```