MitoDrift R6 Class
MitoDrift R6 Class
Public fields
tree_initInitial phylogenetic tree (ape::phylo)
ATransition matrix
leaf_likelihoodsList of leaf likelihoods
logAVector of log transition probabilities
logPList of log probabilities
model_paramsNamed vector containing model parameters (eps, err, npop, ngen, k)
amatAlternative allele count matrix
dmatTotal depth matrix
vmatVAF matrix
mcmc_traceMCMC trace for parameter fitting
tree_listList of trees from optimization
tree_mlMaximum likelihood tree
tree_annotAnnotated tree with clade frequencies
ml_trace_fileFile path for ML trace
mcmc_trace_fileFile path for MCMC trace
mcmc_diag_fileFile path for MCMC diagnostics
param_trace_fileFile path for parameter fitting trace
Methods
Method new()
Initialize MitoDrift object
Usage
MitoDrift$new(
mut_dat = NULL,
amat = NULL,
dmat = NULL,
model_params = NULL,
build_tree = TRUE,
ncores = 1
)Arguments
mut_datMutation data in long format (data.frame with columns: variant, cell, d, a)
amatAlternative allele count matrix (optional, if mut_dat not provided)
dmatTotal depth matrix (optional, if mut_dat not provided)
model_paramsModel parameters (optional)
build_treeWhether to build an initial NJ tree (default: TRUE)
ncoresNumber of cores used when building the initial NJ tree (default: 1)
Method print()
Print object summary
Prints a summary of the MitoDrift object including data dimensions, tree information, model parameters, and available components.
Method fit_params_em()
Fit tree parameters using Expectation-Maximization (EM) algorithm
Arguments
tree_fitTree to fit parameters to
initial_paramsInitial parameter values (ngen, log_eps, log_err)
lower_boundsLower bounds for parameters in transformed space
upper_boundsUpper bounds for parameters in transformed space
max_iterMaximum number of EM iterations (default: 10)
epsilonConvergence threshold (default: 1e-3)
ncoresNumber of cores to use (default: 3)
traceWhether to return trace of parameter values (default: TRUE)
Method optimize_tree()
Optimize tree using C++ implementation
Usage
MitoDrift$optimize_tree(
max_iter = 100,
ncores = 1,
outfile = NULL,
resume = FALSE,
trace_interval = 5
)Method run_mcmc()
Run phylogenetic MCMC sampling
Usage
MitoDrift$run_mcmc(
max_iter = 10000,
conv_thres = NULL,
nchains = 1000,
ncores = 1,
ncores_qs = 1,
batch_size = 1000,
outfile = NULL,
resume = FALSE,
diag = TRUE,
use_nj = FALSE,
diagfile = NULL
)Arguments
max_iterMaximum number of MCMC iterations (default: 10000)
conv_thresConvergence threshold for ASDSF (default: NULL)
nchainsNumber of MCMC chains (default: 1000)
ncoresNumber of cores to use (default: 1)
ncores_qsNumber of cores to use for QS operations (default: 1)
batch_sizeBatch size for MCMC (default: 1000)
outfileOutput file for saving results (optional)
resumeWhether to resume from existing file (default: FALSE)
diagWhether to compute ASDSF diagnostics (default: TRUE)
use_njWhether to use NJ tree instead of ML tree as initial tree (default: FALSE)
diagfileFile path for saving ASDSF diagnostics (RDS)
Method annotate_tree()
Trim tree using MCMC results
Usage
MitoDrift$annotate_tree(
burnin = 0,
max_iter = 1e+08,
use_nj = FALSE,
ncores = 1,
ncores_qs = 1,
mcmc_trace_file = NULL
)Arguments
burninNumber of burnin iterations (default: 0)
max_iterMaximum iteration to include (default: 1e8)
use_njWhether to use NJ tree instead of ML tree (default: FALSE)
ncoresNumber of cores to use (default: 1)
ncores_qsNumber of cores to use for QS operations (default: 1)
mcmc_trace_fileMCMC result file (optional, uses stored file if NULL)
Method copy()
Create a copy of a MitoDrift object with updated structure
This method creates a new MitoDrift instance with the same data but updated class structure. Useful for refreshing objects created with older versions of the code.