-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviz_model.R
52 lines (45 loc) · 1.52 KB
/
viz_model.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
# Generates a figure showing the fit of the model
library(dplyr)
library(ggplot2)
mutation_ht <- read.table(
file = snakemake@input[["mutation_ht"]],
sep = "\t",
header = TRUE
)
calibrate_on <- read.table(
file = snakemake@input[["calibrate_on"]],
sep = "\t",
header = TRUE
)
# To ensure that the script is usable with different input files
calibrate_on <- group_by(calibrate_on, mu) %>%
summarise(variant_count = sum(variant_count), singleton_count = sum(singleton_count)) %>%
mutate(proportion_singletons = singleton_count / variant_count)
calibrate_on <- calibrate_on %>% mutate(transformed_mu = unlist(lapply(mu, snakemake@params[["transformation"]])))
mut_model <- lm(proportion_singletons ~ transformed_mu,
weights = variant_count,
data = calibrate_on
)
pdf(snakemake@output[["plot"]])
calibrate_on %>%
mutate(mu_snp = mu) %>%
left_join(mutation_ht, by = "mu_snp") %>%
ggplot() +
aes(x = transformed_mu, y = proportion_singletons, color = variant_type) +
geom_point(size = 3) +
theme_minimal() +
theme(
legend.position = "bottom",
aspect.ratio = 1,
text = element_text(size = ifelse(is.null(snakemake@params[["text_size"]]), 24, snakemake@params[["text_size"]]))
) +
scale_color_manual(snakemake@params[["legend_title"]],
values = snakemake@params[["colors"]]
) +
geom_abline(
intercept = mut_model$coefficients[[1]],
slope = mut_model$coefficients[[2]]
) +
xlab("Mutability\n(mutation rate per base pair per generation)") +
ylab("Proportion of singletons")
dev.off()