1+
2+ library(dMod )
3+ library(dplyr )
4+ library(ggplot2 )
5+ theme_set(theme_dMod())
6+ rm(list = ls())
7+
8+ # # Read the data ---------------------------------------------
9+
10+ data(BAdata )
11+ data <- BAdata %> %
12+ filter(experiment == " exp1" ) %> %
13+ as.datalist()
14+ covtable <- covariates(data )
15+ print(covtable )
16+
17+ plot(data )
18+
19+
20+ # # Set up a base model ----------------------------------------
21+
22+ # Set up base reactions
23+ reactions <- eqnlist() %> %
24+ addReaction(" Tca_buffer" , " Tca_cyto" , " import_Tca*Tca_buffer" , " Basolateral uptake" ) %> %
25+ addReaction(" Tca_cyto" , " Tca_buffer" , " export_Tca_baso*Tca_cyto" , " Basolateral efflux" ) %> %
26+ addReaction(" Tca_cyto" , " Tca_canalicular" , " export_Tca_cana*Tca_cyto" , " Canalicular efflux" ) %> %
27+ addReaction(" Tca_canalicular" , " Tca_buffer" , " transport_Tca*Tca_canalicular" , " Transport bile" ) %> %
28+ addReaction(" 0" , " cations" , " 0" , " Cation concentration in buffer" )
29+
30+ # Translate to ODEs and let cation concentration change transport rate
31+ odes <- reactions %> %
32+ as.eqnvec() %> %
33+ reparameterize(" x ~ (x*crit/(crit + cations))" , x = " transport_Tca" )
34+
35+ # Set up events to control the experiment
36+ events <- data.frame (
37+ var = c(" Tca_buffer" , " cations" ),
38+ time = c(" change_buffer" , " change_cations" ),
39+ value = c(" value_buffer" , " value_cations" ),
40+ method = c(" replace" , " replace" )
41+ )
42+
43+ # Make ODE model available as prediction function
44+ noSens <- c(" change_buffer" , " change_cations" , " value_cations" , " cations" )
45+ x <- odemodel(odes , events = events , fixed = noSens , modelname = " BA_basemodel" ) %> %
46+ Xs()
47+
48+ # Make observation function available
49+ g <- eqnvec(
50+ buffer = " s*Tca_buffer" ,
51+ cellular = " s*(Tca_cyto + Tca_canalicular)" ) %> %
52+ Y(f = x , modelname = " obsfn" , compile = TRUE )
53+
54+ # Parameterize the model
55+ parameters <- getParameters(g , x )
56+ transformation <- eqnvec() %> %
57+ reparameterize(" x~x" , x = parameters ) %> %
58+ reparameterize(" x~0" , x = c(" Tca_cyto" , " Tca_canalicular" , " value_buffer" , " value_cations" )) %> %
59+ reparameterize(" x~1" , x = " cations" )
60+
61+
62+ p <- P()
63+ for (c in rownames(covtable )) {
64+ p <- p + transformation %> %
65+ reparameterize(" x~cations" , x = " change_cations" , cations = covtable [c , " cations" ]) %> %
66+ reparameterize(" x~buffer" , x = " change_buffer" , buffer = covtable [c , " drug_time" ]) %> %
67+ reparameterize(" x~exp(x)" , x = parameters ) %> %
68+ P(condition = c )
69+ }
70+
71+ estimate <- getParameters(p )
72+ pars <- structure(rep(- 1 , length(estimate )), names = estimate )
73+ times <- seq(0 , 200 , 1 )
74+ (g * x * p )(times , pars ) %> % plot(data = data , time < = 180 )
75+
76+ obj <- normL2(data , g * x * p ) + constraintL2(pars , sigma = 10 )
77+ myfit <- trust(obj , pars , rinit = 1 , rmax = 10 , iterlim = 500 )
78+
79+ (g * x * p )(times , myfit $ argument ) %> % plot(data = data )
80+
81+ profiles <- profile(obj , myfit $ argument , names(myfit $ argument ), cores = 4 )
82+ profiles %> % plotProfile(mode == " data" )
83+
84+
85+ # Add additional data
86+ data $ exp1_30_no_0_0_30 <- rbind(data $ exp1_30_no_0_0_30 , data.frame (
87+ name = " Tca_buffer" , time = 0 , value = 21.5 , sigma = 2
88+ ))
89+
90+ obj <- normL2(data , g * x * p ) + constraintL2(pars , sigma = 10 )
91+ myfit <- trust(obj , pars , rinit = 1 , rmax = 10 , iterlim = 500 )
92+
93+ (g * x * p )(times , myfit $ argument ) %> % plot(data = data )
94+
95+ profiles <- profile(obj , myfit $ argument , c(" s" , " Tca_buffer" ), cores = 2 )
96+ profiles %> % plotProfile(mode == " data" )
97+
98+ # Explore parameter space
99+ fits <- mstrust(obj , pars , fits = 30 , rinit = 1 , rmax = 10 , samplefun = " runif" , min = - 5 , max = 5 , cores = 4 )
100+ parframe <- as.parframe(fits )
101+ plotValues(parframe [1 : 29 ,])
102+ plotPars(parframe [1 : 29 ,])
103+ subframe <- unique(parframe [1 : 29 ,])
104+
105+ prediction <- predict(g * x * p , times = times , pars = subframe , data = data )
106+
107+ ggplot(prediction , aes(x = time , y = value , color = as.factor(.value ))) + facet_wrap(~ name * cations , scales = " free" ) +
108+ geom_line() +
109+ geom_point(data = as.data.frame(data ), color = " black" )
110+
111+ profiles <- lapply(1 : nrow(subframe ), function (i ) {
112+ profile(obj , as.parvec(subframe , i ), names(myfit $ argument ), cores = 4 , algoControl = list (gamma = 10 ))
113+ })
114+ names(profiles ) <- c(" obj = 23" , " obj = 24" , " obj = 27" )
115+ profiles %> % plotProfile(mode == " data" )
116+
117+ partable <- confint(profiles [[1 ]], level = 0.9 , val.column = " value" )
118+
119+ # Save objects from this session
120+ save.image(file = " part1.RData" )
121+
122+
0 commit comments