<p>Python works great for tying everything together and file manipulations.  I find stepping out of Python, using system calls, best for alignment and tree building.  For example:</p>

<pre><code>os.system("mafft --auto {} &gt; {}" .format("unaligned_16s_seq_in_file.fasta", "alignment_out_file.fasta"))

os.system("raxml -f a -s {} -p 12345 -x 12345 -# 100 -m GTRCAT -n {}" .format("alignment_out_file.fasta", "tree_out_file.tre"))
</code></pre>

CC BY-SA 4.0
2020-02-19T00:29:43.177Z
2020-02-19T00:29:43.177Z
Stuber
<p>You simply use Biopython's SeqIO and AlignIO.
The documentation is <a href="https://biopython.org/wiki/AlignIO" rel="nofollow noreferrer">https://biopython.org/wiki/AlignIO</a> 
etc ...
The format you seek is phylip</p>

CC BY-SA 4.0
2020-02-18T23:12:04.453Z
Thank you for your response. I made a .phy file similar to the one here [link](https://github.com/biopython/biopython/blob/master/Tests/TreeConstruction/msa.phy#L1) (except that in mine, the length of the sequences is 253). I ensured that they all have the same length.  But when I ran  `al=AlignIO.read(open("for_tree_top10.phy"),"phylip")`, I got "ValueError: Sequences must all be the same length". I'm not sure why, because I explicitly checked that the sequences have the same length. Not sure what to do now :( Any thoughts?
Kaumz
CC BY-SA 4.0
2020-02-19T00:03:48.280Z
Possibly it is not a programming issue but formating. There is no simple answer to trouble shoot this. Could you ask this as a separate question please? Obviously it is solvable but there's several possibilities and the Moderators will intervene if there are multiple questions within a thread
M__
CC BY-SA 4.0
2020-02-19T15:31:10.013Z
I have asked the question here [link](https://stackoverflow.com/questions/60289336/biopython-gives-valueerror-sequences-must-all-be-the-same-length-even-though-se)
Kaumz
CC BY-SA 4.0
2020-02-19T16:33:26.657Z
thanks answered it
M__
CC BY-SA 4.0
2020-02-18T19:39:14.560Z
2020-02-18T19:39:14.560Z
M__
<p>I'm new here. I need to construct a phylogenetic tree from 16s Sequence data (merged 151 bp) and color the branches/nodes based on my experimental conditions. From <a href="https://towardsdatascience.com/molecular-phylogenetics-using-bio-phylo-57ce27492ee9" rel="nofollow noreferrer">this blog</a>, it looks like I need a .phy file to make the tree. I want to use Biopython for this since I'm reasonably comfortable with python.</p>
<p>I have a csv file with the 16s sequences, the phylogenetic information, and the &quot;name&quot; of the sequence, and the experimental conditions. How can I make a .phy file from this?</p>
<p>I would appreciate any help.
Thank you.</p>

<phylogenetics><python><phylogeny>
How to create a .phy file for constructing a phylogenetic tree?
# How to create a .phy file for constructing a phylogenetic tree?

(Asked by: username_0 on 2020-02-18)

I'm new here. I need to construct a phylogenetic tree from 16s Sequence data (merged 151 bp) and color the branches/nodes based on my experimental conditions. From [this blog](https://towardsdatascience.com/molecular-phylogenetics-using-bio-phylo-57ce27492ee9), it looks like I need a .phy file to make the tree. I want to use Biopython for this since I'm reasonably comfortable with python.

I have a csv file with the 16s sequences, the phylogenetic information, and the "name" of the sequence, and the experimental conditions. How can I make a .phy file from this?

I would appreciate any help.
Thank you.

**Tags:** phylogenetics, python, phylogeny

---

## 2 answers

### Answer by username_1 on 2020-02-19. Score: 1

Python works great for tying everything together and file manipulations.  I find stepping out of Python, using system calls, best for alignment and tree building.  For example:
os.system("mafft --auto {} > {}" .format("unaligned_16s_seq_in_file.fasta", "alignment_out_file.fasta"))

os.system("raxml -f a -s {} -p 12345 -x 12345 -# 100 -m GTRCAT -n {}" .format("alignment_out_file.fasta", "tree_out_file.tre"))


---

### Answer by username_2 on 2020-02-18. Score: 1

You simply use Biopython's SeqIO and AlignIO.
The documentation is <https://biopython.org/wiki/AlignIO>
etc ...
The format you seek is phylip

> **Comments:**
> **username_0**: Thank you for your response. I made a .phy file similar to the one here [link](https://github.com/biopython/biopython/blob/master/Tests/TreeConstruction/msa.phy#L1) (except that in mine, the length of the sequences is 253). I ensured that they all have the same length.  But when I ran  `al=AlignIO.read(open("for_tree_top10.phy"),"phylip")`, I got "ValueError: Sequences must all be the same length". I'm not sure why, because I explicitly checked that the sequences have the same length. Not sure what to do now :( Any thoughts?  
> **username_2**: Possibly it is not a programming issue but formating. There is no simple answer to trouble shoot this. Could you ask this as a separate question please? Obviously it is solvable but there's several possibilities and the Moderators will intervene if there are multiple questions within a thread  
> **username_0**: I have asked the question here [link](https://stackoverflow.com/questions/60289336/biopython-gives-valueerror-sequences-must-all-be-the-same-length-even-though-se)  
> **username_2**: thanks answered it  

---

