babette: BEAUti 2, BEAST2 and Tracer for R

Richel J.C. Bilderbeek

2019-11-26

This vignette does the same as the code in the bioRxiv article.

library(babette)
mcmc <- create_mcmc(chain_length = 2000, store_every = 1000)
if (is_beast2_installed()) {
  out <- bbt_run(
    fasta_filename = "anthus_aco.fas", 
    mcmc = mcmc
  )
}
if (is_beast2_installed()) {
  out <- bbt_run(
    "anthus_aco.fas",
    site_model = create_hky_site_model(),
    clock_model = create_rln_clock_model(),
    tree_prior = create_bd_tree_prior(),
    mcmc = mcmc
  )
}
# Currently, support for multiple alignments has been deprecated
if (is_beast2_installed()) {
  out <- bbt_run(
    "anthus_aco.fas",
    tree_prior = create_yule_tree_prior(
      birth_rate_distr = create_exp_distr()    
    ),
    mcmc = mcmc
  )
}
if (is_beast2_installed()) {
  out <- bbt_run(
    "anthus_aco.fas",
    tree_prior = create_yule_tree_prior(
      birth_rate_distr = create_exp_distr(
        mean = 1.0
      )    
    ),
    mcmc = mcmc
  )
}
# Deprecated
out <- bbt_run(
  "anthus_aco.fas",
  posterior_crown_age = 15,
  mcmc = mcmc
)
if (is_beast2_installed()) {
  out <- bbt_run(
    "anthus_aco.fas",
    mrca_prior = create_mrca_prior(
      alignment_id = get_alignment_id("anthus_aco.fas"),
      taxa_names = get_taxa_names("anthus_aco.fas"),
      mrca_distr = create_normal_distr(
        mean = 15.0,
        sigma = 0.01
      )
    ),
    mcmc = mcmc,
    overwrite = TRUE
  )
}
if (is_beast2_installed()) {
  traces <- remove_burn_ins(
    traces = out$estimates, 
    burn_in_fraction = 0.2
  )
}
if (is_beast2_installed()) {
  esses <- calc_esses(
    traces = traces, 
    sample_interval = 1000
  )
}
if (is_beast2_installed()) {
  sum_stats <- calc_summary_stats(
    traces = traces, 
    sample_interval = 1000
  )
}
if (is_beast2_installed()) {
  plot_densitree(phylos = out$anthus_aco_trees)
}