# How to create Phylogenetic Trees from fasta files in Python or R?

Given around hundred fasta files with DNA sequences with good coverage, how could I create a Phylogenetic Tree from it? Ideally in python or R. I found Phylo from Biopython only handles already calculated trees.

• Would you be open to using a program designed to do this or do you need to roll your own in a programming language? – terdon Feb 13 '19 at 17:35

I would not look for a package for this, but instead build a small pipeline calling external tools with something like the following workflow:

• Cluster the ~100 sequences with CD-HIT-EST/PSI-CD-HIT or many other options
• Take all the sequences that form one individual cluster and build a multiple sequence alignment (MSA) with MAFFT/ClustalOmega or similar
• Take the MSA and build a phylogenetic tree with a Maximum-Likelihood approach like iqtree or similar
• Visualize the tree file with Jalview or similar

Of course this is rather general and depending on exactly what you're doing you may want a different workflow and/or different tools. You should also explore the parameter space, do not assume the defaults are necessarily good choices

• Yes, I agree with this and thats what I do. R is has its uses however in phylogeny – Michael Feb 13 '19 at 22:03
• Jalview can also make the tree for you. Just load the alignment into jalview and tell it to build a tree from it. – terdon Feb 13 '19 at 22:57
• @terdon not recommended though, I think jalview only implements NJ – Chris_Rands Feb 14 '19 at 7:43
• Oh sure, I am not saying it's the best tool. I just know that ~10 years ago when I last used it, it was perfectly capable of producing a decent tree. But then I was using about a dozen sequences, all of which were homologous. So not a very hard tree to build. – terdon Feb 14 '19 at 9:12
• I agree with the first two steps. For the tree building I might consider RAxML. I might then load the finished tree into R with the ape/phangorn package for manipulation/visualisation. For stand-along visualisation figtree is great. – Jonathan Moore Feb 16 '19 at 20:53

I agree with Chris Rands that a reasonable approach would be to call external tools.

However, if you really want to do the phylogeny from within Python, you could use the P4 package, which is a bit complicated to handle but gives you lots of options in the way to build MCMC-based bayesian phylogenies:

https://github.com/pgfoster/p4-phylogenetics

You would still need something else to align the sequences before.

To visualize the tree using python, you could use the ete toolkit, which is likely more powerful than what you can find in Biopython: http://etetoolkit.org/

The obvious single answer is R "ape". This will give you access to PhylML for tree building and Clustal/Muscle for alignment building. The paths to the binarys are important. There are several distance methods in there such as NJ and BIONJ. Its distance approaches however don't look mainstream, but I could be wrong.

There are functions within ape which are cool, the tree sorting is very cool and I need to read through this with much greater care. Personally I wouldn't perform a core phylogenetic analysis within R, because the standalones are sufficient and the analysis is intensive.

https://cran.r-project.org/web/packages/ape/ape.pdf