This vignette shows how to parse a BEAST2 posterior file using tracerer.

Load the tracerer package:

library(tracerer)

Extracting the phylogenies from the .trees file

Check if the example file can be found:

trees_file <- get_tracerer_path("beast2_example_output.trees")
testit::assert(file.exists(trees_file))

Parse the posterior:

posterior_trees <- parse_beast_trees(trees_file)

Investigating the posterior:

names(posterior_trees)
## NULL
testit::assert(length(posterior_trees) == 11)

We can see that the posterior has multiple states.

Every state is a phylogeny:

testit::assert(class(posterior_trees[[1]]) == "phylo")

We can plot these all separately:

for (p in posterior_trees) {
  graphics::plot(p)
}

plot of chunk unnamed-chunk-6plot of chunk unnamed-chunk-6plot of chunk unnamed-chunk-6plot of chunk unnamed-chunk-6plot of chunk unnamed-chunk-6plot of chunk unnamed-chunk-6plot of chunk unnamed-chunk-6plot of chunk unnamed-chunk-6plot of chunk unnamed-chunk-6plot of chunk unnamed-chunk-6plot of chunk unnamed-chunk-6

Or we plot all at once:

phangorn::densiTree(
  posterior_trees, 
  type = "cladogram", 
  alpha = 1
)

plot of chunk unnamed-chunk-7