#!/usr/bin/env python # coding: utf-8 # # Inferring species trees with *tetrad* # # When you install _ipyrad_ a number of analysis tools are installed as well. This includes the program __tetrad__, which applies the theory of phylogenetic invariants (see Lake 1987) to infer quartet trees based on a SNP alignment. It then uses the software wQMC to join the quartets into a species tree. This combined approach was first developed by Chifman and Kubatko (2015) in the software *SVDQuartets*. # ### Required software # In[ ]: ## conda install ipyrad -c ipyrad ## conda install toytree -c eaton-lab # In[1]: import ipyrad.analysis as ipa import ipyparallel as ipp import toytree # ### Connect to a cluster # In[2]: ## connect to a cluster ipyclient = ipp.Client() print("connected to {} cores".format(len(ipyclient))) # ### Run tetrad # In[3]: ## initiate a tetrad object tet = ipa.tetrad( name="pedic-full", seqfile="analysis-ipyrad/pedic-full_outfiles/pedic-full.snps.phy", mapfile="analysis-ipyrad/pedic-full_outfiles/pedic-full.snps.map", nboots=100, ) # In[4]: ## run tetrad on the cluster tet.run(ipyclient=ipyclient) # ### Plot the tree # In[8]: ## plot the resulting unrooted tree import toytree tre = toytree.tree(tet.trees.nhx) tre.draw( width=350, node_labels=tre.get_node_values("support"), ); # In[12]: ## save the tree as a pdf import toyplot.pdf toyplot.pdf.render(canvas, "analysis-tetrad/tetrad-tree.pdf") # ### What does *tetrad* do differently from *svdquartets*? # # Not too much currently. But we have plans to expand it. Importantly, however, the code is open source meaning that anybody can read it and contribute it, which is not the case for Paup\*. *tetrad* is also easier to install using conda and therefore easier to setup on an HPC cluster or local machine, and it can be parallelized across an arbitrarily large number of compute nodes while retaining a super small memory footprint.