This method computes the forest sticks.
Arguments
- birth_threshold
The maximum birth time for the cells associated to the returned sticks (optional).
Value
The list of the forest sticks whose associated cells have
birth time smaller than or equal to birth_threshold
. Each stick is
represented as the list of cell identifiers labelling the nodes in the
stick from the higher to the deeper in the forest.
Details
A crucial node of a forest is a root of the forest, a node whose parent belongs to a different species, or the most recent common ancestor of two crucial nodes.
A stick is a path of the forest in which the only crucial nodes are the first and the last one.
This method return the list of the forest sticks. Each stick is represented by the sequence of cell identifiers labelling the nodes in the stick.
Examples
# set the seed of the random number generator
set.seed(0)
# create a simulation
sim <- SpatialSimulation()
sim$add_mutant(name = "A", growth_rate = 0.2,
death_rate = 0.01)
sim$place_cell("A", 500, 500)
sim$death_activation_level <- 100
sim$run_up_to_size(species = "A", num_of_cells = 100)
#>
[████████████████████████████████████████] 100% [00m:00s] Saving snapshot
sim$get_clock()
#> [1] 30.11838
sim$add_mutant(name = "B", growth_rate = 0.3, death_rate = 0.01)
sim$mutate_progeny(sim$choose_cell_in("A"), "B")
sim$run_up_to_size(species = "B", num_of_cells = 120)
#>
[████████████████████████████████████████] 100% [00m:00s] Saving snapshot
sim$get_clock()
#> [1] 52.1231
sim$add_mutant(name = "C", growth_rate = 0.3, death_rate = 0.01)
sim$mutate_progeny(sim$choose_cell_in("B"), "C")
sim$run_up_to_size(species = "C", num_of_cells = 200)
#>
[█████████████---------------------------] 32% [00m:00s] Cells: 64193
[█████████████████████-------------------] 50% [00m:01s] Cells: 99605
[██████████████████████████--------------] 63% [00m:02s] Cells: 130290
[███████████████████████████████---------] 75% [00m:03s] Cells: 155825
[█████████████████████████████████████---] 90% [00m:04s] Cells: 178743
[███████████████████████████████████████-] 97% [00m:05s] Cells: 198669
[████████████████████████████████████████] 100% [00m:05s] Saving snapshot
# search for a 33x33 region containing 50 cells in A and
# 50 cells in B at least and sample it
region <- sim$search_sample(c(A = 50, B = 50), 33, 33)
sim$sample_cells("S1", region$lower_corner, region$upper_corner)
# search for a 33x33 region containing 50 cells in B and
# 50 cells in C at least and sample it
region <- sim$search_sample(c(B = 50, C = 50), 33, 33)
sim$sample_cells("S2", region$lower_corner, region$upper_corner)
# build the samples forest
forest <- sim$get_samples_forest()
# search for the forest sticks
forest$get_sticks()
#> [[1]]
#> [1] 199 241 297 458 508 758 847 1043 1198 1485 1612 1665
#>
#> [[2]]
#> [1] 0 2 5 11 16 20 36 52 80 184 199
#>
# search for the forest sticks whose corresponding cells have
# birth times 40 time units at most
forest$get_sticks(40)
#> [[1]]
#> [1] 0 2 5 11 16 20 36 52 80 184 199
#>