How to do it...

Reading and writing tree formats with ape and treeio can be executed using the following steps:

  1. Load the ape library and load in trees:
library(ape)
newick <-ape::read.tree(file.path(getwd(), "datasets", "ch4", "mammal_tree.nwk"))
nexus <-ape::read.nexus(file.path(getwd(), "datasets", "ch4", "mammal_tree.nexus"))
  1. Load the treeio library and load in BEAST/RAxML output:
library(treeio)
beast <- read.beast(file.path(getwd(), "datasets", "ch4", "beast_mcc.tree"))
raxml <- read.raxml(file.path(getwd(), "datasets", "ch4", "RAxML_bipartitionsBranchLabels.H3"))
  1. Check the object types that the different functions return:
class(newick)
class(nexus)

class(beast)
class(raxml)
  1. Convert tidytree to phylo, and vice versa:
beast_phylo <- treeio::as.phylo(beast)
newick_tidytree <- treeio::as.treedata(newick)
  1. Write output files using the following code:
treeio::write.beast(newick_tidytree,file = "mammal_tree.beast")
ape::write.nexus(beast_phylo, file = "beast_mcc.nexus")
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.204.54