-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_bestestimates_CI.R
204 lines (146 loc) · 8.76 KB
/
display_bestestimates_CI.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
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
########################################################################
###### Displaying best estimates of virus production rates ######
########################################################################
###### Required libraries
library(graphics)
###### set working directory
# setwd("/path/to/FluAdaptation/") ### <<<--- you have to add the path to the folder on your machine here and uncomment this line!!!
###### source required R scripts
source("ANP_model.R")
########################################################################
###### Definition of functions ######
########################################################################
# function to plot passaging data alongside best fits
plot.passigingdata.withCIbootstrap <- function(fn.pass, fn.estCI, fn.pdf, cinit = c(U = 4e5, IE=0, IK=0, VE=(1-0.1639)*400, VK=0.1639*400 ), t = seq(0,5,0.1), Npass = 5, Tpass = 6, beta = 2.7e-6, delta = 4, c = 3, average = T){
# function to plot the passaging data in ANP_passage_experiment.csv alongside best estimates (see estimating_virus_production_rates.R) and CI (see CIbootstrap.Rmd)
### input:
# fn.pass file name of passaging data fn.pass <- "data/2018-08-16_ANP_passage_experiment.csv"
# fn.estCI file name with best estimates and CI fn.estCI <- "results/revisions/CIwithbootstrap/bestfits_pEi_pKi_withbootstrapCI.csv"
# fn.pdf file name of plot
# ... parameters as described in estimating_virus_production_rates.R
# average if TRUE, the average of the passaging data is drawn as a dotted line
### output:
# pdf file with data and best estimates plotted
ordata <- read.csv(fn.pass)
est <- read.csv(fn.estCI)
pdf(fn.pdf, width=4, height=4, useDingbats=FALSE)
plot(c(0,Npass), c(0,100), xlab="passage", ylab="% PB2-627K", axes=F, type="n" )
axis(1,lwd=2)
axis(2,lwd=2)
for(i in 1:3){
xi <- paste0("X",i)
parms_lower <- c(beta = beta, delta = delta, pE = est[ which(est[,"Xi"] == i & est[,"kind"] == "lower" ), "pEi" ], pK = est[ which(est[,"Xi"] == i & est[,"kind"] == "lower" ), "pKi" ], c = c)
parms_est <- c(beta = beta, delta = delta, pE = est[ which(est[,"Xi"] == i & est[,"kind"] == "estimate" ), "pEi" ], pK = est[ which(est[,"Xi"] == i & est[,"kind"] == "estimate" ), "pKi" ], c = c)
parms_upp <- c(beta = beta, delta = delta, pE = est[ which(est[,"Xi"] == i & est[,"kind"] == "upper" ), "pEi" ], pK = est[ which(est[,"Xi"] == i & est[,"kind"] == "upper" ), "pKi" ], c = c)
est_lower <- predicting_passage_model2(cinit, parms_lower, t, Npass, Tpass)
est_est <- predicting_passage_model2(cinit, parms_est, t, Npass, Tpass)
est_upp <- predicting_passage_model2(cinit, parms_upp, t, Npass, Tpass)
col = list(rgb(1,0,0,0.1), rgb(0,1,0,0.1), rgb(0,0,1,0.1))[[i]]
polygon(c(0:Npass, Npass:0), c(est_lower[, "percentPB2.627K"], rev(est_upp[, "percentPB2.627K"]) ), col= col, border=NA )
lines(0:Npass, est_est[, "percentPB2.627K"] , col= c("red", "green", "blue")[i])
zw <- ordata[which(ordata[,"ANP"]==xi),]
points(zw[,"passage"], zw[,"percentK"], pch= c(15,19,17)[i], col = c("red", "green", "blue")[i])
if(average){
x <- c()
y <- c()
for(pa in unique(zw[,"passage"])){
x <- c(x,pa)
y <- c(y, mean(zw[which(zw[,"passage"]==pa) ,"percentK"]))
}
lines(x,y, pch= c(15,19,17)[i], col = c("red", "green", "blue")[i], lty=2)
}
}
dev.off()
}
# function to plot passaging data in mixed ANP32A expressing cells alongside the model prediction
plot.data.with.prediction.withCIbootstrap <- function(fn.dat, fn.estCI, ratioXi, line, fn.pdf, addaverage = F, Npass = 5, U = 4e5, IE=0, IK=0, sumVEVK=400, t = seq(0,5,0.1), Tpass = 6, beta = 2.7e-6, delta = 4, c = 3){
### input:
# fn.dat file name of data, eg. fn.dat <- "data/arificial_cell_lines/Line_7_9.csv"
# fn.estCI file name with best estimates and CI fn.estCI <- "results/revisions/CIwithbootstrap/bestfits_pEi_pKi_withbootstrapCI.csv"
# ratioXi ratios of X1, X2, X3
# addaverage True if a line between the average points should be drawn
### output:
# a pdf file
dat <- read.csv(fn.dat)
subdat <- dat[which(dat[,"line"] == line), ]
est <- read.csv(fn.estCI)
pdf(fn.pdf, width=4, height=4, useDingbats=FALSE)
plot(c(0,Npass), c(0,100), xlab="passage", ylab="% PB2-627K", axes=F, type="n")
axis(1,lwd=2)
axis(2,lwd=2)
v.pE_lower <- est[which(est[,"kind"] == "lower"), "pEi" ]
v.pK_lower <- est[which(est[,"kind"] == "lower"), "pKi" ]
pE_lower <- sum( v.pE_lower * ratioXi/sum(ratioXi) )
pK_lower <- sum( v.pK_lower * ratioXi/sum(ratioXi) )
v.pE_estimate <- est[which(est[,"kind"] == "estimate"), "pEi" ]
v.pK_estimate <- est[which(est[,"kind"] == "estimate"), "pKi" ]
pE_estimate <- sum( v.pE_estimate * ratioXi/sum(ratioXi) )
pK_estimate <- sum( v.pK_estimate * ratioXi/sum(ratioXi) )
v.pE_upper <- est[which(est[,"kind"] == "upper"), "pEi" ]
v.pK_upper <- est[which(est[,"kind"] == "upper"), "pKi" ]
pE_upper <- sum( v.pE_upper * ratioXi/sum(ratioXi) )
pK_upper <- sum( v.pK_upper * ratioXi/sum(ratioXi) )
parms_lower <- c(beta = beta, delta = delta, pE = pE_lower, pK = pK_lower, c = c)
parms_est <- c(beta = beta, delta = delta, pE = pE_estimate, pK = pK_estimate, c = c)
parms_upp <- c(beta = beta, delta = delta, pE = pE_upper, pK = pK_upper, c = c)
col <- c(rgb(0,0,0,0.1),rgb(1,0,0,0.1))
startVK <- mean(subdat[which(subdat[,"passage"]==0), "percentPB2.627K"])/100
cinit <- c(U = U, IE=IE, IK=IK, VE=(1-startVK)*400, VK=startVK*400 )
est_lower <- predicting_passage_model2(cinit, parms_lower, t, Npass, Tpass)
est_est <- predicting_passage_model2(cinit, parms_est, t, Npass, Tpass)
est_upp <- predicting_passage_model2(cinit, parms_upp, t, Npass, Tpass)
polygon(c(0:Npass, Npass:0), c(est_lower[, "percentPB2.627K"], rev(est_upp[, "percentPB2.627K"]) ), col= col[1], border=NA )
lines(0:Npass, est_est[,"percentPB2.627K"], lwd=2, col = 1 )
points(subdat[,"passage"], subdat[,"percentPB2.627K"], pch=16, col= 1)
if(addaverage){
perc.av <- c()
for(pass in sort(unique(subdat[,"passage"]))){
perc.av <- c(perc.av, mean( subdat[ which(subdat[,"passage"] ==pass) ,"percentPB2.627K"] ))
}
lines(0:pass, perc.av, lwd=2, col = 1, lty = 3 )
}
dev.off()
}
####################################################
###### Example for function calls ######
####################################################
# # Note this section is commented out such that this file can be sourced without producing any output.
# # Source the necessary functions, but make sure to comment-out this command when sourcing this file (otherwise
# # you will have an infinite loop:
# # source("virus_production_rates/display_bestestimates_CI.R")
# # This is the script for reproducing Figure 4b of the paper:
# fol.out <- "virus_production_rates/test/"
# system(paste0("mkdir ", fol.out))
#
# fn.pass <- "data/input/ANP_passage_experiment.csv"
# fn.estCI <- "data/results/estimation_virus_production/bestfits_pEi_pKi_withbootstrapCI.csv"
# fn.pdf <- paste0(fol.out, "bestfits_pEi_pKi_withbootstrapCI_averageline.pdf")
# plot.passigingdata.withCIbootstrap(fn.pass = fn.pass, fn.estCI = fn.estCI, fn.pdf = fn.pdf, average=T)
#
# # This is the script for reproducing Figures 4 c, d, f, g:
# # Figure 4c
# fn.dat <- "data/input/Chicken_cells_passaging_DF_1.csv"
# fn.estCI <- "data/results/estimation_virus_production/bestfits_pEi_pKi_withbootstrapCI.csv"
# line <- 1
# ratioXi <- c(66,24.9,9.1)
# fn.pdf <- paste0(fol.out, "predictions_chickencells_DF_1_withaverageline.pdf")
# plot.data.with.prediction.withCIbootstrap(fn.dat, fn.estCI, ratioXi, line, fn.pdf, addaverage = T)
# Figure 4d
# fn.dat <- "data/input/Chicken_cells_LMH-I.csv"
# fn.estCI <- "data/results/estimation_virus_production/bestfits_pEi_pKi_withbootstrapCI.csv"
# line <- 1
# ratioXi <- c(62.6,26.7,10.7)
# fn.pdf <- paste0(fol.out, "predictions_chickencells_LMH-I_withaverageline.pdf")
# plot.data.with.prediction.withCIbootstrap(fn.dat, fn.estCI, ratioXi, line, fn.pdf, addaverage = T)
# Figure 4f
# fn.dat <- "data/input/artificial_cell_lines.csv"
# line <- 7
# ratioXi <- c(10, 0, 90)
# fn.pdf <- paste0(fol.out, "predictions_line7_withaverageline.pdf")
# plot.data.with.prediction.withCIbootstrap(fn.dat, fn.estCI, ratioXi, line, fn.pdf, addaverage = T)
# # Figure 4g
# fn.dat <- "data/input/artificial_cell_lines.csv"
# line <- 9
# ratioXi <- c(84, 0, 16)
# fn.pdf <- paste0(fol.out, "predictions_line9_withaverageline.pdf")
# plot.data.with.prediction.withCIbootstrap(fn.dat, fn.estCI, ratioXi, line, fn.pdf, addaverage = T)