25
I routinely use AlignIO in BioPython for manipulating alignments and in context here moving from fasta format to phylip format. Alot of phylogeny packages accept a relaxed (sequence ID) & sequential (sequence) phylip format. This format is user-friendly, helps double-check for alignment errors and can be the essential input format.
A typical bit of code is,
'''Converts a fasta file to phylip format'''from Bio import AlignIOClass Convert (inheritClass): def fa2phy (self): fileOut, fileIn = self._inOut() # builds the path name and deletes any pre-exising outfile align = AlignIO.read(fileIn, "fasta") # reads the alignment in fasta AlignIO.write(align, fileOut, "phylip-relaxed") # writes in phylipThe output of "phylip-relaxed" is interleaved format
4 120virusA_detailed_description ACGTGACG .... ATCCCCAAvirusB_detailed_description ACGTGACG .... ATCGGGAAvirusC_detailed_description ACGTGACG .... ATCAAAAAvirusD_detailed_description ACGTGACG .... ATTTTTAAACGTGACG .... ATCCCCAAACGTGACG .... ATCGGGAAACGTGACG .... ATCAAAAAACGTGACG .... ATTTTTAAOutput sought is relaxed-sequential
4 120virusA_detailed_description ACGTGACG .... ATCCCCAAACGTGACG .... ATCCCCAAvirusB_detailed_description ACGTGACG .... ATCGGGAAACGTGACG .... ATCGGGAAvirusC_detailed_description ACGTGACG .... ATCAAAAAACGTGACG .... ATCAAAAAvirusD_detailed_description ACGTGACG .... ATTTTTAAACGTGACG .... ATTTTTAAThere is an option to allow a sequential format (above). HOWEVER, a "phylip-sequential" option output is as follows (it truncates the sequence ID to 10 characters,
4 120virusA_det ACGTGACG .... ATCCCCAAACGTGACG .... ATCCCCAAvirusB_det ACGTGACG .... ATCGGGAAACGTGACG .... ATCGGGAAvirusC_det ACGTGACG .... ATCAAAAAACGTGACG .... ATCAAAAAvirusD_det ACGTGACG .... ATTTTTAAACGTGACG .... ATTTTTAANo matter how I look through AlignIO options the above is the nearest format. Could anyone point to a IO style solution?I could write it, but that defeats the object (i.e. purpose not an instance of a method).
Note the "...." in the outputs above are not a typical "sequence identity" symbols, it just means that total length of a line in an interleaved format is 60 nucleotides (it might be 80).
2026-10-25