RAxML is the most popular tool for inferring phylogenetic trees using maximum likelihood. It is fast even for very large data sets. The documentation for raxml is huge, and there are many options. However, I tend to use the same small number of options very frequently, which motivated me to write the ipa.raxml()
tool to automate the process of generating RAxml command line strings, running them, and accessing the resulting tree files. The simplicity of this tool makes it easy to incorporate into other more complex tools, for example, to infer tress in sliding windows along the genome using the ipa.treeslider
tool.
In [1]:
# conda install ipyrad -c bioconda
# conda install raxml -c bioconda
# conda install toytree -c eaton-lab
In [2]:
import ipyrad.analysis as ipa
import toytree
The raxml tool takes a phylip formatted file as input. In addition you can set a number of analysis options either when you init the tool, or afterwards by accessing the .params
dictionary. You can view the raxml command string that is generated from the input arguments and you can call .run()
to start the tree inference.
This example takes about 3-5 minutes to run on my laptop for a data set with 13 samples and ~1.2M SNPs and about 14% missing data.
In [6]:
# the path to your phylip formatted output file
phyfile = "../min10_outfiles/min10.phy"
In [7]:
# init raxml object with input data and (optional) parameter options
rax = ipa.raxml(data=phyfile, T=4, N=10)
# print the raxml command string for prosperity
print(rax.command)
# run the command, (options: block until finishes; overwrite existing)
rax.run(block=True, force=True)
In [8]:
# (optional) draw your tree in the notebook
import toytree
# load from the .trees attribute of the raxml object, or from the saved tree file
tre = toytree.tree(rax.trees.bipartitions)
# draw the tree
rtre = tre.root(wildcard="prz")
rtre.draw(tip_labels_align=True, node_labels="support");
By default several parameters are pre-set in the raxml object. To remove those parameters from the command string you can set them to None. Additionally, you can build complex raxml command line strings by adding almost any parameter to the raxml object init, like below. You probably can't do everythin in raxml using this tool, it's only meant as a convenience. You can always of course just write the raxml command line string by hand instead.
In [23]:
# init raxml object
rax = ipa.raxml(data=phyfile, T=4, N=10)
# parameter dictionary for a raxml object
rax.params
Out[23]:
In [24]:
# paths to output files produced by raxml inference
rax.trees
Out[24]:
In [9]:
rax = ipa.raxml(
data=phyfile,
name="test",
workdir="analysis-raxml",
m="GTRGAMMA",
T=20,
f="a",
N=100,
)
print(rax.command)
Another common option: Perform N rapid hill-climbing ML analyses from random starting trees, with no bootstrap replicates.
In [10]:
rax = ipa.raxml(
data=phyfile,
name="test",
workdir="analysis-raxml",
m="GTRGAMMA",
T=20,
f="d",
N=10,
x=None,
)
print(rax.command)