Phylogenetics: HyPhy Lab
|EEB 349: Phylogenetics|
|The goal of this lab exercise is to show you how to use the HyPhy program for data exploration and hypothesis testing within a maximum likelihood framework.|
- 1 Obtaining the sequences
- 2 Using a codon model
- 3 Downloading and installing HyPhy
- 4 Loading data into HyPhy
- 5 Creating a partition
- 6 Computing the likelihood under a local codon model
- 7 Computing the likelihood under the most-constrained model
- 8 Performing a model comparison
- 9 Computing the likelihood under a partially-constrained model
Obtaining the sequences
A Nexus data file containing sequences and a tree is located here: wickett.nex. This dataset was assembled by our own Norm Wickett and contains several sequences of bryophytes, including two from a parasitic bryophyte that is non-green and does not photosynthesize. Norm's sequences have now been published, so there is no need for secrecy, but the names of the taxa have been nevertheless been obscured (pending permission to reveal them). The parasitic ones are clearly labeled, however.
The sequences are of a gene important for photosynthesis. The basic idea behind today's lab is to see if we can detect shifts in the evolution of these sequences at the point where these organisms became non-photosynthetic (thus presumably no longer needing genes like this).
Using a codon model
Although HyPhy can utilize the same standard models found in PAUP*, it also lets you to do some interesting and useful things that PAUP* cannot, such as (1) use codon and secondary structure models, and (2) allow the model of evolution to change across a tree.
Downloading and installing HyPhy
HyPhy is available for Mac and Windows from the HyPhy home page.
Loading data into HyPhy
Start HyPhy and dismiss the "Welcome to HyPhy" dialog box (if it appears) by pressing the Ok button. Choose File > Open > Open Data File, then navigate to and select the wickett.nex data file that you saved previously. You should now see the sequences appear in a window entitled "DataSet wickett". I will refer to this as the Data window from this point on.
Creating a partition
HyPhy thinks of your data as being composed of one or more partitions. Partitioning data means assigning characters (sites) into mutually-exclusive groups. For example, suppose your data set comprises two genes: you might want to assign a separate model for each gene, so in this case you would create two partitions (one for each gene).
The word partition is used in two ways
The word partition is ambiguous: it formerly meant "wall" or "divider" but, with the advent of computer hard drives, it has also come to mean the space between the walls or dividers. When someone says they partitioned their data, they mean that they erected dividers, for example between the rbcL and 18S genes. When someone says they applied a GTR+I+G model to the rbcL partition, they have now switched to using the word partition to mean the sites on the rbcL side of the divider.
No partitioning implies one partition!
Even if you choose to not partition (old meaning) your data in HyPhy, you must go through the motions of creating a single partition (new meaning) because HyPhy only allows you to apply a model to a partition. To create a single partition containing all of your sites, choose Edit > Select All from the Data window menu, then choose Data > Selection->Partition to assign all the selected sites to a new partition. You should see a line appear below your sequences with a partition name "wickett_part".
Assign a data type to your partition
Now that you have a partition, you can create a model for it. Under the column name Partition Type, choose codon (just press the Ok button in the dialog box that appears). You have now chosen to view your data as codons (i.e. three nucleotides at a time) rather than as single nucleotides. The third possible choice for Partition Type is Di-nucl., which you would use if you were planning to use a secondary structure (i.e. stem) model, which treats each sequential pair of nucleotides as a state.
Assign a tree topology to your partition
Under Tree Topology, you have several options. Because a tree topology was defined in the wickett.nex data file, this tree topology shows up in the drop-down list as wickett_tree. Choose wickett_tree as the tree topology for your partition.
Assign a substitution model to your partition
The only substitution models that show up in the drop-down list are codon models because earlier you chose to treat your data as codon sequences rather than nucleotide sequences. The substitution model you should use is MG94xHKY85_3x4 (second from the bottom). This model is like the Muse and Gaut (1994) codon model, which is the only codon model I discussed in lecture. You will remember (I'm sure) that the MG94 model allows substitutions to be either synonymous or non-synonymous, but does not make a distinction between transitions and transversions. The HKY85 model distinguishes between transitions and transversions (remember kappa?), but does not distinguish between synonymous and non-synonymous substitutions. Thus, MG94xHKY85 is a hybrid model that allows all four possibilities: synonymous transitions, synonymous transversions, nonsynonymous transitions and nonsynonymous transversions. The name is nevertheless a bit puzzling because (as you will find out in a few minutes) it actually behaves more like the GTR model than the HKY model in that it allows all 6 possible types of substitutions (A<->C, A<->G, A<->T, C<->G, C<->T and G<->T) to have their own rates.
The 3x4 part on the end of the name means that the 61 codon frequencies are obtained by multiplying together the four nucleotide frequencies that are estimated separately for the three codon positions. Thus, the frequency for the AGT codon is obtained by multiplying together these three quantities:
- the frequency of A nucleotides at first positions
- the frequency of G nucleotides at second positions
- the frequency of T nucleotides at third positions
(Note: HyPhy corrects these for the fact that the three stop codons are not included.) This involves estimating the 4 nucleotides frequencies at each of the 3 codon positions, hence the 3x4 in the name.
Local vs. global
You have only a couple more decisions to make before calculating the likelihood. You must choose Local or Global from the Parameters drop-down list. Local means that HyPhy will estimate some substitution model parameters for every branch in the tree. Global means that all substitution model parameters will apply to the entire tree. In all the models discussed thus far in the course, we were effectively using the global option except for the branch lengths themselves, which are always local parameters (it doesn't usually make any sense to think of every branch having the same length).
Tell HyPhy to use the Local option (this should already be set correctly).
You should also leave the equilibrium frequencies set to "Partition". This sets the equilibrium base frequencies to the empirical values (i.e. the frequency of A is the number of As observed in the entire partition divided by the total number of nucleotides in the partition). Other options include:
- Dataset, which would not be different than "Partition" in this case where there is only one partition defined,
- Equal, which sets all base frequencies equal to 0.25, and
- Estimate, which estimates the base frequencies
Computing the likelihood under a local codon model
You are now ready to compute the maximum likelihood estimates of the parameters in your model. Choose Likelihood > Build Function to build a likelihood function, then Likelihood > Optimize to optimize the likelihood function (i.e. search for the highest point on the likelihood surface, thus obtaining maximum likelihood estimates of all parameters).
Saving the results
When HyPhy has finished optimizing (this will take several seconds to several minutes, depending on the speed of the computer you are using), it will pop up a "Likelihood parameters for wickett" window (hereafter I will just refer to this as the Parameters window) showing you values for all the quantities it estimated.
Click on the HYPHY Console window to bring it to the foreground, then, using the scroll bar to move up if needed, answer the following questions:
Switch back to the Parameters window now and look at the very bottom of the window to answer these questions:
Before moving on, save a snapshot of the likelihood function with the current parameter values by choosing "Save LF state" from the drop-down list box at the top of the Parameters window. Choose the name "unconstrained" when asked. After saving the state of the likelihood function, choose "Select as alternative" from the same drop-down list. This will allow us to easily perform likelihood ratio tests using another, simpler model as the null model.
Viewing the tree and obtaining information about branches
The first item in the Parameters window should be "wickett_tree". Double-click this line to bring up a Tree window showing the tree. You may need to expand the Tree window to see the entire tree. This shows the tree with branch lengths scaled to be proportional to the expected number of substitutions (the normal way to scale branch lengths).
The next step is to compare the unconstrained model (in which there are the same number of omega parameters as there are branches) with simpler models involving fewer omega parameters. For example, one model you will use in a few minutes allows the three branches in the parasite clade to evolve under one omega, while all other branches evolve under an omega value that is potentially different. For future reference, you should determine now what name HyPhy is using for the branch leading to the two parasite taxa.
Click on the branch leading to the two parasites. It should turn into a dotted line. Now double-click this branch and you should get a dialog box popping up with every bit of information known about this branch:
You can now close the "Branch Info" dialog box.
Computing the likelihood under the most-constrained model
Under the current (unconstrained) model, two parameters were estimated for each branch: the synonymous substitution rate and the nonsynonymous substitution rate. Now let's constrain each branch so that the ratio (omega) between the nonsynonymous rate and the synonymous rate is identical for all branches.
To do this, first notice that each branch is represented by two parameters in the Parameter window. For example, the branch leading to Parasite_A is associated with these two parameters:
The goal is to constrain these two parameters so that the nonsynonymous rate is always omega times the synonymous rate, where omega is a new parameter shared by all branches.
Select the two parameters listed above for the branch leading to PARASITE_A. (You can do this by single-clicking both parameters while simultaneously holding down the Shift key.) Once you have both parameters selected, click on the third button from the left at the top of the Parameters window. This is the button decorated with the symbol for proportionality. Clicking this button will produce a long list of possiblities: here is the one you should choose:
Once you select this option, HyPhy will ask for a name: type
as the name of the new ratio.
Now select the two parameters for a different pair of branches, say
Click the proportionality constraint button again, but this time choose
Note that you can choose to use a constraint for other branches once you have defined it for one branch.
Continue to apply this constraint to all 19 remaining branches. When you are finished, choose Likelihood > Optimize from the menu at the top of the Parameters window.
Performing a model comparison
After HyPhy is finished optimizing the likelihood function, answer the following questions using the numbers at the bottom of the Parameters window:
Although you should do the calculation yourself first, you can now have HyPhy perform the likelihood ratio test for you to check your calculations. In the drop-down list box at the top of the Parameters window, choose "Save LF state" and name it "most-constrained". Now, using the same list box, choose "Select as null". Now perform the test by choosing LRT from the same drop-down list box. The results should appear in the HYPHY Console window.
Computing the likelihood under a partially-constrained model
Let's try one more model that is intermediate between the unconstrained and most-constrained models you just analyzed. This model will allow for omega to be different in the non-green, parasitic clade compared to the remaining green, non-parasite part of the tree.
For one of the three branches in the parasite clade (say, the branch leading to PARASITE_A), select the two parameters associated with the branch and click the rightmost button at the top of the Parameters window (this button releases the constraint previously placed on these two parameters). With the two parameters still selected, click the proportionality constraint button again (third from left) and choose the option
as the name of the New Ratio. Now apply this new ratio to the other two branches in the clade by first releasing the existing constraint and then applying the omega2 constraint.
Once you are finished, choose Likelihood > Optimize again to search for the maximum likelihood point. Now choose "Save LF state", naming this one "partially-constrained". Answer the following questions using the values shown in the Parameter window:
You can now perform a likelihood ratio test. Using the drop-down list box at the top of the Parameters window, specify the most-constrained model to be the null model and the partially-constrained model to be the alternative. Choose LRT from the drop-down list to perform the test.
Perform one more likelihood ratio test, this time using the partially-constrained model as the null and the unconstrained model as the alternative.