R/dynamics_relevant_functions.R
simulate_sc_dynamics.RdSimulates cell population dynamics using a Gillespie algorithm, tracking births, deaths, transitions between cell types, and mutations on chromosomes. This function models cell growth with logistic constraints and generates detailed lineage information.
simulate_sc_dynamics(
initial_population,
max_steps,
intrinsic_birth_rates,
intrinsic_death_rates,
edge_transition_rates,
clone_capacity,
chr_lengths,
mutation_rate
)Named numeric vector specifying the initial count for each clone type
Maximum number of simulation steps to perform
Named numeric vector of birth rates for each clone type
Named numeric vector of death rates for each clone type
Data frame with columns: parent, child, rate - specifying transitions between clone types
Numeric value representing the carrying capacity of the system of each clone
Nested list structure defining chromosome lengths for each clone and haplotype
Probability of mutation occurring during cell division
A list containing:
population_history: Data frame tracking population counts over time
time_history: Vector of time points corresponding to population_history
cell_info: Data frame with detailed lineage information for each cell
mutation_info: Data frame recording mutation events that occurred during simulation
The simulation implements a Gillespie algorithm with three possible events:
Birth: A cell divides into two daughter cells with possible mutations
Death: A cell dies and is removed from the population
Transition: A cell changes from one clone type to another
Birth rates are modulated by logistic growth constraints based on total population and clone capacity. The simulation tracks detailed lineage information including parent-child relationships, birth and death times for each cell, and mutation events.
The simulation stops when either max_steps is reached or the total event rate becomes zero.