Title: | Trajectories and Phylogenies Simulator |
---|---|
Description: | Generates stochastic time series and genealogies associated with a population dynamics model. Times series are simulated using the Gillespie exact and approximate algorithms and a new algorithm we introduce that uses both approaches to optimize the time execution of the simulations. Genealogies are simulated from a trajectory using a backwards-in-time based approach. Methods are described in Danesh G et al (2022) <doi:10.1111/2041-210X.14038>. |
Authors: | Gonche Danesh [aut, cre, cph], Emma Saulnier [aut, cph], Olivier Gascuel [aut, cph], Marc Choisy [aut, cph, ths], Samuel Alizon [aut, cph, ths] |
Maintainer: | Gonche Danesh <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.2.3 |
Built: | 2024-11-07 04:58:04 UTC |
Source: | https://github.com/cran/TiPS |
A simulator is built by supplying reactions of the model described by our formalism or described by differential equations The returned function will be used to simulate trajectories, that can further be used to simulate phylogenies.
build_simulator(reactions, functions = NULL)
build_simulator(reactions, functions = NULL)
reactions |
A character vector of reactions describing the input model. |
functions |
A named vector where functions are defined. |
An object of class simulation
, which is a function that can be used to simulate trajectories from the model.
Gonche Danesh
## Not run: # Build a simulator for an SIR model reactions <- c('S [beta * S * I] -> I', 'I [gamma * I] -> R') sir.simu <- build_simulator(reactions = reactions) # Run a simulation of a trajectory sir_traj <- sir.simu(paramValues = c(gamma = 1, beta = 2e-4), initialStates = c(I = 1, S = 9999, R = 0), times = c(0, 20), , method = "exact", seed = 166) # The output is a named list containing the trajectory, the algorithm used, # the parameter values and the reactions of the model. names(sir_traj) # Print head of the simulated trajectory head(sir_traj$traj) # Plot the trajectory plot(sir_traj) ## End(Not run)
## Not run: # Build a simulator for an SIR model reactions <- c('S [beta * S * I] -> I', 'I [gamma * I] -> R') sir.simu <- build_simulator(reactions = reactions) # Run a simulation of a trajectory sir_traj <- sir.simu(paramValues = c(gamma = 1, beta = 2e-4), initialStates = c(I = 1, S = 9999, R = 0), times = c(0, 20), , method = "exact", seed = 166) # The output is a named list containing the trajectory, the algorithm used, # the parameter values and the reactions of the model. names(sir_traj) # Print head of the simulated trajectory head(sir_traj$traj) # Plot the trajectory plot(sir_traj) ## End(Not run)
simutraj
.Plot an object of class simutraj
.
## S3 method for class 'simutraj' plot(x, ...)
## S3 method for class 'simutraj' plot(x, ...)
x |
An object of |
... |
Arguments to be passed to methods, such as graphical parameters |
Gonche Danesh
Simulates a phylogeny using a beackward-in-time process using sampling dates and a trajectory
simulate_tree( simuResults, dates, deme, sampled, root, isFullTrajectory = FALSE, nTrials = 1, addInfos = FALSE, resampling = FALSE, verbose = FALSE, seed = 0, outFile = "", format = "newick" )
simulate_tree( simuResults, dates, deme, sampled, root, isFullTrajectory = FALSE, nTrials = 1, addInfos = FALSE, resampling = FALSE, verbose = FALSE, seed = 0, outFile = "", format = "newick" )
simuResults |
Object of class |
dates |
Contains the sampling dates. Can be a vector (for example using |
deme |
A vector with the compartments that contribute to the simulation of phylogeny. |
sampled |
A named vector with the proportions of sampling for each compartment. This is used in case there are multiple deme compartments where the sampling dates will be randomly associated to a compartment to sample. Sum of |
root |
Name of the compartment from which the phylogeny is rooted. |
isFullTrajectory |
Boolean to define if death events generate or not leaves. By default, |
nTrials |
Integer indicating the number of unsuccessful simulation trials allowed before giving up. |
addInfos |
Boolean to define if each internal node' name will be the reaction. By default, |
resampling |
Boolean to allow a sampled individual to transmit the pathogen once again. By default, |
verbose |
Boolean to allow printing time execution of simulation |
seed |
Seed to initialize the random generator, for better reproducibility. By default, |
outFile |
Output file name to write tree. By default, tree is not written in output file. |
format |
Output tree format if output file is given. Values are either |
An object of class ape::phylo
.
Gonche Danesh
## Not run: # A multi-type birth-death model with birth rate beta, # death rate gamma, mutation rates m1 and m2 # and I1 and I2 the number of infected individuals of each type. # With parameter beta varying over 2 time intervals. reactions <- c("0 [beta1 * I1] -> I1","I1 [gamma1 * I1] -> 0", "I1 [mu1 * I1] -> I2","0 [beta2 * I2] -> I2", "I2 [gamma2 * I2] -> 0","I2 [mu2 * I2] -> I1") BD_simu <- build_simulator(reactions) initialStates <- c(I1 = 0, I2 = 1) times <- c(1975, 1998, 2018) theta <- list(gamma1 = c(0.2, 0.09), gamma2 = 0.1, mu1 = 0.025, mu2 = 0.021, beta1 = c(0.26,0.37), beta2 = 0.414) BDres <- BD_simu(paramValues = theta, initialStates = initialStates, times = times, tau = 0.08, method = "approximate", seed = 994543) # Let's generate 100 sampling dates from 2015 and 2018 dates_bd <- seq(from=2015, to=2018, length.out=100) BD_tree <- simulate_tree(simuResults = BDres, dates = dates, deme = c("I"), sampled = c(I=1), root = "I", isFullTrajectory = FALSE, seed = 973360) BD_tree$seed # Plot the simulated phylogeny using the \code{ape::plot.phylo} function. ape::plot.phylo(BD_tree) ## End(Not run)
## Not run: # A multi-type birth-death model with birth rate beta, # death rate gamma, mutation rates m1 and m2 # and I1 and I2 the number of infected individuals of each type. # With parameter beta varying over 2 time intervals. reactions <- c("0 [beta1 * I1] -> I1","I1 [gamma1 * I1] -> 0", "I1 [mu1 * I1] -> I2","0 [beta2 * I2] -> I2", "I2 [gamma2 * I2] -> 0","I2 [mu2 * I2] -> I1") BD_simu <- build_simulator(reactions) initialStates <- c(I1 = 0, I2 = 1) times <- c(1975, 1998, 2018) theta <- list(gamma1 = c(0.2, 0.09), gamma2 = 0.1, mu1 = 0.025, mu2 = 0.021, beta1 = c(0.26,0.37), beta2 = 0.414) BDres <- BD_simu(paramValues = theta, initialStates = initialStates, times = times, tau = 0.08, method = "approximate", seed = 994543) # Let's generate 100 sampling dates from 2015 and 2018 dates_bd <- seq(from=2015, to=2018, length.out=100) BD_tree <- simulate_tree(simuResults = BDres, dates = dates, deme = c("I"), sampled = c(I=1), root = "I", isFullTrajectory = FALSE, seed = 973360) BD_tree$seed # Plot the simulated phylogeny using the \code{ape::plot.phylo} function. ape::plot.phylo(BD_tree) ## End(Not run)