#!/usr/bin/env python3
'''
Converts a fasta file to phylip format
'''
from Bio import AlignIO
from Bio.AlignIO.PhylipIO import PhylipWriter
import sys
infile = sys.argv[1]
outfile = sys.argv[2]
idwidth = int(sys.argv[3])
with open(infile, 'r') as input_handle:
align = AlignIO.read(input_handle, "fasta")
with open(outfile, 'w') as output_handle:
PhylipWriter(output_handle).write_alignment(align, id_width=idwidth)
Then, save this script as phylpwrtr.py and do:
chmod +x phylpwrtr.py
./phylpwrtr.py input.fa output_longids.phy 30 # 30 is the width of the header, adjust the value to adjust header length
The contents of output_longids.phy looks like:
4 32
virusA_detailed_description ACGTGACGAT CCCCAAACGT GACGATCCCC AA
virusB_detailed_description ACGTGACGAT CGGGAAACGT GACGATCGGG AA
virusC_detailed_description ACGTGACGAT CAAAAAACGT GACGATCAAA AA
virusD_detailed_description ACGTGACGAT TTTTAAACGT GACGATTTTT AA
I have nutted out a solution for you.
If this is the content of input.fa:
And this is the script:
Then, save this script as
phylpwrtr.pyand do:The contents of
output_longids.phylooks like:I have nutted out a solution for you.
If this is the content of input.fa:
And this is the script:
Then, save this script as
phylpwrtr.pyand do:The contents of
output_longids.phylooks like:More
VOTE
VOTE
VOTE
VOTE