#!/usr/bin/env python # coding: utf-8 # In[1]: from __future__ import print_function import os import shutil import dendropy from dendropy.interop import raxml # In[2]: ebola_data = dendropy.DnaCharacterMatrix.get_from_path('trim.fasta', 'fasta') rx = raxml.RaxmlRunner() ebola_tree = rx.estimate_tree(ebola_data, ['-m', 'GTRGAMMA', '-N', '10']) print('RAxML temporary directory: %s' % rx.working_dir_path) del ebola_data # In[3]: ebola_tree.write_to_path('my_ebola.nex', 'nexus') # In[4]: import matplotlib.pyplot as plt from Bio import Phylo get_ipython().run_line_magic('matplotlib', 'inline') my_ebola_tree = Phylo.read('my_ebola.nex', 'nexus') my_ebola_tree.name = 'Our Ebolavirus tree' fig = plt.figure(figsize=(16, 18)) ax = fig.add_subplot(1, 1, 1) Phylo.draw(my_ebola_tree, axes=ax) # ## RAxML with Biopython # In[5]: import random import sys from Bio.Phylo.Applications import RaxmlCommandline raxml_cline = RaxmlCommandline(sequences='trim.fasta', model='GTRGAMMA', name='biopython', num_replicates='10', parsimony_seed=random.randint(0, sys.maxint), working_dir=os.getcwd() + os.sep + 'bp_rx') print(raxml_cline) try: os.mkdir('bp_rx') except OSError: shutil.rmtree('bp_rx') os.mkdir('bp_rx') out, err = raxml_cline() # In[6]: from Bio import Phylo biopython_tree = Phylo.read('bp_rx/RAxML_bestTree.biopython', 'newick') # In[7]: print(biopython_tree) # In[ ]: