Introduction

The purpose of beautier is to create a valid BEAST2 XML input file from its function argument. In this way, a scientific pipeline using BEAST2 can be fully scripted, instead of using BEAUti's GUI.

Demonstration

First, beautier is loaded:

library(beautier)

A BEAST2 XML input file needs an alignment (as BEAST2 infers phylogenies and parameters on DNA sequences). This demonstration uses a testing FASTA file used by beautier:

fasta_filename <- get_beautier_path("test_output_0.fas")

We can display the alignment in the file:

image(ape::read.FASTA(fasta_filename))

plot of chunk unnamed-chunk-3

Now we can create our XML file:

# The name of the file you intend to let BEAST2 run
output_filename <- tempfile(pattern = "beeast2", fileext = ".xml")

create_beast2_input_file(
  fasta_filename,
  output_filename
)

The file indeed is a BEAST2 input file:

cat(readLines(output_filename), quote = FALSE, sep = '\n')
## <?xml version="1.0" encoding="UTF-8" standalone="no"?><beast beautitemplate='Standard' beautistatus='' namespace="beast.core:beast.evolution.alignment:beast.evolution.tree.coalescent:beast.core.util:beast.evolution.nuc:beast.evolution.operators:beast.evolution.sitemodel:beast.evolution.substitutionmodel:beast.evolution.likelihood" required="" version="2.4">
## 
## 
##     <data
## id="test_output_0"
## name="alignment">
##                     <sequence id="seq_t1" taxon="t1" totalcount="4" value="acttgttgcgactgcgcctg"/>
##                     <sequence id="seq_t2" taxon="t2" totalcount="4" value="acttattgcgactgaggccg"/>
##                     <sequence id="seq_t3" taxon="t3" totalcount="4" value="acttaatgcgaatgagcccg"/>
##                     <sequence id="seq_t4" taxon="t4" totalcount="4" value="aacgacccgcgatcggggat"/>
##                     <sequence id="seq_t5" taxon="t5" totalcount="4" value="acttgttgcgactgagcctg"/>
##                 </data>
## 
## 
##     
## 
## 
##     
## 
## 
##     
## <map name="Uniform" >beast.math.distributions.Uniform</map>
## <map name="Exponential" >beast.math.distributions.Exponential</map>
## <map name="LogNormal" >beast.math.distributions.LogNormalDistributionModel</map>
## <map name="Normal" >beast.math.distributions.Normal</map>
## <map name="Beta" >beast.math.distributions.Beta</map>
## <map name="Gamma" >beast.math.distributions.Gamma</map>
## <map name="LaplaceDistribution" >beast.math.distributions.LaplaceDistribution</map>
## <map name="prior" >beast.math.distributions.Prior</map>
## <map name="InverseGamma" >beast.math.distributions.InverseGamma</map>
## <map name="OneOnX" >beast.math.distributions.OneOnX</map>
## 
## 
## <run id="mcmc" spec="MCMC" chainLength="10000000">
##     <state id="state" storeEvery="5000">
##         <tree id="Tree.t:test_output_0" name="stateNode">
##             <taxonset id="TaxonSet.test_output_0" spec="TaxonSet">
##                 <alignment idref="test_output_0"/>
##             </taxonset>
##         </tree>
##         <parameter id="birthRate.t:test_output_0" name="stateNode">1.0</parameter>
##     </state>
## 
##     <init id="RandomTree.t:test_output_0" spec="beast.evolution.tree.RandomTree" estimate="false" initial="@Tree.t:test_output_0" taxa="@test_output_0">
##         <populationModel id="ConstantPopulation0.t:test_output_0" spec="ConstantPopulation">
##             <parameter id="randomPopSize.t:test_output_0" name="popSize">1.0</parameter>
##         </populationModel>
##     </init>
## 
##     <distribution id="posterior" spec="util.CompoundDistribution">
##         <distribution id="prior" spec="util.CompoundDistribution">
##             <distribution id="YuleModel.t:test_output_0" spec="beast.evolution.speciation.YuleModel" birthDiffRate="@birthRate.t:test_output_0" tree="@Tree.t:test_output_0"/>
##             <prior id="YuleBirthRatePrior.t:test_output_0" name="distribution" x="@birthRate.t:test_output_0">
##                 <Uniform id="Uniform.100" name="distr" upper="Infinity"/>
##             </prior>
##         </distribution>
##         <distribution id="likelihood" spec="util.CompoundDistribution" useThreads="true">
##             <distribution id="treeLikelihood.test_output_0" spec="ThreadedTreeLikelihood" data="@test_output_0" tree="@Tree.t:test_output_0">
##                 <siteModel id="SiteModel.s:test_output_0" spec="SiteModel">
##                     <parameter id="mutationRate.s:test_output_0" estimate="false" name="mutationRate">1.0</parameter>
##                     <parameter id="gammaShape.s:test_output_0" estimate="false" name="shape">1.0</parameter>
##                     <parameter id="proportionInvariant.s:test_output_0" estimate="false" lower="0.0" name="proportionInvariant" upper="1.0">0.0</parameter>
##                     <substModel id="JC69.s:test_output_0" spec="JukesCantor"/>
##                 </siteModel>
##                 <branchRateModel id="StrictClock.c:test_output_0" spec="beast.evolution.branchratemodel.StrictClockModel">
##                     <parameter id="clockRate.c:test_output_0" estimate="false" name="clock.rate">1.0</parameter>
##                 </branchRateModel>
##             </distribution>
##         </distribution>
##     </distribution>
## 
##     <operator id="YuleBirthRateScaler.t:test_output_0" spec="ScaleOperator" parameter="@birthRate.t:test_output_0" scaleFactor="0.75" weight="3.0"/>
## 
##     <operator id="YuleModelTreeScaler.t:test_output_0" spec="ScaleOperator" scaleFactor="0.5" tree="@Tree.t:test_output_0" weight="3.0"/>
## 
##     <operator id="YuleModelTreeRootScaler.t:test_output_0" spec="ScaleOperator" rootOnly="true" scaleFactor="0.5" tree="@Tree.t:test_output_0" weight="3.0"/>
## 
##     <operator id="YuleModelUniformOperator.t:test_output_0" spec="Uniform" tree="@Tree.t:test_output_0" weight="30.0"/>
## 
##     <operator id="YuleModelSubtreeSlide.t:test_output_0" spec="SubtreeSlide" tree="@Tree.t:test_output_0" weight="15.0"/>
## 
##     <operator id="YuleModelNarrow.t:test_output_0" spec="Exchange" tree="@Tree.t:test_output_0" weight="15.0"/>
## 
##     <operator id="YuleModelWide.t:test_output_0" spec="Exchange" isNarrow="false" tree="@Tree.t:test_output_0" weight="3.0"/>
## 
##     <operator id="YuleModelWilsonBalding.t:test_output_0" spec="WilsonBalding" tree="@Tree.t:test_output_0" weight="3.0"/>
## 
##     <logger id="tracelog" fileName="test_output_0.log" logEvery="1000" model="@posterior" sanitiseHeaders="true" sort="smart">
##         <log idref="posterior"/>
##         <log idref="likelihood"/>
##         <log idref="prior"/>
##         <log idref="treeLikelihood.test_output_0"/>
##         <log id="TreeHeight.t:test_output_0" spec="beast.evolution.tree.TreeHeightLogger" tree="@Tree.t:test_output_0"/>
##         <log idref="YuleModel.t:test_output_0"/>
##         <log idref="birthRate.t:test_output_0"/>
##     </logger>
## 
##     <logger id="screenlog" logEvery="1000">
##         <log idref="posterior"/>
##         <log id="ESS.0" spec="util.ESS" arg="@posterior"/>
##         <log idref="likelihood"/>
##         <log idref="prior"/>
##     </logger>
## 
##     <logger id="treelog.t:test_output_0" fileName="$(tree).trees" logEvery="1000" mode="tree">
##         <log id="TreeWithMetaDataLogger.t:test_output_0" spec="beast.evolution.tree.TreeWithMetaDataLogger" tree="@Tree.t:test_output_0"/>
##     </logger>
## 
## </run>
## 
## </beast>
## FALSE

This XML input file can be read by BEAST2.