-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprecision-recall.rmd
78 lines (69 loc) · 1.99 KB
/
precision-recall.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
---
title: Calculate precision and recall of Tigmint
author: Shaun Jackman
output:
html_document:
keep_md: true
params:
breakpoints_count_tsv:
label: "Input TSV file of parameters and metrics"
value: "breakpoints.count.tsv"
input: text
samtobreak_tsv:
label: "Input TSV file of parameters and metrics"
value: "samtobreak.tsv"
input: text
output_tsv:
label: "Output TSV file of precision, recall, and G-score"
value: "precision-recall.out.tsv"
input: text
---
```{r setup, message=FALSE}
library(dplyr)
library(ggplot2)
library(ggrepel)
library(knitr)
library(readr)
library(tidyr)
knit_print.data.frame <- function(x, ...) kable(x) %>% paste(collapse = "\n") %>% asis_output
breakpoints_count_tsv <- params$breakpoints_count_tsv
samtobreak_tsv <- params$samtobreak_tsv
output_tsv <- params$output_tsv
```
# Read the data
```{r read-data}
breakpoints_count <- read_tsv(breakpoints_count_tsv)
samtobreak_orig <- read_tsv(samtobreak_tsv)
samtobreak <- samtobreak_orig %>% drop_na()
Positives <- max(samtobreak_orig$Total_breakpoints)
metrics <- left_join(breakpoints_count, samtobreak, by = c("Depth", "Starts")) %>%
transmute(Depth, Starts, PP, FN = Total_breakpoints, P = Positives)
```
# Compute the precision, recall, and F1 score.
```{r compute-precision-recall}
precision_recall <- metrics %>%
mutate(
Label = paste("Clipped =", Starts),
TP = P - FN,
FP = PP - TP,
PPV = TP / PP,
TPR = TP / P,
F1 = 2 * PPV * TPR / (PPV + TPR),
G = sqrt(PPV * TPR))
```
# Precision vs recall scatter plot
```{r precision-recall}
ggplot(precision_recall) +
aes(x = TPR, y = PPV, label = Label) +
geom_point() +
geom_text_repel() +
scale_x_continuous(name = "Recall (TPR)", limits = c(0, 0.15)) +
scale_y_continuous(name = "Precision (PPV)", limits = c(0, 1)) +
theme_bw(base_size = 20) +
theme(panel.border = element_blank())
```
# Precision vs recall table
```{r precision-recall-table}
precision_recall %>% select(-Label) %>% write_tsv(output_tsv)
precision_recall
```