TITLE: AU Test with IQTree 
AUTHORS: Dakota Betz

[DESCRIPTION]
Our protocols are constantly evolving and old versions will be deleted.
The documents here are not intended to be cited in publications

[STEPS]
SECTION: Programs and Dependencies
1. IQ-Tree
Download: http://www.iqtree.org/
Additional information/tutorials: http://www.iqtree.org/doc/Advanced-Tutorial

Mesquite
Download: https://www.mesquiteproject.org/Installation.html

RAxML-ng
Download: https://github.com/amkozlov/raxml-ng
GUI 2.0 (compatible with ng): https://antonellilab.github.io/raxmlGUI/

Text Editor (options below)
SublimeText:  https://www.sublimetext.com/3
BBEdit: https://www.barebones.com/products/bbedit/download.html
SECTION: File Preparation
3. Make sure you have a copy of your original RAxML tree (against which you would like to test your constraint tree, which you have not created yet). 

Open your original tree in FigTree if it is a .tre file and convert it to a nexus file. To do this, click:
File > Export Trees
And choose Nexus from the dropdown menu. 

Append the filename of this nexus file with "_original.nex" so that it's easy to tell apart from the constraint you will make.
SECTION: File Preparation
4. You will use the original file as a base to start your constraint. Open your tree file "_original.nex" in Mesquite. Re-save it as "_constraint.nex" before you begin making changes. 
SECTION: File Preparation
5. Collapse  all of the nodes in your tree into a single polytomy, including the outgroup. See image below of the collapse tool:
  

SECTION: File Preparation
6. Now select only the taxa you want to constrain and make those a single polytomy using the arrow cursor tool (they should be separate from the other polytomy which is the rest of the tree). The tree should now have a total of 2 polytomies. 

Reminder: the outgroup is not separated out--it can be in the polytomy with the remaining taxa that you are not intending to constrain. Save again just in case (remember filename should now be "_constraint.nex").
SECTION: File Preparation
7. Select Tree > Store tree in other block as and give your tree a name (e.g. "constraint"). Then Store in new tree block   and name the new tree block. Select switch to new tree and select your new tree. To export this, click File > Export > Export Nexus tree file from tree source > stored trees. Make sure you select the tree you want (constraint). Check the box to include taxa block, then click Export > Save. 
SECTION: File Preparation
8. You should be able to open the newly saved "_constraint.nex" file in FigTree. If not, make a copy  of this file outside mesquite (should be a .nex file) and add the extension .tre instead (works on Mac OS only). Now open the "_constraint.tre" tree in FigTree.

Once you have confirmed that Mesquite/FigTree saved the topology you wanted, export as a .nex file again from FigTree. 
SECTION: RAxML Likelihood Estimation
13. Make sure you have the following settings in the RAxML GUI: RAxML-ng, ML Tree Inference, 1 run. Select the same outgroup that you used in your unconstrained analysis. Change the output name and folder to something that makes sense (e.g. "_RAxMLconstrained"). 

 

SECTION: RAxML Likelihood Estimation
10. For this part of the protocol, you will need the data and partitions you used to create your original/unconstrained tree, i.e.:
your concatenated dataset (nucleotide or amino acid)
your partitions for your concatenated dataset (if applicable)
 

SECTION: RAxML Likelihood Estimation
14. Run RAxML. The resulting "best tree" will be the constrained tree that you test against your "_original" unconstrained tree for the AU test. Name it something like "_RAxMLconstrained" so you can tell the difference between this and the constraint tree you made in Mesquite. To make the tree easier to open in FigTree, add the .tre extension to the end of the filename.
SECTION: Combining Tree Files
15. Ensure both your "_original" and your new "_RAxMLconstrained" trees are in Nexus format. You can do this by opening them in FigTree and exporting them as Nexus files as in this step:   

SECTION: Combining Tree Files
16. Open one of your trees in a text editor (e.g. SublimeText). Resave it as "_combined.nex" before you begin to make changes.

