Examples

For all examples, do load beautier:

library(beautier)

All examples read the alignment from a FASTA file (usually my_fasta.fas) and create a BEAST2 input file called my_beast.xml.

Example #1: all default

Using all default settings, only specify a DNA alignment.

create_beast2_input_file(
  "test_output_0.fas",
  "my_beast.xml"
)

All other parameters are set to their defaults, as in BEAUti.

Example #3: JC69 site model

create_beast2_input_file(
  "my_alignment.fas",
  "my_beast.xml",
  site_model = create_jc69_site_model()
)

Example #4: Relaxed clock log normal

create_beast2_input_file(
  "my_alignment.fas",
  "my_beast.xml",
  clock_model = create_rln_clock_model()
)

Example #5: Birth-Death tree prior

create_beast2_input_file(
  "my_alignment.fas",
  "my_beast.xml",
  tree_prior = create_bd_tree_prior() 
)

Example #6: Yule tree prior with a normally distributed birth rate

create_beast2_input_file(
  "my_alignment.fas",
  "my_beast.xml",
  tree_prior = create_yule_tree_prior(
    birth_rate_distr = create_normal_distr()
  ) 
)

Thanks to Yacine Ben Chehida for this use case

Example #7: HKY site model with a non-zero proportion of invariants

create_beast2_input_file(
  "my_alignment.fas",
  "my_beast.xml",
  site_model = create_hky_site_model(
    gamma_site_model = create_gamma_site_model(prop_invariant = 0.5)
  )
)

Thanks to Yacine Ben Chehida for this use case

Example #8: Strict clock with a known clock rate

create_beast2_input_file(
  "my_alignment.fas",
  "my_beast.xml",
  clock_model = create_strict_clock_model(
    clock_rate_param = 0.5
  ) 
)

Thanks to Paul van Els and Yacine Ben Chehida for this use case.

Example #9: Use MRCA prior

Since v1.13 it is supported to specify an MRCA ('Most Recent Common Ancestor') prior.

create_beast2_input_file(
  "my_alignment.fas",
  "my_beast.xml",
  mrca_prior = create_mrca_prior()
)
create_beast2_input_file(
  "my_alignment.fas",
  "my_beast.xml",
  mrca_prior = create_mrca_prior(
    mrca_distr = create_normal_distr(
      mean = 10.0,
      sigma = 0.01
    )
  )
)

Example #10: Use MRCA prior to specify a close-to-fixed crown age

Since v1.13 it is supported to specify an MRCA ('Most Recent Common Ancestor') prior.

With an MRCA prior, it is possible to specify a close-to-fixed crown age:

crown_age <- 15
create_beast2_input_file(
  "my_alignment.fas",
  "my_beast.xml",
  mrca_prior = create_mrca_prior(
    is_monophyletic = TRUE,
    mrca_distr = create_normal_distr(
      mean = crown_age,
      sigma = 0.001
    )
  )
)

Example #11: Two alignments

# Deprecated support for now
if (1 == 2) {
  create_beast2_input_file(
    c("anthus_aco.fas", "anthus_nd2.fas"),
    "my_beast.xml"
  )
}

Thanks to Paul van Els for this use case and supplying these FASTA files.

Example #12: Two alignments, different site models

# Deprecated support for now
beautier::create_beast2_input_file(
  c("anthus_aco.fas", "anthus_nd2.fas"),
  "my_beast.xml",
  site_models = list(
    create_hky_site_model(), 
    create_tn93_site_model()
  )
)

Since v1.12 this it is supported to have two alignments with different site models, clock models and tree priors.

Thanks to Paul van Els for this use case.

Example #13: Two alignments, shared clock model

# Deprecated support for now
if (1 == 2) {
  beautier::create_beast2_input_file(
    c("anthus_aco.fas", "anthus_nd2.fas"),
    "my_beast.xml",
    clock_models = list(
      create_strict_clock_model(id = "anthus_aco"), 
      create_strict_clock_model(id = "anthus_aco")
    )
  )
}

In a future version, it will be supported to have two alignments with shared site models, clock models and tree priors.

Thanks to Yacine Ben Chehida for this use case.