How to run HYPHY on multiple files non-interactively? I would like to test for positive selection in a large set of genes.

I want to have a yes/no answer to the question if gene was evolving under positive selection. Therefore I chose model BUSTED for my analysis, which is implemented in HYPHY.

When I launch HYPHY in the command-line, I get a series of question I  have to answer in the interactive form.

Is there way to perform a batch analysis involving multiple datasets, i.e. many sequence alignments?
TL;DR

I made the following bash script to generate an input file for HYPHY.



#!/bin/bash
cat &lt;&lt; EOF
inputRedirect = {};
inputRedirect["01"]="Universal"; // genetic code
inputRedirect["02"]="$(readlink -f $1)"; // codon data
inputRedirect["03"]="$(readlink -f $2)"; // tree
inputRedirect["04"]="${3:-All}"; // Test for selection on a branch
inputRedirect["05"]=""; // complete selection


ExecuteAFile (HYPHY_LIB_DIRECTORY+"TemplateBatchFiles/BUSTED.bf", inputRedirect);
EOF


If you want to test all the branches jointly run:

./gen_busted.sh alignment.phy tree.nwk &gt; script.bf


Or for a particular branch:

./gen_busted.sh alignment.phy tree.nwk branchLabel &gt; script.bf


And then run:

HYPHYMP script.bf


Now you can use the script to generate a .bf file for every sequence alignment you have, and run HYPHY for every file.

Longer version

I will describe how to make a similar script for any model, such as MEME, RELAX or PARRIS.

First, find the .bf script which performs the analysis. On GNU/Linux it should be at HYPHY_INSTALLATION_PATH/lib/hyphy/TemplateBatchFiles (it might be different between different OS). In case of BUSTED your script has a name BUSTED.bf.

Now run this model in the interactive mode in order to record all the inputs required by the model. Make sure to specify full paths to all the files.

HYPHYMP HYPHY_INSTALLATION_PATH/lib/hyphy/TemplateBatchFiles/BUSTED.bf


In case of BUSTED the inputs are:


Genetic code.
Codon data (sequence alignment in phylip format).
Tree (in newick format).
Which branches to test.


Now for every input alignment you need to generate a batch file which looks like this:

inputRedirect = {};
inputRedirect["01"]="Universal"; // genetic code
inputRedirect["02"]="/path/to/alignment.phy"; // codon data
inputRedirect["03"]="/path/to/tree.nwk"; // tree
inputRedirect["04"]="All"; // Test for selection on all branches
inputRedirect["05"]="BRANCH1"; // Test for selection on branch1 
inputRedirect["06"]="BRANCH2"; // Test for selection on branch2 
inputRedirect["07"]=""; // complete selection


ExecuteAFile (HYPHY_LIB_DIRECTORY+"TemplateBatchFiles/BUSTED.bf", inputRedirect);


Now you can create a script which generates the file. The most important thing, don't forget to use full paths in the .bf file.