Difference between revisions of "Phylogenetics: BEAST2 Lab"

From EEBedia
Jump to: navigation, search
(Created page with "{| border="0" |- |rowspan="2" valign="top"|150px |<span style="font-size: x-large">[http://hydrodictyon.eeb.uconn.edu/eebedia/index.php/Phylogenetics:_S...")
(No difference)

Revision as of 16:49, 25 April 2018

Adiantum.png EEB 5349: Phylogenetics
The goal of this lab exercise is to use BEAST2 to estimate divergence times under a relaxed clock model and to assess whether the Random Local Clocks or the Uncorrelated Lognormal model fits the data best using estimates of the log marginal likelihood.

Getting started

(q)login to the cluster

Login to the Bioinformatics Facility Dell cluster:

ssh username@bbcsrv3.biotech.uconn.edu

Then use the qlogin command to find a free node:


Once you are transferred to a free node, type

module load java/1.8.0
module load beast/2.5.0

This makes a more recent version of BEAST2 available to you and loads Java 8 (actually version 1.8), which is required by BEAST 2.5.0.

Create a directory

Use the unix mkdir command to create a directory to play in today:

mkdir beastlab
cd beastlab

Download and save the data file

The tutorial uses a data file named primate-mtDNA.nex that is located on the cluster. Here's how to copy it to your beastlab directory:

cp $BEAST/examples/nexus/primate-mtDNA.nex .

The $BEAST part represents a bash variable (bash is the scripting language you are using to communicate with the operating system). The module load beast/2.5.0 command above created the BEAST variable, which points to the directory on the cluster's hard drive where beast2 was installed. The cp command stands for copy, so the command above will copy the file primate-mtDNA.nex to the current directory, which should be your newly-created beastlab directory (the period at the end of the cp command is shorthand for the current directory).

Download BEAST2

BEAST2 comprises two main programs: BEAST and BEAUTi. BEAUTi is a graphical application that helps you create the xml file that BEAST runs. Because BEAUTi is graphical, it is difficult to run on the cluster, so please download the latest version of BEAST2 to your own laptop and run BEAUTi from there. Here's the web site:


Divergence Dating Tutorial

The tutorial at the web site address shown below walks you through the process of dating a primate mtDNA tree but does not show you how to assess model fit using marginal likelihood estimation. After you finish the tutorial, I will show you how to estimate the marginal likelihood of the model using BEAST2.

Important: read before starting the tutorial

In section 2.3 (Setting the clock model), we will try using three different clock models. Each person will be assigned one of the following:

  1. strict clock (this is what the tutorial advises)
  2. uncorrelated lognormal relaxed clock
  3. random local clocks

It is important that you pay attention and do not simply plow through section 2.3 at full tilt because then everyone will end up doing only the strict clock analysis!

Here is the tutorial


Note that you will run BEAUTi on your own laptop to generate the xml file, then move the xml file (e.g. myfile.xml) to the cluster and run beast as follows:

beast myfile.xml

Marginal Likelihood Estimation

BEAST2 can estimate the marginal likelihood of a model but unfortunately this currently (as of April 2018, BEAST 2.5.0) involves modifying the xml file directly (there is no menu option in BEAUTi that will do this for you). Open your xml file using your favorite text editor (e.g. BBEdit/TextWrangler on Mac, Notepad++ on Windows) and make the following modifications:

  1. Search for "<run" and change it to "<mcmc"
  2. Search for "</run>" and change it to "</mcmc>"
  3. Before "<mcmc", add the following lines
<run  spec='beast.inference.PathSampler' nrOfSteps='32' alpha='0.3'>
cd $(dir)
java -cp $(java.class.path) beast.app.beastapp.BeastMain $(resume/overwrite) -java -seed $(seed) beast.xml 
  1. After "</mcmc>" add the following line:

The sections below show what the file looks like before and after these modifications.


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beast ...>
<run id="mcmc" spec="MCMC" chainLength="6000000">


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beast ...>
<run  spec='beast.inference.PathSampler' nrOfSteps='32' alpha='0.3'>
cd $(dir)
java -cp $(java.class.path) beast.app.beastapp.BeastMain $(resume/overwrite) -java -seed $(seed) beast.xml 
<mcmc id="mcmc" spec="MCMC" chainLength="6000000">

Upload this new xml file to your beastlab directory (you may wish to move any output files from the previous run first so they will not be overwritten) on the cluster and run it using beast as before. When beast is finished, it will spit out the log marginal likelihood that it estimated.

Further Information (no need to read this for today's lab)

Read these section only if you are trying to run this lab entirely on your own computer (not the cluster) or if you are looking for more information about marginal likelihood estimation in BEAST2.

Marginal likelihood estimation on your own laptop

You used the cluster to perform the BEAST run that estimated the marginal likelihood. Were you to try this on your own computer, you would discover that you need to install the BEASTLabs and MODEL_SELECTION packages before performing the analysis. This is done using BEAUTi's File > Manage Packages... menu item. The packages are normally installed in the .beast directory inside your home directory on whichever computer you use to run BEAUTi. Rather than have everyone do this separately (and because some of you cannot use graphical applications such as BEAUTi if they are run on the cluster), I moved these packages to a place where BEAST can find them on the cluster (/usr/local/share/beast/2.5).

Run options

For reference, here are all the options that you can include in the <run ...> xml tag. We only used the first two in this lab and let the defaults apply to all other options.

  • alpha: alpha parameter of Beta(alpha,1) distribution used to space out steps, default 0.3. If alpha <= 0, uniform intervals are used.
  • nrOfSteps: the number of steps to use, default 8
  • rootdir: root directory for storing particle states and log files (default /tmp)
  • mcmc: MCMC analysis used to specify model and operations in each of the particles
  • chainLength: number of sample to run a chain for a single step (default 100000L)
  • burnInPercentage: burn-In Percentage used for analysing log files (default 50)
  • preBurnin: number of samples that are discarded for the first step, but not the others (default 100000)
  • value: script for launching a job:
    • $(dir) is replaced by the directory associated with the particle]
    • $(java.class.path) is replaced by a java class path used to launch this application
    • $(java.library.path) is replaced by a java library path used to launch this application
    • $(seed) is replaced by a random number seed that differs with every launch
    • $(host) is replaced by a host from the list of hosts
  • hosts: comma separated list of hosts. If there are k hosts in the list, for particle i the term $(host) in the script will be replaced by the (i modulo k) host in the list. Note that whitespace is removed
  • doNotRun: Set up all files but do not run analysis if true. This can be useful for setting up an analysis on a cluster (default false)
  • deleteOldLogs: delete existing log files from root dir (default false)
  • posterior2prior: whether to do steps from posterior to prior or the other way around. Going from posterior to prior is biased towards over estimates, while from prior to posterior the ML estimate is biased towards under estimates (default true)