Make sure the label (probably "tree_1" in the text file) is edited to reflect which tree this is. For ex: if you opened your constrained tree first and renamed the file, make sure "tree_1" in this file is replaced with "constrained". 

SECTION: Combining Tree Files
17. Open your other tree in a text editor. Copy and paste the tree notation (with the name, be sure to edit it to reflect which tree it is like you did in the previous step) into your "_combined.nex" file. Be sure to appropriately label this tree as well (this will be "original" if you opened the constrained first in the above step). Save and close your "_combined.nex" file. 
SECTION: Combining Tree Files
19. Open your "_combined.tre" file in FigTree to check that the trees look as expected. Export the tree in Newick format (same procedure as exporting for nexus, but select newick from the dropdown menu and "select all trees") with a .txt extension at the end of the filename. 
SECTION: Running the AU Test
23. It's easiest to proceed if your terminal working directory is the same one that IQTree is in. For ease of use, open the IQTree folder on your computer and place a copy  of the following files:
your combined trees in newick format ("_combined.txt")
your nucleotide dataset (concatenated) in phylip format ("nuc_concat.phy")
your partitions for above dataset ("partitions.txt" or "partitions.nex")
 

SECTION: Running the AU Test
24. Use the following code to run the AU Test with a likelihood approximation:

For partitioned data that uses a single model:
 

For partitioned data using multiple models (remember you will need the nexus-style partition file from Steps 18-20 for this):


 

SECTION: Running the AU Test
25. The results of the test are contained in the file ending in ".iqtree".
SECTION: File Preparation
9. Drag this file ("_constraint.nex") into a text editor (e.g. SublimeText) and remove everything except the tree notation/newick format (the portion in parentheses). See below for an example of what this looks like. Save this as "_constraint.txt". in case the .nex version fails in RAxML. 

 

SECTION: RAxML Likelihood Estimation
11. 
Open the RAxML GUI and ensure you're set to run using RAxML-ng. Load in your concatenated dataset (concat.txt) file from your original/unconstrained phylogenetic analysis in RAxML. Load in your partition file (part.txt) from that analysis as well.
SECTION: RAxML Likelihood Estimation
12. Now you will import the constraint tree file into RAxMLng as a multifurcating constraint. You can do this in the GUI by selecting (at the top menu) Analysis > Enforce Constraint > Use multifurcating constraint. When prompted, open your constraint tree file in either .nex or .txt format (either should work, but if .nex fails, try .txt).
SECTION: For Multiple Models: Prepare Partition File
20. 
 

SECTION: For Multiple Models: Prepare Partition File
21. Open your RAxML-style partition file in a text editor. You will need to convert it to a nexus-style partition file (example below). This file constrains a SETS block with CharSet and CharPartition commands to specify individual genes and the partition, respectively.

 
 

SECTION: For Multiple Models: Prepare Partition File
22. Save your nexus-style partition file as a .nex file (e.g. "partitions.nex")
 

SECTION: Programs and Dependencies
2. This protocol assumes you have already completed initial tree inference. It is designed to test another topology (constrained) against your unconstrained analysis. Before beginning this protocol, you will need:
 a copy of your unconstrained tree (.tre file)
the data you used to create the unconstrained tree (.phy file, probably nucleotide data)
knowledge/list of model(s) applied to your data
if you're running a partitioned analysis (multiple genes or data types), you will also need a partition file (.txt or .nex file)
SECTION: Combining Tree Files
18. When you save this tree in newick format, you'll lose the tree names youo created. This step will help you create a record or which tree was which so you can check back later if needed. Re-save tthe combined.nex file you just created as "_combined.tre". Now delete everything except the tree notation (look for parentheses/at example in this step :   ). This includes the tree names and any other symbols, except the parentheses involved with the trees themselves (do not delete those) and the semicolon after each tree. Now if you forget which tree is which, you know they're in the same order in this file as in the "_combined.nex"  file and can check back there if needed.