---
title: "beautier demo"
author: "Richèl J.C. Bilderbeek"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{beautier demo}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = ""
)
```

# Introduction

![](beautier_logo.png)

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.

`beautier` is part of the `babette` package suite (website at [https://github.com/ropensci/babette](https://github.com/ropensci/babette)). 
`babette` allows to use BEAST2 (and its tools) from R.

# Demonstration

First, `beautier` is loaded:

```{r load_beautier}
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`:

```{r get_fasta_filename}
fasta_filename <- get_beautier_path("test_output_0.fas")
```

We can display the alignment in the file:


```{r show_alignment}
image(ape::read.FASTA(fasta_filename))
```

Specify the filename for our XML file, here I use a temporary filename,
so there is no need to clean up afterwards:

```{r create_output_filename}
output_filename <- tempfile(pattern = "beast2", fileext = ".xml")
output_filename
```

Now we can create our XML file. We do not specify any inference model,
and just use the BEAUti default settings:

![](all_default.png)

```{r create_beast2_input_file}
create_beast2_input_file(
  fasta_filename,
  output_filename
)
```

The file indeed is a BEAST2 input file:

```{r show_beast2_input_file}
readLines(output_filename)
```

This XML input file can be read by BEAST2. 

You can use `beastier` to run BEAST2 from R, see [https://github.com/ropensci/beastier](https://github.com/ropensci/beastier).
You can use `babette` to do a BEAST2 inference directly, 
see [https://github.com/ropensci/babette](https://github.com/ropensci/babette).
