Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
381 changes: 381 additions & 0 deletions ModelF/Changed/AFIRT_calculation.R

Large diffs are not rendered by default.

283 changes: 283 additions & 0 deletions ModelF/Changed/Task05_Sensitivity_Analysis_pt2.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
---
title: "Task05_Sensitivity_Analysis_pt2"
author: "Miandra Ellis"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: html_document
# output:
# html_document:
# toc: true
# toc_float: true
# code_folding: hide
---

# Preliminary stuff

```{r, warning=FALSE}
# Need this to get rxode working. I don't know why I keep having to run this.
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:/RBuildTools/3.4/bin/",
"C:/RBuildTools/3.4/mingw_64/bin", sep = ";"))
Sys.setenv(BINPREF = "C:/RBuildTools/3.4/mingw_64/bin/")

# To be called at the top of every Rmd file. Initialization code and some useful constants.
suppressMessages(source("ams_initialize_script.R"))
```

# Create data frame for multiple drugs and parameters.

```{r, include=FALSE}

# Note: Insoluble and soluble drugs are treated differently.
# For insoluble, Tacc = M3totss/M30. For soluble, Tacc = S3totss/S30.
# We are also interested in different parameters in the SA for either case.
# See writeup for details.

# --------------------------------------------------------------------------------
# Initialize.
# --------------------------------------------------------------------------------

# Load model.
model = ivsc_4cmtct_shedct(target = TRUE)
# Drugs to explore.
drugs = c("Atezolizumab", "Herceptin", "Pembrolizumab", "Bevacizumab")
# List of parameters of interest.
parameters = c("dose", "ksynM3", "k13D", "kshedM3", "kshedDM3", "VD3")
# names(parameters) = parameters
# Create vector of soluble drugs.
soluble = "Bevacizumab"

# Create paths to data files for each drug.
paths = NULL
for (i in 1:length(drugs)) {
paths[i] = paste0("../data/ModelF_", drugs[i],"_Params.xlsx")
}

# Dose time, frequency, compartment, nominal dose
tmax = 26*7 #days
tau = 21 #days
compartment = 2
dose.nmol = scale.mpk2nmol
joined = NULL
isSoluble = FALSE

# --------------------------------------------------------------------------------
# Iterate over all the drugs.
# --------------------------------------------------------------------------------
i.dfs = 0
for (i in 1:length(drugs)){
# Load parameters.
param.as.double = read.param.file(paths[i])
df_param = as.data.frame(t(param.as.double))

# Check if drug has soluble target.
if (drugs[i] %in% soluble) {
# Change any non-shed parameters including M to S.
parameters = sapply(parameters,
function(x) {
if (!grepl("shed|dose",x)) {return(gsub("M","S", x))}
return(x)
})
isSoluble = TRUE
}

# 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(dose = lseq(scale.mpk2nmol*.1,scale.mpk2nmol*10,7),
lapply(df_param[nnzero], function(x) lseq(x*0.1, x*10, 7)))

dfs = list()
# Iterate all of the parameters for a single drug.
for (j in 1:ncol(params.to.iterate)){
i.dfs = i.dfs+1
param.to.change = names(params.to.iterate)[j]
param.to.change.range = params.to.iterate[[j]]
soluble = isSoluble
compare_i = 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,
soluble = soluble) %>%
mutate(drug = drugs[i], isSol = isSoluble)

dfs[[i.dfs]] = compare_i
}

# Reset isSoluble to false since the default in compare.thy.sim is false.
isSoluble = FALSE
}
joined = bind_rows(dfs)

```

# Plot the output AFIRT.

```{r}
# I only wanted a subset of the parameters for gather.
joined.A = joined[c("fold.change","AFIRT.Kssd", "AFIRT.Kss", "AFIRT.Kd", "AFIRT.sim", "param","drug", "isSol")]

# Use gather to make the long data frame for ggplot.
plots.A = joined.A %>% gather(key, AFIRT.value, -param, -fold.change,-drug, -isSol) %>%
filter(!is.na(AFIRT.value)) %>%
# Group by isSoluble to create to separate plots.
group_by(isSol)%>%
do(plot = ggplot(., aes(fold.change, AFIRT.value, color=key)) +
scale.x.log10() +
scale.y.log10() +
geom_line() +
geom_point() +
facet_grid(drug ~ param))
plots.A$plot
```

# Plot the output TFIRT.

```{r}
# I only wanted a subset of the parameters for gather.
joined.T = joined[c("fold.change","TFIRT.Kssd", "TFIRT.Kss", "TFIRT.Kd", "TFIRT.sim", "param","drug", "isSol")]

# Use gather to make the long data frame for ggplot.
plots.T = joined.T %>% gather(key, TFIRT.value, -param, -fold.change,-drug, -isSol) %>%
filter(!is.na(TFIRT.value)) %>%
# Group by isSoluble to create to separate plots.
group_by(isSol)%>%
do(plot = ggplot(., aes(fold.change, TFIRT.value, color=key)) +
scale.x.log10() +
scale.y.log10() +
geom_line() +
geom_point() +
facet_grid(drug ~ param))
plots.T$plot
```

