-
Notifications
You must be signed in to change notification settings - Fork 0
/
tigmint-parameters.rmd
170 lines (155 loc) · 5.45 KB
/
tigmint-parameters.rmd
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
---
title: Determine sensitivity to parameters of Tigmint
author: Shaun Jackman
output:
html_document:
keep_md: true
params:
input_tsv:
label: "Input TSV file of parameters and QUAST metrics"
value: "tigmint-span-parameters.quast.tsv"
input: text
output_tsv:
label: "Output TSV file of parameters and QUAST metrics"
value: "tigmint-span-parameters.quast.out.tsv"
input: text
---
```{r setup, message=FALSE}
library(cowplot)
library(dplyr)
library(ggplot2)
library(ggrepel)
library(knitr)
library(magrittr)
library(readr)
library(scales)
library(stringr)
library(tidyr)
knit_print.data.frame <- function(x, ...) kable(x) %>% paste(collapse = "\n") %>% asis_output
input_tsv <- params$input_tsv
output_tsv <- params$output_tsv
input_tsv
output_tsv
```
# Read the data
```{r read-data}
metrics_orig <- read_tsv(input_tsv)
metrics <- metrics_orig %>%
distinct() %>%
rename(Misassemblies = `# misassemblies`) %>%
filter(!str_detect(Assembly, "arcs"), !str_detect(Assembly, "broken")) %>%
mutate(Assembler = Assembly %>%
str_replace("abyss2.*", "ABySS") %>%
str_replace("discovardenovo_abyss.*", "DISCO+ABySS") %>%
str_replace("discovardenovo_besst.*", "DISCO+BESST")) %>%
bind_cols(as_tibble(str_match(.$Assembly, "window([0-9]+).*span([0-9]+)")) %>%
transmute(Window = parse_integer(V2), Span = parse_integer(V3))) %>%
mutate(Label = str_c("w=", Window, " s=", Span))
```
# Determine the range of the data
```{r range}
ranges <- metrics %>% summarize_at(vars(Window, Span, Misassemblies, NGA50), funs(min, max), na.rm = TRUE)
misassemblies_range <- ranges %$% c(0, Misassemblies_max)
nga50_range <- ranges %$% c(0, NGA50_max)
window_range <- ranges %$% c(Window_min, Window_max)
span_range <- ranges %$% c(Span_min, Span_max)
```
# Plot parameters and assembly metrics
```{r NGA50-misassemblies}
ggplot(drop_na(metrics)) +
aes(x = Misassemblies, y = NGA50, label = Label) +
geom_point() +
geom_text_repel() +
scale_x_continuous(name = "QUAST Misassemblies", labels = comma) +
scale_y_continuous(name = "Scaffold NGA50", labels = unit_format(unit = "Mbp", scale = 1e-6)) +
theme_minimal(base_size = 11)
```
# Plot misassemblies vs window
```{r misassemblies-window}
plot_misassemblies_window <- ggplot(metrics %>% filter(Span == 20)) +
aes(x = Window, y = Misassemblies,
colour = Assembler, group = Assembler, shape = Assembler) +
geom_point() +
geom_line() +
scale_y_continuous(name = "Misassemblies", labels = comma) +
scale_x_log10(name = "Window (bp)", labels = comma,
breaks = unique(metrics$Window), minor_breaks = NULL) +
scale_colour_brewer(palette = "Dark2") +
expand_limits(x = window_range, y = misassemblies_range) +
theme_minimal(base_size = 11) +
theme(legend.position="bottom")
plot_misassemblies_window
```
# Plot NGA50 vs window
```{r NGA50-window}
plot_nga50_window <- ggplot(metrics %>% filter(Span == 20)) +
aes(x = Window, y = NGA50,
colour = Assembler, group = Assembler, shape = Assembler) +
geom_point() +
geom_line() +
scale_y_continuous(name = "NGA50 (Mbp)", labels = unit_format(unit = "", scale = 1e-6)) +
scale_x_log10(name = "Window (bp)", labels = comma,
breaks = unique(metrics$Window), minor_breaks = NULL) +
scale_colour_brewer(palette = "Dark2") +
expand_limits(x = window_range, y = nga50_range) +
theme_minimal(base_size = 11) +
theme(legend.position="bottom")
plot_nga50_window
```
# Plot misassemblies vs spanning molecules
```{r misassemblies-molecules}
plot_misassemblies_molecules <- ggplot(metrics %>% filter(Window == 2000)) +
aes(x = Span, y = Misassemblies,
colour = Assembler, group = Assembler, shape = Assembler) +
geom_point() +
geom_line() +
scale_y_continuous(name = "Misassemblies", labels = comma) +
scale_x_log10(name = "Spanning molecules",
breaks = unique(metrics$Span), minor_breaks = NULL) +
scale_colour_brewer(palette = "Dark2") +
expand_limits(x = span_range, y = misassemblies_range) +
theme_minimal(base_size = 11) +
theme(legend.position="bottom")
plot_misassemblies_molecules
```
# Plot NGA50 vs spanning molecules
```{r NGA50-molecules}
plot_nga50_molecules <- ggplot(metrics %>% filter(Window == 2000)) +
aes(x = Span, y = NGA50,
colour = Assembler, group = Assembler, shape = Assembler) +
geom_point() +
geom_line() +
scale_y_continuous(name = "NGA50 (Mbp)", labels = unit_format(unit = "", scale = 1e-6)) +
scale_x_log10(name = "Spanning molecules",
breaks = unique(metrics$Span), minor_breaks = NULL) +
scale_colour_brewer(palette = "Dark2") +
expand_limits(x = span_range, y = nga50_range) +
theme_minimal(base_size = 11) +
theme(legend.position="bottom")
plot_nga50_molecules
```
# Metrics vs parameters
```{r parameters, fig.width = 6, fig.height = 4, dpi = 300}
plot_grid(ncol = 2,
labels = c("A", "B", "C", "D"),
plot_misassemblies_molecules + theme(legend.position = "none"),
plot_misassemblies_window + theme(legend.position = "none"),
plot_nga50_molecules + theme(legend.position = "none"),
plot_nga50_window + theme(legend.position = "none")) %>%
plot_grid(ncol = 1, rel_heights = c(2, 0.1), get_legend(plot_misassemblies_molecules))
```
# Table of parameters and assembly metrics
```{r parameters-table}
parameters_table <- metrics %>%
arrange(Assembler, !is.na(Window), Window, Span) %>%
replace_na(list(Window = "Original", Span = "Original")) %>%
transmute(
Assembler,
Window,
Span,
`NG50 (Mbp)` = round(NG50 / 1e6, 2),
`NGA50 (Mbp)` = round(NGA50 / 1e6, 2),
Misassemblies = comma(Misassemblies))
parameters_table
write_tsv(parameters_table, output_tsv)
```