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 #2: fixed crown age

Using all default settings, only specify a DNA alignment.

[No screenshot, as this cannot be done in BEAUti yet]
create_beast2_input_file_1_12(
  "my_fasta.fas",
  "my_beast.xml",
  fixed_crown_age = TRUE,
  initial_phylogenies = fasta_to_phylo(
    fasta_filename = "my_fasta.fas",
    crown_age = 15)
)
create_beast2_input_file(
  "my_fasta.fas",
  "my_beast.xml",
  posterior_crown_age = 15
)

fasta_to_phylo creates a random phylogeny from a FASTA file of a certain crown age.

Example #3: JC69 site model

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

Example #4: Relaxed clock log normal

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

Example #5: Birth-Death tree prior

create_beast2_input_file(
  "my_alignment.fas",
  "my_beast.xml",
  tree_priors = 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_priors = 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_models = 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_models = create_strict_clock_model(
    clock_rate_param = create_clock_rate_param(value = 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_priors = create_mrca_prior(
    alignment_id = get_alignment_id("my_alignment.fas"),
    taxa_names = get_taxa_names("my_alignment.fas")
  )
)
create_beast2_input_file(
  "my_alignment.fas",
  "my_beast.xml",
  mrca_priors = create_mrca_prior(
    alignment_id = get_alignment_id("my_alignment.fas"),
    taxa_names = get_taxa_names("my_alignment.fas"),
    mrca_distr = create_normal_distr(
      mean = create_mean_param(value = 10.0),
      sigma = create_sigma_param(value = 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_priors = create_mrca_prior(
    alignment_id = get_alignment_id("my_alignment.fas"),
    taxa_names = get_taxa_names("my_alignment.fas"),
    is_monophyletic = TRUE,
    mrca_distr = create_normal_distr(
      mean = create_mean_param(value = crown_age),
      sigma = create_sigma_param(value = 0.001)
    )
  )
)

Example #11: Two alignments

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

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

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")
  )
)

From v1.14, 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.