-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model 1B.Rmd
110 lines (96 loc) · 2.9 KB
/
Model 1B.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
---
output: html_document
editor_options:
chunk_output_type: console
---
```{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 = 17,
MDM2 = 10
)
# Define parameters
parms <- c(
CP_DD = 8.89550362,
CD_DD = 2.82600077,
CP_p53 = 5.47504722,
dephos = 9.03410545,
phos = 6.88752248,
CD_p53 = 9.03410545,
CD_p53_MDM2 = 4.61270449,
CD_p53P = 3.45737907,
CD_p53P_MDM2 = 8.55691123,
CP_MDM2 = 1.26171641,
CD_MDM2 = 8.94995013,
CD_MDM2_p53P = 8.97424401
)
# 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")
)
# Simulate the model
out <- ssa(
initial_state = ini_state,
reactions = reactions,
params = parms,
method = ssa_exact(),
final_time = 24,
census_interval = 0.01,
verbose = TRUE,
sim_name = "p53P_model"
)
data.frame(out$state, time = out$time)
}
# 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 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")
ggplot(p53P_results, aes(x = time, y = avg_value)) +
geom_smooth(colour="red") +
labs(title = "Average phosforylated p53 concentration",
x = "time",
y = "Average p53P")
```