-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model 2A GA optimialisation.Rmd
93 lines (75 loc) · 2.63 KB
/
Model 2A GA optimialisation.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
```{r}
library(tidyverse)
library(GillespieSSA2)
library(GA)
library(doParallel)
```
```{r}
rm(list = ls()) # clear environment
# Define initial states
ini_state <- c(
DD = 10,
p53 = 10,
p53P = 17,
MDM2 = 10,
p21 = 4
)
param_names <- c("CP_DD", "CD_DD", "CP_p53", "CD_p53", "CD_p53_MDM2", "phos", "dephos", "CD_p53P", "CD_p53P_MDM2", "CP_MDM2", "CD_MDM2", "CP_p21", "CD_p21")
# Define the new objective function based on p21 protein levels
objective_function <- function(params) {
names(params) <- param_names
reactions1 <- list(
reaction(~params["CP_DD"], c(DD = +1), name = "Prod_DD"),
reaction(~params["CD_DD"] * p53P, c(DD = -1), name = "Decay_DD"),
reaction(~params["CP_p53"] * DD, c(p53 = +1), name = "Prod_p53"),
reaction(~params["CD_p53"] * p53, c(p53 = -1), name = "Decay_p53"),
reaction(~params["CD_p53_MDM2"] * p53 * MDM2, c(p53 = -1), name = "Inhibition_p53_MDM2"),
reaction(~params["phos"] * p53 * DD, c(p53 = -1, p53P = +1), name = "Phos_p53"),
reaction(~params["dephos"] * p53P, c(p53P = -1, p53 = +1), name = "Dephos_p53P"),
reaction(~params["CD_p53P"] * p53P, c(p53P = -1), name = "Decay_p53P"),
reaction(~params["CD_p53P_MDM2"] * p53P * MDM2, c(p53P = -1), name = "Inhibition_p53P_MDM2"),
reaction(~params["CP_MDM2"] * p53, c(MDM2 = +1), name = "Prod_MDM2"),
reaction(~params["CD_MDM2"] * DD * MDM2, c(MDM2 = -1), name = "Decay_MDM2"),
reaction(~params["CP_p21"] * p21_mRNA, c(p21 = +1), name = "Prod_p21"),
reaction(~params["CD_p21"] * p21, c(p21 = -1), name = "Decay_p21")
)
out <- ssa(
initial_state = ini_state,
reactions = reactions1,
params = params,
method = ssa_exact(),
final_time = 24,
census_interval = .01,
verbose = FALSE
)
# Extract p21 data
p21_data <- out %>% filter(variable == "p21")
# Calculate the objective metric based on desired behavior
oscillation_metric <- sd(p21_data$value)
trend_metric <- mean(diff(p21_data$value))
combined_metric <- oscillation_metric + abs(trend_metric)
return(-combined_metric)
}
```
```{r}
# Define parameter bounds
lower_bounds <- c(0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001)
upper_bounds <- c(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10)
# Run the Genetic Algorithm optimization
ga_result <- ga(
type = "real-valued",
fitness = objective_function,
lower = lower_bounds,
upper = upper_bounds,
popSize = 100,
maxiter = 100,
run = 100,
keepBest = TRUE,
parallel = TRUE,
seed = 123
)
# Extract the best parameter set
best_params <- ga_result@solution
# Print the best parameters
print(best_params)
```