A few weeks ago, we had a look at a simultion study with BEAST, using the SequenceSimulator, LogAnalyser and R. Let’s do that study again, but now with BEASTShell, a package for scripting BEAST-objects. It is based on BeanShell, but has special extentions to conveniently deal with BEASTObject classes.
In the previous blog, I sampled sequences for a range of shape parameter values that seemed reasonable in my experience. However, the model assumes an exponential prior distribution over the shape parameters with mean 1, so arguably, that information is sufficient to draw shape values from. In this study, we will
sample 100 values of the shape parameter from this prior distribution,
sample an alignment with 10.000 characters using 4 gamma categories and one of the sampled shape paramter values
run the analysis on the sampled data
record the estimate of the shape parameter
create a plot of sampled against estimated shape values
Let’s get started with BEASTShell. The easiest way to create scripts is using BEASTStudio, the BEASTShell GUI. First, we import a bunch of packages we are going to need. BEASTShell already loads a nuber of packages (javax.swing.event, javax.swing, java.awt.event, java.awt,java.net, ava.util,java.io, and java.lang) which makse it easy to create standard class instances.
First, we draw gamma shape from the prior (exp(1.0))
Newx, we set up a model to draw samples from
For each of the shape values (shape0 in the following), we set up a site model with gamma shape parameter
Then, we specify which XML analysis, (we prepared in the previous blog) we want to use to analyse the generated alignment, using
Now, we have all the components ready to set up the sequence simulator:
This produces gammaShapeSequence.xml and merge it with analysis.xml to get analysis-out.xml. Now we can run the analysis using:
After this finished in a minute or so, we grab estimates from the analysis using the LogAnalyser, and store it in the estimate list.
After we have done this for all generated shape parameter values, we can draw a scatter plot and save to “Sample_Chart.png”, using
This analysis just overwrites log files for each generated alignment. To tell BEAST to overwrite, we need
Furthermore, we want to use BEAGLE, but dependeing on your hardware, this may not speed things up. Setting BEAGLE flags can be done like so:
Running the analysis
So, that gives us the following complete script.
You can run the analysis in BEASTStudio, but you can also run it from the command line, which is probably a bit faster. BEASTShell has a command line interpreter that can be started with
Once you ran the script, something similar to the following image should appear in the file Sample_Chart.png.
Looks like the shape parameter can be fairly reliably recovered from a large range of shape values. Only at the extremes — below 0.05 and over 15 — the prior is drawing the estimate to the mean.