Skip to contents

This method simulates cell evolution until a formula does not hold.

Arguments

formula

The formula that will be satisfied at the end of the simulation.

quiet

An optional Boolean flag to avoid the progress bar (default: FALSE).

Examples

# set the seed of the random number generator
set.seed(0)

# create a simulation
sim <- SpatialSimulation()
sim$add_mutant(name = "A",
               epigenetic_rates = c("+-" = 0.01, "-+" = 0.01),
               growth_rates = c("+" = 0.2, "-" = 0.08),
               death_rates = c("+" = 0.1, "-" = 0.01))
sim$place_cell("A+", 500, 500)

# get the variable representing the simulation time
v_time <- sim$var("Time")

# get the variable representing the cardinality of A+
va_p <- sim$var("A+")

# get the variable representing the cardinality of A-
va_m <- sim$var("A-")

# get the variable representing the number of epigenetic
# switches from A+
va_ps <- sim$var("A+.switches")

# build a condition stating that the cardinality of A+ doubles
# that of A-
c1 <- va_p >= 2*va_m

# build a condition that holds when there are more than
# 100000 live cells of mutant A
c2 <- va_p + va_m > 1e5

# build a condition that holds when less than 4000 switched
# from A+ have occured
c3 <- va_ps < 4000

# build a condition that holds when 40 time unit have been
# simulated at least
c4 <- v_time >= 40

# build a condition that holds when c4 and at least one
# among c1, c2, and c3 hold
c5 <- c4 & (c1 | c2 | c3)
c5
#> Time>=40 and (|A+|>=2*|A-| or |A+|+|A-|>100000 or 4000>|A+.switches|)

# run the simulation while c5 does not hold
sim$run_until(c5)
#> 
 [████████████████████████████████████████] 100% [00m:00s] Saving snapshot                                        


sim
#> ──  rRACES   D   S   M  /var/folders/tb/jqmdpgxs2t5129bny6pb96680000gn/T/rRACES_alberto_17b95e2a ─────────────────
#> 
#> ── Species: 2, with epigenetics 
#>    
#>    =======  ====  ====  ====  ======  ===
#>    species   λ      δ    ε    counts   % 
#>    =======  ====  ====  ====  ======  ===
#>         A-  0.08  0.01  0.01    30    75 
#>         A+  0.20  0.10  0.01    10    25 
#>    =======  ====  ====  ====  ======  ===
#> 
#> ── Firings: 73 total 
#> 
#> 	Species [A-]:  5 (deaths), 37 (duplications) and  5 (switches)
#> 	Species [A+]:  8 (deaths), 15 (duplications) and  3 (switches)
#>  The simulation has no samples yet!
sim$get_clock()
#> [1] 40.34598