-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLethalFracSensitivity.R
More file actions
65 lines (51 loc) · 1.84 KB
/
LethalFracSensitivity.R
File metadata and controls
65 lines (51 loc) · 1.84 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
library(tidyverse)
library(gridExtra)
library(scales)
## Figure 3B: Mutation accumulation experiment ##
#Load initial processing of sequencing data
source("analyses/SequencingAnalysis.R")
source("analyses/ConditionalProbability.R")
#Separate conditions into different tables
#control
ctl <- mut_per_sample %>%
filter(str_detect(condition, "Ctl")) %>%
pull(n_mutations)
#calculate bootstrapped 95% confidence intervals
lethal_fraction = 0.4
#Infer values for full population
#function for unconditional bootstrap
bootstrap_uc <- function(n, mut_counts, lf){
#pre-allocate
bs_mean <- vector(mode = "numeric", length = n)
bs_var <- vector(mode = "numeric", length = n)
for(i in 1:n){
s <- sample(mut_counts, n, replace = TRUE)
bs_mean[i] <- exp_x_uc(mean(s), var(s), lf)
bs_var[i] <- var_x_uc(mean(s), var(s), lf)
}
return(tibble(m = bs_mean, v = bs_var, oi = v/m))
}
#calculate inferred values
ctl_bs_uc <- bootstrap_uc(1000, ctl, lethal_fraction)
ctl_95_uc <- quantile(ctl_bs_uc$oi,c(0.05, 0.95), na.rm = TRUE)
ci_uc <- tibble(
condition = factor(c("Ctl"), levels = c("Ctl")),
q5 = c(ctl_95_uc[1]),
q95 = c(ctl_95_uc[2])
)
#plot inferred data and confidence intervals
overdispersion_ci_uc <- overdispersion_full %>%
right_join(ci_uc, by = "condition") %>%
mutate(oi_uc = var_x_ucV(mean_mut, var_mut, lethal_fraction)/
exp_x_ucV(mean_mut, var_mut, lethal_fraction),
q5 = ifelse(is.na(q5), 0.8, q5))
ggplot(overdispersion_ci_uc, aes(x = condition, y = oi_uc)) +
geom_point(size = 3) +
geom_text(aes(label = round(oi_uc,2)), hjust = -0.5, size = 6) +
geom_linerange(aes(ymin = q5, ymax = q95)) +
geom_hline(yintercept = 1, alpha = 0.5, linetype = 5) +
theme_classic() +
scale_y_continuous(limits = c(0.8, 1.5)) +
labs(x = "ribavirin",
y = "index of dispersion",
title = "Inferred")