#!/usr/bin/env python
# coding: utf-8
#
ipyrad-analysis toolkit: Astral species trees
# Once you've run treeslider you now have a distribution of gene trees that you can use as input to a multi-locu species tree or network inference program. Here I demonstrate how to input your data to **astral**.
# ### Required software
# In[1]:
# conda install ipyrad -c bioconda
# conda install toytree -c eaton-lab
# In[2]:
import pandas as pd
import toytree
# ### Short Tutorial:
#
#
# In[4]:
# load the tree table from CSV
tree_table = pd.read_csv(
"./analysis-treeslider/test.tree_table.csv",
index_col=0,
)
# In[59]:
# examine top of table
tree_table.head()
# ### Write the trees column to a file
#
# In[11]:
outfile = open("trees.nwk", "w")
outfile.write("\n".join(tree_table.tree.tolist()))
outfile.close()
# ### Get Astral
# The following command will download and unzip Astral into the current directory. A binary to call the program *astral* will be located in the Astral directory.
# In[12]:
get_ipython().run_cell_magic('bash', '', 'wget -q https://github.com/smirarab/ASTRAL/raw/master/Astral.5.6.3.zip \nunzip -qo Astral.5.6.3\n')
# ### Run Astral
# This will write the results (stdout) to a file called astral.tre, and it will write other information printed to the screen (stderr) to a file called astral.err. By default astral runs 100 bootstrap replicates by gene-tree resampling. To turn on gene and site resampling would require inputting the bootstrap files, which we did not currently save (we could...).
# In[13]:
get_ipython().run_cell_magic('bash', '', 'java -jar Astral/astral.5.6.3.jar -i trees.nwk > astral.tre 2>astral.err\n')
# ### Plot astral species tree
# In[61]:
tre = toytree.rtree.coaltree(10)
tre.
# In[71]:
tre.rotate_node(names=["r0", "r1", "r2"])
# In[68]:
tre.draw(node_labels=True);
# In[60]:
tre = toytree.tree("astral.tre").root('reference')
tre.draw(node_labels="support", tip_labels_align=True);
# ### Plot astral species tree with quartet supports
# Not yet supported in toytree, what a wonky file format...