-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model 2A.Rmd
150 lines (129 loc) · 4.08 KB
/
Model 2A.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
140
141
142
143
144
145
146
147
148
149
```{r}
library(tidyverse)
library(GillespieSSA2)
library(ggplot2)
library(dplyr)
```
```{r echo=TRUE}
#rm(list = ls())
simulations <- function() {
# Define initial states
ini_state <- c(
DD = 10,
p53 = 10,
p53P = 10,
MDM2 = 15,
p21 = 4
)
# Define parameters
parms <- c(
CP_DD = 8.89550362,
CD_DD = 2.82600077,
CP_p53 = 5.47504722,
phos = 6.88752248,
dephos = 9.03410545,
CD_p53 = 9.03410545,
CD_p53_MDM2 = 4.61270449,
CD_p53P = 3.45737907,
CD_p53P_MDM2 = 8.55691123,
CP_MDM2 = 0.06171641,
CD_MDM2 = 8.94995013,
CD_MDM2_p53P = 8.97424401,
CP_p21 = 2.822643,
CD_p21 = 3.057379
)
# Define reactions
reactions <- list(
reaction(~CP_DD, c(DD = +1), name = "Prod_DD"),
reaction(~CD_DD * p53P * DD, c(DD = -1), name = "Decay_DD"),
reaction(~CP_p53 * DD, c(p53 = +1), name = "Prod_p53"),
reaction(~CD_p53 * p53, c(p53 = -1), name = "Decay_p53"),
reaction(~CD_p53_MDM2 * p53 * MDM2, c(p53 = -1), name = "Inhibition_p53_MDM2"),
reaction(~phos * p53 * DD, c(p53 = -1, p53P = +1), name = "Phos_p53"),
reaction(~dephos * p53P, c(p53P = -1, p53 = +1), name = "Dephos_p53P"),
reaction(~CD_p53P * p53P, c(p53P = -1), name = "Decay_p53P"),
reaction(~CD_p53P_MDM2 * p53P * MDM2, c(p53P = -1), name = "Inhibition_p53P_MDM2"),
reaction(~CP_MDM2 * p53P, c(MDM2 = +1), name = "Prod_MDM2"),
reaction(~CD_MDM2 * MDM2, c(MDM2 = -1), name = "Decay_MDM2"),
reaction(~CP_p21 * p53P, c(p21 = +1), name = "Prod_p21"),
reaction(~CD_p21 * p21, c(p21 = -1), name = "Decay_p21")
)
# Simulate the model
out <- ssa(
initial_state = ini_state,
reactions = reactions,
params = parms,
method = ssa_exact(),
final_time = 24,
census_interval = 0.001,
verbose = TRUE,
sim_name = "p21_no_mRNA_model"
)
data.frame(out$state, time = out$time) # Storing the data in a data frame
}
# Run the simulation multiple times and store results
num_runs <- 1
results_list <- vector("list", num_runs)
for (i in 1:num_runs) {
results_list[[i]] <- simulations()
}
# Combine and average results
combined_results <- bind_rows(results_list, .id = "run")
# Reshape data to long format, which is more suitable for averaging
long_results <- combined_results %>%
pivot_longer(cols = -c(run, time), names_to = "variable", values_to = "value")
# Calculate average values for each variable at each time point
avg_results <- long_results %>%
group_by(time, variable) %>%
summarise(avg_value = mean(value), .groups = 'drop')
# Plot the averaged results for all variables
ggplot(avg_results, aes(x = time, y = avg_value, color = variable)) +
geom_smooth() +
labs(title = "Averaged SSA Simulation Results",
x = "Time",
y = "Average Value")
```
```{r echo=TRUE}
# Plotting a single variable in this case p53P
# Extract only the p53P variable columns
p53P_results <- avg_results %>%
filter(variable == "p53P")
# Create the plot of the data subset
ggplot(p53P_results, aes(x = time, y = avg_value)) +
geom_smooth(colour="blue") +
labs(title = "Average phosforylated p53 concentration",
x = "Time",
y = "Average p53P")
```
```{r}
# Plotting a single variable in this case p53P
# Extract only the p53P variable columns
p21_results <- avg_results %>%
filter(variable == "p21")
# Create the plot of the data subset
ggplot(p21_results, aes(x = time, y = avg_value)) +
geom_smooth(colour="red") +
labs(title = "Average p21 concentration",
x = "Time",
y = "Average p21")
```
```{r}
ggplot(p53P_results, aes(x = time, y = avg_value)) +
geom_line(colour="blue") +
labs(title = "Average phosphorylated p53 concentration",
x = "Time",
y = "Average p53P")
ggplot(p21_results, aes(x = time, y = avg_value)) +
geom_line(colour="red") +
labs(title = "Average p21 protein concentration",
x = "Time",
y = "Average p21 protein")
```
```{r}
# Plot the averaged results for all variables
ggplot(avg_results, aes(x = time, y = avg_value, color = variable)) +
geom_smooth() +
labs(title = "Averaged SSA Simulation Results",
x = "Time",
y = "Average Value")
```