beastier demo

Richèl J.C. Bilderbeek

2021-08-18

Introduction

This vignette demonstrates how to use beastier.

First, load the library:

library(beastier)

Also, we’ll load the testthat library, to verify the statements in this vignette:

library(testthat)

To run BEAST2, we need to create a BEAST2 options structure`. We will use a supplied BEAST2 XML file. For the rest, we’ll use the default options:

beast2_options <- create_beast2_options(
  input_filename = get_beastier_path("2_4.xml")
)
names(beast2_options)
#> [1] "input_filename"        "output_state_filename" "rng_seed"             
#> [4] "n_threads"             "use_beagle"            "overwrite"            
#> [7] "beast2_path"           "verbose"

Before running BEAST2, the BEAST2 input file must exist, and we expect no output file to be created just yet:

expect_true(file.exists(beast2_options$input_filename))
expect_false(file.exists(beast2_options$output_state_filename))

We can run beastier now, if BEAST2 is installed. Because BEAST2 needs to be installed by the user, this vignette checks if it is installed in every step:

if (is_beast2_installed()) {
  output <- run_beast2_from_options(beast2_options)
}

If beastier has run BEAST2, the BEAST2 output can be shown:

if (is_beast2_installed()) {
  print(output)
}
#>   [1] ""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>   [2] "                        BEAST v2.6.4, 2002-2021"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
#>   [3] "             Bayesian Evolutionary Analysis Sampling Trees"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
#>   [4] "                       Designed and developed by"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>   [5] " Remco Bouckaert, Alexei J. Drummond, Andrew Rambaut & Marc A. Suchard"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#>   [6] "                                    "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>   [7] "                   Centre for Computational Evolution"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
#>   [8] "                         University of Auckland"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
#>   [9] "                       r.bouckaert@auckland.ac.nz"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
#>  [10] "                        alexei@cs.auckland.ac.nz"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>  [11] "                                    "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>  [12] "                   Institute of Evolutionary Biology"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>  [13] "                        University of Edinburgh"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
#>  [14] "                           a.rambaut@ed.ac.uk"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#>  [15] "                                    "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>  [16] "                    David Geffen School of Medicine"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
#>  [17] "                 University of California, Los Angeles"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#>  [18] "                           msuchard@ucla.edu"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#>  [19] "                                    "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>  [20] "                      Downloads, Help & Resources:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
#>  [21] "                           http://beast2.org/"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#>  [22] "                                    "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>  [23] "  Source code distributed under the GNU Lesser General Public License:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#>  [24] "                   http://github.com/CompEvol/beast2"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>  [25] "                                    "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>  [26] "                           BEAST developers:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#>  [27] "   Alex Alekseyenko, Trevor Bedford, Erik Bloomquist, Joseph Heled, "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>  [28] " Sebastian Hoehna, Denise Kuehnert, Philippe Lemey, Wai Lok Sibon Li, "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#>  [29] "Gerton Lunter, Sidney Markowitz, Vladimir Minin, Michael Defoin Platel, "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
#>  [30] "          Oliver Pybus, Tim Vaughan, Chieh-Hsi Wu, Walter Xie"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#>  [31] "                                    "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>  [32] "                               Thanks to:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
#>  [33] "          Roald Forsberg, Beth Shapiro and Korbinian Strimmer"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#>  [34] ""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>  [35] "Writing state to file /home/richel/.cache/beastier/beast2_1bd825c874f68.xml.state"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
#>  [36] "Random number seed: 1629291660550"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
#>  [37] ""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>  [38] "t1: 20 4"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
#>  [39] "t2: 20 4"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
#>  [40] "t3: 20 4"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
#>  [41] "t4: 20 4"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
#>  [42] "t5: 20 4"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
#>  [43] "Alignment(test_output_0)"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
#>  [44] "  5 taxa"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
#>  [45] "  20 sites"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
#>  [46] "  16 patterns"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#>  [47] ""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>  [48] "TreeLikelihood(treeLikelihood.test_output_00) uses BeerLikelihoodCore4"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#>  [49] "  Alignment(test_output_0): [taxa, patterns, sites] = [5, 16, 20]"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
#>  [50] "==============================================================================="                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
#>  [51] "Citations for this model:"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
#>  [52] ""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>  [53] "Bouckaert, Remco, Timothy G. Vaughan, Joëlle Barido-Sottani, Sebastián Duchêne, Mathieu Fourment, "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
#>  [54] "Alexandra Gavryushkina, Joseph Heled, Graham Jones, Denise Kühnert, Nicola De Maio, Michael Matschiner, "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
#>  [55] "Fábio K. Mendes, Nicola F. Müller, Huw A. Ogilvie, Louis du Plessis, Alex Popinga, Andrew Rambaut, "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
#>  [56] "David Rasmussen, Igor Siveroni, Marc A. Suchard, Chieh-Hsi Wu, Dong Xie, Chi Zhang, Tanja Stadler, "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
#>  [57] "Alexei J. Drummond "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
#>  [58] "  BEAST 2.5: An advanced software platform for Bayesian evolutionary analysis. "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
#>  [59] "  PLoS computational biology 15, no. 4 (2019): e1006650."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
#>  [60] ""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>  [61] "==============================================================================="                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
#>  [62] "Start likelihood: -131.57940525293628 "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#>  [63] "         Sample      posterior ESS(posterior)     likelihood          prior"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
#>  [64] "              0      -131.5794              N      -125.2445        -6.3348 --"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
#>  [65] "           1000       -87.4821         2.0          -86.3663        -1.1158 --"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
#>  [66] ""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>  [67] "Operator                                                   Tuning    #accept    #reject      Pr(m)  Pr(acc|m)"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#>  [68] "ScaleOperator(YuleBirthRateScaler.t:test_output_0)        0.75000         36          1    0.04000    0.97297 Try setting scaleFactor to about 0.562"                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>  [69] "ScaleOperator(YuleModelTreeScaler.t:test_output_0)        0.50000         35         26    0.04000    0.57377 Try setting scaleFactor to about 0.25"                                                                                                                                                                                                                                                                                                                                                                                                                                               
#>  [70] "ScaleOperator(YuleModelTreeRootScaler.t:test_output_0)    0.50000         25         15    0.04000    0.62500 Try setting scaleFactor to about 0.25"                                                                                                                                                                                                                                                                                                                                                                                                                                               
#>  [71] "Uniform(YuleModelUniformOperator.t:test_output_0)               -        193        214    0.40000    0.47420 "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
#>  [72] "SubtreeSlide(YuleModelSubtreeSlide.t:test_output_0)       1.00000         27        164    0.20000    0.14136 "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
#>  [73] "Exchange(YuleModelNarrow.t:test_output_0)                       -         51        137    0.20000    0.27128 "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
#>  [74] "Exchange(YuleModelWide.t:test_output_0)                         -          2         31    0.04000    0.06061 "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
#>  [75] "WilsonBalding(YuleModelWilsonBalding.t:test_output_0)           -          2         42    0.04000    0.04545 "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
#>  [76] ""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>  [77] "     Tuning: The value of the operator's tuning parameter, or '-' if the operator can't be optimized."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
#>  [78] "    #accept: The total number of times a proposal by this operator has been accepted."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
#>  [79] "    #reject: The total number of times a proposal by this operator has been rejected."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
#>  [80] "      Pr(m): The probability this operator is chosen in a step of the MCMC (i.e. the normalized weight)."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
#>  [81] "  Pr(acc|m): The acceptance probability (#accept as a fraction of the total proposals for this operator)."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
#>  [82] ""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>  [83] ""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>  [84] "Total calculation time: 0.342 seconds"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
#>  [85] "File: 2_4.xml seed: 1629291660550 threads: 1"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#>  [86] "Loading package Beasy v0.0.2"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#>  [87] "Loading package bacter v2.2.3"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#>  [88] "Loading package BASTA v3.0.1"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#>  [89] "Loading package NS v1.1.0"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
#>  [90] "Loading package BADTRIP v1.0.0"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
#>  [91] "Loading package MASTER v6.1.2"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#>  [92] "Loading package BEAST_CLASSIC v1.5.0"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#>  [93] "Loading package besp v0.2.0"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
#>  [94] "Loading package GEO_SPHERE v1.3.0"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
#>  [95] "Loading package CodonSubstModels v1.1.3"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
#>  [96] "Loading package CoalRe v0.0.5"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
#>  [97] "Loading package BEASTvntr v0.1.3"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#>  [98] "Loading package CA v2.0.0"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
#>  [99] "Loading package BDSKY v1.4.6"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#> [100] "Loading package BEAST v2.6.4"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#> [101] "Loading package BEASTLabs v1.9.6"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#> [102] "Loading package MODEL_SELECTION v1.5.3"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
#> [103] "Loading package BDMM v1.0"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
#> [104] "Loading package bModelTest v1.2.1"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
#> [105] "Loading package Babel v0.3.2"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#> [106] "Loading package BREAK_AWAY v1.0.1"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
#> [107] "Loading package MultiTypeTree v7.0.2"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
#> [108] "Loading package BEAST v2.6.4"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
#> [109] "Failed to load BEAGLE library: no hmsbeagle-jni in java.library.path: [/usr/lib/jvm/java-11-openjdk-amd64/lib/server, /usr/lib/jvm/java-11-openjdk-amd64/lib, /usr/lib/jvm/java-11-openjdk-amd64/../lib, /usr/lib/R/lib, /usr/lib/x86_64-linux-gnu, /usr/lib/jvm/default-java/lib/server, /usr/lib/R/lib, /usr/lib/x86_64-linux-gnu, /usr/lib/jvm/default-java/lib/server, /usr/lib/R/lib, /usr/lib/x86_64-linux-gnu, /usr/lib/jvm/default-java/lib/server, /usr/java/packages/lib, /usr/lib/x86_64-linux-gnu/jni, /lib/x86_64-linux-gnu, /usr/lib/x86_64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]"
#> [110] "Writing file test_output_0.log"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
#> [111] "Writing file test_output_0.trees"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
#> [112] "End likelihood: -87.48219740756475"

If beastier has run BEAST2, the MCMC’s final state will be saved to a file:

if (is_beast2_installed()) {
  expect_true(file.exists(beast2_options$output_state_filename))
  file.remove(beast2_options$output_state_filename)
}
#> [1] TRUE

This final state can be used to continue the run.