R/dynamics_relevant_functions.R
pick_transition.RdSelects a specific transition event between clone types based on the current population and edge transition rates, then updates the transition rate matrix to prevent the same transition from occurring again.
pick_transition(population, edge_transition_rates)A list containing:
transition_clone: Character string representing the name of the target clone type (the clone to which the cell transitions)
edge_transition_rates: Updated data frame of transition rates with the selected transition's rate set to zero
This function implements the transition selection step in the Gillespie algorithm for cell clone type transitions. The probability of selecting a particular transition is proportional to the population of the parent clone multiplied by the transition rate. After selection, the transition rate for the selected transition is set to zero, indicating it can only occur once in the simulation.
# Population counts
pop <- c(A = 100, B = 50, C = 30)
# Define transition matrix
transitions <- data.frame(
parent = c("A", "B", "A"),
child = c("B", "C", "C"),
rate = c(0.01, 0.02, 0.005)
)
# Select and process a transition event
result <- pick_transition(pop, transitions)
#> Warning: restarting interrupted promise evaluation
#> Warning: internal error -3 in R_decompress1
#> Error: lazy-load database '/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/cancerSimCraft/R/cancerSimCraft.rdb' is corrupt
result$transition_clone # The selected target clone
#> Error: object 'result' not found
result$edge_transition_rates # Updated transition matrix
#> Error: object 'result' not found