/
model_building.Rmd
139 lines (105 loc) · 3.06 KB
/
model_building.Rmd
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
---
title: "Model Building"
author: "Jonas Förster & Jürgen Pahle"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Model Building}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, echo=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.width = 8,
fig.asp = 10/16,
out.width = "100%",
error = TRUE,
warning = TRUE,
message = FALSE
)
set.seed(1)
```
# Initial Setup
```{r setup}
library(ggplot2)
library(CoRC)
```
# Quick Model Building
Building a quick Michaelis-Menten reaction using COPASI's automatisms.
Working with reaction equations automatically creates required entities the same way the COPASI GUI does.
```{r}
newModel()
newReaction("a = b", fun = "Reversible Michaelis-Menten")
getSpecies()
getReactions()
getParameters()
unloadModel()
```
# More Detail
Getting more detail in can be helpful.
Here we create a global quantity "substrate concentration" which applies a fixed value to species "a".
This is achieved by assigning the `Value` reference of the global quantity to species "a".
```{r}
newModel()
subs_quant <- newGlobalQuantity("substrate concentration", initial_value = 10)
subs_value <- quantity(subs_quant, reference = "Value")
subs_value
newSpecies("a", type = "assignment", expression = subs_value)
newReaction("a = b", fun = "Reversible Michaelis-Menten")
getGlobalQuantities()
getSpecies()
getReactions()
getParameters()
timecourse <- runTimeCourse(1000)
autoplot.copasi_ts(timecourse)
unloadModel()
```
# Defining Reaction Kinetics Manually
In previous examples, we used the predefined "Reversible Michaelis-Menten" kinetic functions.
In this example we create an equivalent function manually to achieve the same result.
```{r}
newModel()
newCompartment("compartment")
newSpecies("a", type = "fixed", initial_concentration = 10)
newSpecies("b")
newKineticFunction(
"manual MM",
"((Vf * substrate) / Kms - Vr * product / Kmp) / (1 + substrate / Kms + product / Kms)",
parameters = list(substrate = "substrate", product = "product")
)
newReaction(
"a = b",
fun = "manual MM",
mapping = list(
substrate = "a",
product = "b",
Vf = 0.1,
Kms = 0.1,
Vr = 0.1,
Kmp = 0.1
)
)
timecourse <- runTimeCourse(1000)
autoplot.copasi_ts(timecourse)
unloadModel()
```
# Quantities as Proxy for Time Course Output
The `runTimeCourse` function only returns data for actual defined entities of the model.
Auxiliarry information like reaction rates can be missing and needs to be added via global quantity assignments.
This example creates a global quantity "reaction rate" to generate data for the main reaction's flux.
```{r}
newModel()
subs_quant <- newGlobalQuantity("substrate concentration", initial_value = 10)
subs_value <- quantity(subs_quant, reference = "Value")
newSpecies("a", type = "assignment", expression = subs_value)
newReaction("a = b", fun = "Reversible Michaelis-Menten")
runTC(1000)$result
newGlobalQuantity(
"reaction rate",
type = "assignment",
expression = reaction("a = b", reference = "Flux")
)
runTimeCourse(1000)$result
unloadModel()
```