# Create data frame for multiple drugs and parameters.
# This is redone for no target in order to compare Cmin.
# The only difference is 'target = FALSE' is the input for the model.

```{r, include=FALSE}

# Note: Insoluble and soluble drugs are treated differently.
# For insoluble, Tacc = M3totss/M30. For soluble, Tacc = S3totss/S30.
# We are also interested in different parameters in the SA for either case.
# See writeup for details.

# --------------------------------------------------------------------------------
# Initialize.
# --------------------------------------------------------------------------------

# Load model.
model = ivsc_4cmtct_shedct(target = FALSE)
# Drugs to explore.
drugs = c("Atezolizumab", "Herceptin", "Pembrolizumab", "Bevacizumab")
# List of parameters of interest.
parameters = c("dose", "ksynM3", "k13D", "kshedM3", "kshedDM3", "VD3")
# names(parameters) = parameters
# Create vector of soluble drugs.
soluble = "Bevacizumab"

# Create paths to data files for each drug.
paths = NULL
for (i in 1:length(drugs)) {
paths[i] = paste0("../data/ModelF_", drugs[i],"_Params.xlsx")
}

# Dose time, frequency, compartment, nominal dose
tmax = 26*7 #days
tau = 21 #days
compartment = 2
dose.nmol = scale.mpk2nmol
joined = NULL
isSoluble = FALSE

# --------------------------------------------------------------------------------
# Iterate over all the drugs.
# --------------------------------------------------------------------------------

for (i in 1:length(drugs)){
# Load parameters.
param.as.double = read.param.file(paths[i])
df_param = as.data.frame(t(param.as.double))

# Check if drug has soluble target.
if (drugs[i] %in% soluble) {
# Change any non-shed parameters including M to S.
parameters = sapply(parameters,
function(x) {
if (!grepl("shed|dose",x)) {return(gsub("M","S", x))}
return(x)
})
isSoluble = TRUE
}

# 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(dose = lseq(scale.mpk2nmol*.1,scale.mpk2nmol*10,7),
lapply(df_param[nnzero], function(x) lseq(x*0.1, x*10, 7)))

dfs = list()
# Iterate all of the parameters for a single drug.
for (j in 1:ncol(params.to.iterate)){
i.dfs = i.dfs + 1
dfs[[i.dfs]] = compare.thy.sim(model = model,
param.as.double = param.as.double,
dose.nmol = dose.nmol,
tmax = tmax,
tau = tau,
compartment = compartment,
param.to.change = names(params.to.iterate)[j],
param.to.change.range = params.to.iterate[[j]],
soluble = isSoluble) %>%
mutate(drug = drugs[i], isSol = isSoluble)
}
# Reset isSoluble to false since the default in compare.thy.sim is false.
isSoluble = FALSE
}
joined = bind_rows(dfs)

```

# Plot the output Cmin.

```{r}

# I only wanted a subset of the parameters for gather.
joined.Cmin = joined[c("fold.change","Cmin", "param","drug", "isSol")]

# Use gather to make the long data frame for ggplot.
plots.Cmin = joined.Cmin %>% gather(key, Cmin.value, -param, -fold.change,-drug, -isSol) %>%
filter(!is.na(Cmin.value)) %>%
# Group by isSoluble to create to separate plots.
group_by(isSol)%>%
do(plot = ggplot(., aes(fold.change, Cmin.value, color=key)) +
scale.x.log10() +
scale.y.log10() +
geom_line() +
geom_point() +
facet_grid(drug ~ param))
plots.Cmin$plot

```


















487 changes: 487 additions & 0 deletions ModelF/Task03_Explore_Bevacizumab.html

Large diffs are not rendered by default.

302 changes: 302 additions & 0 deletions ModelF/Task04_Sensitivity_Analysis.html

Large diffs are not rendered by default.

224 changes: 224 additions & 0 deletions ModelF/Task04_Sensitivity_Analysis_Individual.html

Large diffs are not rendered by default.

