Coalescent.jl
Index
Coalescent.CoalescentCoalescent.ModelFGYCoalescent.ModelFGYCoalescent.ModelFGYCoalescent.SampleConfigurationCoalescent.SampleConfigurationCoalescent.SampleConfigurationCoalescent.SimTreeCoalescent.SimTreeCoalescent.SimTreeCoalescent.SimTreeCoalescent.SimTreeCoalescent.SimTreeCoalescent.distancematrixCoalescent.solveodesCoalescent.solveodesCoalescent.tonewickCoalescent.tonewick
Coalescent.Coalescent — Module
Coalescent
Coalescent simulation and analysis with flexible markup of demographic processes and sampling patterns.
This module provides tools for:
- Simulating coalescent trees
- Handling structured population models
- Solving ordinary differential equations for population dynamics
- Managing sample configuration
Functions
Coalescent.SimTree — Type
SimTreeRepresents a simulated coalescent tree.
Fields
parent::Array{Union{Nothing,Int}}: Parent nodeschild::Array{Union{Nothing,Int}}: Child nodesn::Int: Number of tipsnNode::Int: Number of internal nodesedgelength::Array{Union{Nothing,Float64}}: Edge lengthsheights::Array{Union{Nothing,Float64}}: Node heightstiplabs::Array{Union{Nothing,String}}: Tip labelsshs::Array{Union{Nothing,Float64}}: Sample heightsdescendants::Union{Nothing,BitMatrix}: Descendant matrixdaughters::Union{Nothing,Vector{Tuple{Int, Int, Int, Int}}}: Daughter nodesdemes::Union{Nothing,Vector{String}}: Demes for each node
Coalescent.tonewick — Function
tonewick(o)Convert a SimTree to a Newick format string.
Arguments
o::SimTree: The SimTree to convert
Returns
String: Newick format representation of the tree
Coalescent.ModelFGY — Type
ModelFGYRepresents a structured Forward-in-time Genealogy (FGY) model for coalescent simulations.
Fields
modelname::String: Name of the modelbirthrxn::Array{Reaction}: Birth reactions in the modelmigrationrxn::Array{Reaction}: Migration reactions in the modeldeathrxn::Array{Reaction}: Death reactions in the modelnondemerxn::Array{Reaction}: Non-deme reactions in the modeldemes::Array{String}: Names of demes in the modelnondemes::Union{Nothing,Array{String}}: Names of non-deme variablesnumberdemes::Int: Number of demesnumbernondemes::Int: Number of non-deme variablesinitial::Dict{String,Number}: Initial conditions for variablest0::Float64: Initial timetfin::Float64: Final timeparameters::Union{Nothing,Dict{String,Number}}: Model parametershelperexprs::Union{Nothing,Array{Expr}}: Helper expressions for the model
Coalescent.SampleConfiguration — Type
SampleConfigurationRepresents a configuration for sampling in coalescent simulations.
Fields
sconf::Array{Tuple{Union{Nothing,String}, Float64}}: Array of tuples containing deme (or nothing) and sampling time
Coalescent.solveodes — Function
solveodes(model::ModelFGY; odemethod = :(Rosenbrock23()), res::Union{Missing,Int64} = missing)Solve the ordinary differential equations (ODEs) defined by the given model.
Arguments
model::ModelFGY: The structured FGY model containing the ODEs to solve
Keywords
odemethod = :(Rosenbrock23()): The ODE solver method to useres::Union{Missing,Int64} = missing: The number of time points to return in the solution
Returns
ODESolution: The solution of the ODEs
Detailed Function Documentation
SimTree
Coalescent.SimTree — Method
SimTree(Ne::Float64, n::Int64)::SimTreeSimulate a coalescent tree with constant Ne and n samples at time 0, without specifying tmrcaguess.
Arguments
Ne::Float64: Constant effective population sizen::Int64: Number of samples
Returns
SimTree: The simulated coalescent tree
Coalescent.SimTree — Method
SimTree(Ne::Float64, sampletimes::Array{Float64}, p...; tmrcaguess::Union{Nothing,Float64}=nothing, algorithm=ALGO_MARKOV)::SimTreeSimulate a coalescent tree with constant Ne and flexible sampling times.
Arguments
Ne::Float64: Constant effective population sizesampletimes::Array{Float64}: Array of sample timestmrcaguess::Float64: Initial guess for the time to most recent common ancestorp...: Additional parameters (unused for constant Ne)
Keywords
algorithm::String = ALGO_STATIONARY: Algorithm to use for simulation (ALGOSTATIONARY or ALGOMARKOV)
Returns
SimTree: The simulated coalescent tree
Coalescent.SimTree — Method
SimTree(Ne::Function, sampletimes::Array{Float64}, p...; tmrcaguess::Union{Nothing,Float64}=nothing, algorithm=ALGO_STATIONARY)::SimTreeSimulate a coalescent tree with flexible Ne function and sampling times.
Arguments
Ne::Function: Effective population size functionsampletimes::Array{Float64}: Array of sample timestmrcaguess::Float64: Initial guess for the time to most recent common ancestorp...: Additional parameters for the Ne function
Keywords
algorithm::String = ALGO_MARKOV: Algorithm to use for simulation (ALGOSTATIONARY or ALGOMARKOV)
Returns
SimTree: The simulated coalescent tree
Coalescent.SimTree — Method
SimTree(Ne::Function, n::Int64,p...; tmrcaguess::Union{Nothing,Float64}=nothing, algorithm=ALGO_MARKOV)::SimTreeSimulate a coalescent tree with flexible Ne function and n samples at time 0.
Arguments
Ne::Function: Effective population size over time functionn::Int64: Number of samplestmrcaguess::Float64: Initial guess for the time to most recent common ancestorp...: Additional parameters for the Ne function
Keywords
algorithm::String = ALGO_MARKOV: Algorithm to use for simulation (ALGOSTATIONARY or ALGOMARKOV)
Returns
SimTree: The simulated coalescent tree
Coalescent.SimTree — Method
SimTree(model::ModelFGY, sample::SampleConfiguration; computedescendants = false)Simulate a coalescent tree based on a given model and sampling configuration.
Arguments
model::ModelFGY: The structured FGY model to simulatesample::SampleConfiguration: The sampling configuration for the simulation
Keywords
computedescendants::Bool = false: Whether to compute descendants for each nodeodemethod = :(Tsit5()): ODE solver for the cumulative hazard of genealogical events. The hazard does not depend on the ODE state, so the problem is not stiff. Solvers that differentiate with ForwardDiff, such asRosenbrock23()orAutoTsit5(Rosenbrock23()), can fail with aMethodErrorytol::Float64 = 1e-6: Lower bound on deme size relative to the number of lineages, for numerical stability of the rates
Returns
SimTree: A simulated coalescent tree
ModelFGY
Coalescent.ModelFGY — Method
ModelFGY(; confstr::String)Constructor for ModelFGY from a YAML configuration string.
Arguments
confstr::String: String defining model in YAML format
Returns
ModelFGY: The constructed model
Coalescent.ModelFGY — Method
ModelFGY(conffn::String)Constructor for ModelFGY from a YAML configuration file.
Arguments
conffn::String: Path to the YAML configuration file
Returns
ModelFGY: The constructed model
SampleConfiguration
Coalescent.SampleConfiguration — Method
SampleConfiguration(conffn::String)Create a SampleConfiguration from a YAML configuration file.
Arguments
conffn::String: Path to the YAML configuration file
Returns
SampleConfiguration: The constructed sampling configuration
Coalescent.SampleConfiguration — Method
SampleConfiguration(; confstr::String)Create a SampleConfiguration from a YAML configuration string.
Arguments
confstr::String: YAML configuration string defining the sampling scheme
Returns
SampleConfiguration: The constructed sampling configuration
Other Functions
Coalescent.tonewick — Method
tonewick(o)Convert a SimTree to a Newick format string.
Arguments
o::SimTree: The SimTree to convert
Returns
String: Newick format representation of the tree
Coalescent.distancematrix — Method
distancematrix(t)::Matrix{Float64}Compute the distance matrix for a SimTree.
Arguments
t::SimTree: The SimTree to compute distances for
Returns
Matrix{Float64}: The computed distance matrix
Coalescent.solveodes — Method
solveodes(model::ModelFGY; odemethod = :(Rosenbrock23()), res::Union{Missing,Int64} = missing)Solve the ordinary differential equations (ODEs) defined by the given model.
Arguments
model::ModelFGY: The structured FGY model containing the ODEs to solve
Keywords
odemethod = :(Rosenbrock23()): The ODE solver method to useres::Union{Missing,Int64} = missing: The number of time points to return in the solution
Returns
ODESolution: The solution of the ODEs