-
Notifications
You must be signed in to change notification settings - Fork 1
/
Task07_Check_Repar.R
164 lines (133 loc) · 6.41 KB
/
Task07_Check_Repar.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
source("ams_initialize_script.R")
#rxSetIni0(FALSE)
source("SCIM_calculation.R")
source("ivsc_2cmt_RR_V1.R")
dirs$Rscript.name = "Task07_Check_Repar.R"
dirs$output.prefix= str_extract(dirs$Rscript.name,"^Task\\d\\d\\w?_")
model = ivsc_2cmt_RR_KeqT0L0()
#Drug list to loop through for finding file names
drugs_list = list("Pembro","VEGFR1","VEGFR2","Atezoli","Ramuc","Siltux","Tociliz") #ADD THIS LINE
dfs = data.frame() #ADD THIS LINE
# Create paths to data files for each drug.
param = NULL #ADD THIS LINE
i = 1 #ADD THIS LINE
#Get params for all the drugs
drugs = drugs_list[1] #ADD THIS LOOP
filename = "parameters/ModelG_Pembro_Params_update_RR.xlsx"
# List of parameters of interest.
parameters = c("T0", "keDT","Kss_TL", "kon_TL", "Kss_DT","kon_DT")
# Dose time, frequency, compartment, nominal dose
tmax = 52*7 #days
tau = 21 #days
compartment = 2
dose.nmol = 100*scale.mpk2nmol
param.list = list()
all_params <- data.frame() #ADD THIS LINE
i = 1
# Load parameters.
param.as.double = read.param.file(filename) #ADD THIS LINE (CHANGED VARIABLE NAME TO PARAM)
param.as.double["T0"] = 1
param.as.double["L0"] = 1
param.as.double["Kss_DT"] = 1 #with(df_param,(koff_DT+keDT)/kon_DT)
param.as.double["Kss_TL"] = 1 #with(df_param,(koff_TL+keTL)/kon_TL)
param.as.double = param.as.double[model$pin]
df_param = as.data.frame(t(param.as.double))
param.list[[i]] = data.frame(t(param.as.double)) %>%
mutate(drug = drugs_list[[i]]) %>%
dplyr::select(drug,everything())
# Set range for parameters of interest in SA.
# Check which parameters are nonzero, not including dose which isn't in df_param.
nnzero = df_param[parameters[which(parameters != "dose")]] != 0
nnzero = colnames(nnzero)[which(nnzero)]
params.to.iterate = data.frame(lapply(df_param[nnzero], function(x) lseq(x*0.000001, x*1000000, 13)))
dfs = list() #Reset the temp list for every drug
temp_dfs <- data.frame() #Reset the temporary dataframe
# Iterate all of the parameters for a single drug.
for (j in 1:ncol(params.to.iterate)){
param.to.change = names(params.to.iterate)[j]
param.to.change.range = params.to.iterate[[j]]
dfs[[j]] = compare.thy.sim(model = model,
param.as.double = param.as.double,
dose.nmol = dose.nmol,
tmax = tmax,
tau = tau,
compartment = compartment,
param.to.change = param.to.change,
param.to.change.range = param.to.change.range)
}
#ADD THESE LINES
temp_dfs <- bind_rows(dfs) #create a temp dataframe for all the data
temp_dfs$drug <- as.character(drugs_list[i])
all_params <- rbind(all_params,temp_dfs) #Cat data frame
# param.table = bind_rows(param.list) %>%
# mutate(Kd_DT = koff_DT/kon_DT,
# Kss_DT = (koff_DT + keDT)/kon_DT,
# Kd_TL = koff_TL/kon_TL,
# Kss_TL = (koff_TL + keTL)/kon_TL)
# #View(param.table)
#
# drug = param.table$drug
# param.tablet = param.table %>%
# dplyr::select(-drug) %>%
# t() %>%
# as.data.frame() %>%
# setNames(drug)
# #View(param.tablet)
data.plot = all_params %>%
dplyr::select(fold.change.param, SCIM_sim, SCIM_thy_keTL_negroot, SCIM_thy_keTL0, AFIR_thy, drug,param) %>%
gather(key,value,-c(fold.change.param,drug,param))
g = ggplot(data.plot, aes(x=fold.change.param,y=value,color=key,linetype=key))
g = g + geom_line(size = 1, alpha = .5)
g = g + facet_grid(drug ~ param,scales = "free_y", switch = "y")
g = g + scale_x_log10()
g = g + scale_y_log10()
g = g + scale_color_manual (values = c(SCIM_sim = "black",
SCIM_thy_keTL0 = "blue",
SCIM_thy_keTL_negroot = "green",
AFIR_thy = "red"))
g = g + scale_linetype_manual(values = c(SCIM_sim = "solid",
SCIM_thy_keTL0 = "dotted",
SCIM_thy_keTL_negroot = "dashed",
AFIR_thy = "solid"))
print(g)
# Compare simplified SCIM eqns.
# SCIM_thy_keTL_negroot is the most complex i.e not simplified version of SCIM
# SCIM_sim is the SCIM from the simulation
# 26, 29, and 31 refer to the eqn numbers in the latex doc. for the simplified SCIMs
data.SCIMs = all_params %>%
dplyr::select(fold.change.param, SCIM_sim, SCIM_thy_keTL_negroot, SCIM_thy_keTL_negroot26, SCIM_thy_keTL_negroot31, drug,param) %>%
gather(key,value,-c(fold.change.param,drug,param))
g <- ggplot(data.SCIMs, aes(x=fold.change.param,y=value,color=key,linetype=key)) +
geom_line(size = 1, alpha = .6) +
facet_grid(drug ~ param,scales = "free_y", switch = "y") +
scale_x_log10() +
scale_y_log10() +
scale_color_manual(values = c(SCIM_sim = "gray25",
SCIM_thy_keTL_negroot = "green3",
SCIM_thy_keTL_negroot26 = "dodgerblue4",
#SCIM_thy_keTL_negroot29 = "yellow",
SCIM_thy_keTL_negroot31 = "darkorange")) +
scale_linetype_manual(values = c(SCIM_sim = "solid",
SCIM_thy_keTL_negroot = "dashed",
SCIM_thy_keTL_negroot26 = "dotdash",
#SCIM_thy_keTL_negroot29 = "dotted",
SCIM_thy_keTL_negroot31 = "dashed"))
print(g)
# Compare simplified SCIMs and AFIR.
data.SCIMs2 = all_params %>%
dplyr::select(fold.change.param, SCIM_sim, SCIM_thy_keTL_negroot, SCIM_thy_keTL_negroot26, AFIR_thy, drug,param) %>%
gather(key,value,-c(fold.change.param,drug,param))
g <- ggplot(data.SCIMs2, aes(x=fold.change.param,y=value,color=key,linetype=key)) +
geom_line(size = 1, alpha = .6) +
facet_grid(drug ~ param,scales = "free_y", switch = "y") +
scale_x_log10() +
scale_y_log10() +
scale_color_manual (values = c(SCIM_sim = "gray25",
SCIM_thy_keTL_negroot = "green3",
SCIM_thy_keTL_negroot26 = "dodgerblue4",
AFIR_thy = "red")) +
scale_linetype_manual(values = c(SCIM_sim = "solid",
SCIM_thy_keTL_negroot = "dashed",
SCIM_thy_keTL_negroot26 = "dotdash",
AFIR_thy = "solid"))
print(g)