32 changes: 13 additions & 19 deletions ModelF/Task05_Sensitivity_Analysis_Aggregate.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ plots.A.Kssd = plots.A.Kssd %>%
param = str_replace(param,"S","T"),
key = str_replace(key,"_",""),
key = str_replace(key,"AFIRT\\.",""),
key = str_replace(key,"Kssd","Theory (AFTIR*)"),
key = str_replace(key,"Kssd","Theory (AFTIR)"),
key = str_replace(key,"sim","Simulation"),
Target = ifelse(isSol,"Soluble","Membrane-Bd"),
Target = factor(Target,levels=c("Soluble","Membrane-Bd")))
Expand All @@ -158,7 +158,7 @@ plots.T.Kssd = plots.T.Kssd %>%
param = str_replace(param,"S","T"),
key = str_replace(key,"_",""),
key = str_replace(key,"TFIRT\\.",""),
key = str_replace(key,"Kssd","Theory (TFTIR*)"),
key = str_replace(key,"Kssd","Theory (TFTIR)"),
key = str_replace(key,"sim","Simulation"),
Target = ifelse(isSol,"Soluble","Membrane-Bd"),
Target = factor(Target,levels=c("Soluble","Membrane-Bd")))
Expand All @@ -168,7 +168,7 @@ plots.A.Kss = plots.A.Kss %>%
param = str_replace(param,"S","T"),
key = str_replace(key,"_",""),
key = str_replace(key,"AFIRT\\.",""),
key = str_replace(key,"Kss","Theory (AFTIR*)"),
key = str_replace(key,"Kss","Theory (AFTIR)"),
key = str_replace(key,"sim","Simulation"),
Target = ifelse(isSol,"Soluble","Membrane-Bd"),
Target = factor(Target,levels=c("Soluble","Membrane-Bd")))
Expand All @@ -177,7 +177,7 @@ plots.T.Kss = plots.T.Kss %>%
param = str_replace(param,"S","T"),
key = str_replace(key,"_",""),
key = str_replace(key,"TFIRT\\.",""),
key = str_replace(key,"Kss","Theory (TFTIR*)"),
key = str_replace(key,"Kss","Theory (TFTIR)"),
key = str_replace(key,"sim","Simulation"),
Target = ifelse(isSol,"Soluble","Membrane-Bd"),
Target = factor(Target,levels=c("Soluble","Membrane-Bd")))
Expand All @@ -187,7 +187,7 @@ plots.A.Kd = plots.A.Kd %>%
param = str_replace(param,"S","T"),
key = str_replace(key,"_",""),
key = str_replace(key,"AFIRT\\.",""),
key = str_replace(key,"Kd","Theory (AFTIR*)"),
key = str_replace(key,"Kd","Theory (AFTIR)"),
key = str_replace(key,"sim","Simulation"),
Target = ifelse(isSol,"Soluble","Membrane-Bd"),
Target = factor(Target,levels=c("Soluble","Membrane-Bd")))
Expand All @@ -196,7 +196,7 @@ plots.T.Kd = plots.T.Kd %>%
param = str_replace(param,"S","T"),
key = str_replace(key,"_",""),
key = str_replace(key,"TFIRT\\.",""),
key = str_replace(key,"Kd","Theory (TFTIR*)"),
key = str_replace(key,"Kd","Theory (TFTIR)"),
key = str_replace(key,"sim","Simulation"),
Target = ifelse(isSol,"Soluble","Membrane-Bd"),
Target = factor(Target,levels=c("Soluble","Membrane-Bd")))
Expand All @@ -208,10 +208,9 @@ g = g + geom_line()
g = g + facet_grid(drug + Target ~ param, switch = "y")
g = g + scale_linetype_manual(values = c("solid","longdash"))
g = g + labs(x="Fold Change in Parameter",
y="Average Free Tissue target to\nInitial target Ratio (AFTIR)",
y="Average Free Tissue target to\nInitial target Ratio (AFTIR)")
# color = "Estimate",
# linetype = "Estimate",
caption = "Kssd")
# linetype = "Estimate")
g = g + theme(legend.position="bottom",
text=element_text(size=15),
axis.title.x=element_text(size=20),
Expand All @@ -224,30 +223,25 @@ height = 7
plot(g)
ggsave("../results/Task05_AFTIR.Kssd.pdf",width = width,height=height)
g = g %+% plots.T.Kssd
g = g + labs(y="Trough Free Tissue target to\ninitial target Ratio (TFTIR)",
caption = "Kssd")
g = g + labs(y="Trough Free Tissue target to\ninitial target Ratio (TFTIR)")
plot(g)
ggsave("../results/Task05_TFTIR.Kssd.pdf",width = width,height=height)

g = g %+% plots.A.Kss
g = g + labs(y="Average Free Tissue target to\nInitial target Ratio (AFTIR)",
caption = "Kss")
g = g + labs(y="Average Free Tissue target to\nInitial target Ratio (AFTIR)")
plot(g)
ggsave("../results/Task05_AFTIR.Kss.pdf",width = width,height=height)
g = g %+% plots.T.Kss
g = g + labs(y="Trough Free Tissue target to\ninitial target Ratio (TFTIR)",
caption = "Kss")
g = g + labs(y="Trough Free Tissue target to\ninitial target Ratio (TFTIR)")
plot(g)
ggsave("../results/Task05_TFTIR.Kss.pdf",width = width,height=height)

g = g %+% plots.A.Kd
g = g + labs(y="Average Free Tissue target to\nInitial target Ratio (AFTIR)",
caption = "Kd")
g = g + labs(y="Average Free Tissue target to\nInitial target Ratio (AFTIR)")
plot(g)
ggsave("../results/Task05_AFTIR.Kd.pdf",width = width,height=height)
g = g %+% plots.T.Kd
g = g + labs(y="Trough Free Tissue target to\ninitial target Ratio (TFTIR)",
caption = "Kd")
g = g + labs(y="Trough Free Tissue target to\ninitial target Ratio (TFTIR)")
plot(g)
ggsave("../results/Task05_TFTIR.Kd.pdf",width = width,height=height)
```
Expand Down
Loading