-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.R
More file actions
66 lines (53 loc) · 2.39 KB
/
model.R
File metadata and controls
66 lines (53 loc) · 2.39 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
64
65
66
# We'll use the deSolve package for our integration engine
library(deSolve)
# define the solver that we want to use
solver <- ode
# Header element describing this model
headerText <- "Binding Model"
# Sidebar header with instructions. (this is markdown code)
sidebarHeader <- "The simulation will update as you change the parameters below. Use the 'Simulation' tab to iterate over a series of input parameters."
# Footer with some extra text. (this is markdown code)
sidebarFooter <- "Version 0.5. [Source code](https://github.com/whitwort/bindingModel) available on github."
# Kinetic parameters; don't duplicate names with the state vector
parameters <- c( kon = 1000
, koff = 10
)
# Initial values of state variables; don't duplicate names with the parameters vector
state <- c( A = 0.001
, B = 0.01
, AB = 0
)
# Time window and step size
time <- c( start = 0
, end = 1
, step = 0.01
)
# deSolve functional interface; t is the model time passed by the library
model <- function(t, state, parameters) {
# We'll bind state and parameter variables to clean up our model code block
with(as.list(c(state, parameters)), {
# This function returns an ordered list of rate of change calculations: the
# order should match that of the state vector
return(list(c( dA <- (koff * AB) - (kon * A * B)
, dB <- (koff * AB) - (kon * A * B)
, dAB <- (kon * A * B) - (koff * AB)
)
)
)
})
}
# Named vector of functions that are availabe as response variable choices on
# the summary tab. Functions should take one argument, the results data.frame,
# with a $time variable and named variables for all of the model states.
state.summary <- c( "min([A])" = function(r) { min(r$A) }
, "min([B])" = function(r) { min(r$B) }
, "min([AB])" = function(r) { min(r$AB) }
, "max([A])" = function(r) { max(r$A) }
, "max([B])" = function(r) { max(r$A) }
, "max([AB])" = function(r) { max(r$AB) }
)
# Label formatters
stateFormat <- function(name) { paste("Initial [", name, "] (mM)", sep = "") }
parameterFormat <- function(name) { paste("Rate of ", name, " (s-1)", sep = "") }
simluationSteps <- 25
simulationTime <- 20000