Friday, February 15, 2008

I write scripts...

No, I haven't been on strike for the past few months; I write small programs in scripting languages. Many people in bioinformatics, even those with no formal programming background, learn enough to write a simple series of commands in some scripting language or another. The most popular language for this sort of coding is almost certainly Perl. Python is another popular language for doing this. I've written some Perl and a few one liners to play with Python, but those languages won't be the focus of these posts. I intend to provide some enlightenment on another, lesser known language - the scripting language used by the Mesquite package.

Mesquite, for those who haven't heard of it or read my introductory post, is a application environment for phylogenetics, focusing on doing things with trees rather than inferring them. It does have the ability to serve as a frontend to programs that do tree inference - either directly for MrBayes or indirectly using a bridge to the Cipres libraries - which support PAUP*, RAxML, and GARLI as well as MrBayes. Mesquite will also create trees using a variety of simulation methods, such as pure birth (aka Yule trees), birth-death, and the model that corresponds to the BiSSE method of estimation.

Many, if not most, users treat Mesquite as a GUI application without any knowledge of the scripting that Mesquite supports and uses when they save and then reload a project containing trees and character matrices. There are several ways to use Mesquite scripts - either by including them in a Mesquite block in the nexus file that represents the project, but they can also be used to send a series of commands to a window during a Mesquite session. If you use a command line to launch Mesquite you can also send commands or scripts via the terminal that you launched Mesquite from.

I'll finish this post with a simple "Hello World" style example of some Mesquite script that you can run within the Mesquite GUI.

Start Mequite and create a new project, call it scriptTest.nex. Accept the defaults in the dialog that comes up for creating the project. If you are running Mesquite 2.0 or later, you should see something to this in your Mesquite window.

Make sure that "Tree Window 1" is selected and from the Window menu select Scripting:Send Script. This will bring up a dialog where you can type a script command. Here's "Hello World" in Mesquite Script :
message 'Hello World'

So bring up the script window, type in the commands and press the OK button.

So where's my message?
After the script window disappears, you are probably wondering where the message went? It's not in the Tree Window - you actually didn't request the window to do anything. The message appeared in the Mesquite Log. The log contains a record of what Mesquite has done during a session. The easiest way to see the log is to go back to the window menu and select Log from the list. This will expose the log window. If you scroll down to the bottom, you will see your message, followed by the showWindow command you used to bring up the log.

The log appears in other places - the file Mesquite_Log that is created in Mesquite_Support files - a new file is created each time you start Mesquite. If you start Mesquite from a command line, logged information is also written to the terminal you launched from.

That's it for now. Next time, I'll discuss It and other important variables and the structure of scripts. In the meantime, there is a list of "Universal" Mesquite scripting commands available by choosing Scripting from the help menu and the selecting the 'universal commands' link near the top of the page.