Skip to content

Creating Consensus Tree Figures with Ancestral State Estimations in BayesTraits

Notifications You must be signed in to change notification settings

Joseph-Watts/BayesTraits-Discrete-Nodes-Plots

Repository files navigation

Creating Consensus Tree Figures with Ancestral State Estimations in BayesTraits

These R scripts are used to generate figures of consensus trees with nodes that represent the ancestral state estimations and phylogenetic uncertainty. See Primates_Trait_A.pdf and Primates_Trait_B.pdf for examples of figures generated.

This is not a fully automated process, and there are two main steps involved, each with a separate R script. The first step is to generate the commands that you need to enter into BayesTraits before running analyses. This step requires a consensus tree with nodes ordered as you want them in your final images (see BEAST’s TreeAnnotator for how to generate a consensus tree). An efficient way of entering commands into BayesTraits is to use a command file, rather than having to enter all commands line by line. For more information on using command files, check out the “Running BayesTraits with a command file” section the BayesTraits manual. One point of caution here though is that this can hide any warnings, so make sure you are happy with how it is running first.

The second step involves reading in the output from BayesTraits in R, then using this output and the same consensus tree that you used in step one to create two pdf images representing the ancestral state estimation for each trait. These figures will not necessarily be publication quality, and may require further editing, depending on your requirements. I recommend saving the figures in pdf format or some other vector based format to preserve image quality when rescaling and editing.

Example files

The example used in this script is based on the “Primates” dataset from BayesTraits and uses the same settings as the example used in the BayesTraits manual (these settings can be seen in the Primates_AddNodes_Dep_Commands.txt file). The tree files supplied here have been modified slightly to work with the scripts provided (modifications noted in the tree files). When using the fields supplied in this repository, the figures created should look like Primates_Trait_A.pdf and Primates_Trait_B.pdf.

Notes:

  • This script only works for the Discrete Dependent analyses in v3 of BayesTraits. The node orders and commands are different in earlier versions of BayesTraits. It shouldn’t be too hard for others to modify it to work with older version of BayesTraits or for use in the Discrete Independent or Multistate analyses.
  • This is designed to be run with a sample of trees in BayesTraits, not a single tree. The only time a single tree is used here is for the purposes of the consensus tree figure in R.
  • By “phylogenetic uncertainty” I mean the proportion of trees in the tree sample (typically from the posterior distribution) that have a node with the same descendants in the consensus tree.
  • If you use this code, please cite the authors of R, BayesTraits, and ape.
  • I am not a programmer and I know that my code is not elegant or efficient (e.g. I use too many for loops!). I appreciate suggested improvements, though it may take some time for me to work through them. If you spot any mistakes please log them as issues on the issues page so that others are aware of them too.

Examples of some papers with figures based on this code:

Other GitHub pages worth taking a looking at for BayesTraits and R users:

About

Creating Consensus Tree Figures with Ancestral State Estimations in BayesTraits

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published