Home > Community > Relaxed and sequential Phylip format conversion
Upvote

25

Downvote
+ Bioinformatics
+ Biochemistry
+ Phylogenetics
Posted by
Mitu Howlader

Relaxed and sequential Phylip format conversion

Ashish Virmani  Follow

I have nutted out a solution for you.

If this is the content of input.fa:

>virusA_detailed_descriptionACGTGACGATCCCCAAACGTGACGATCCCCAA>virusB_detailed_descriptionACGTGACGATCGGGAAACGTGACGATCGGGAA>virusC_detailed_descriptionACGTGACGATCAAAAAACGTGACGATCAAAAA>virusD_detailed_descriptionACGTGACGATTTTTAAACGTGACGATTTTTAA

And this is the script:

#!/usr/bin/env python3'''Converts a fasta file to phylip format'''from Bio import AlignIOfrom Bio.AlignIO.PhylipIO import PhylipWriterimport sysinfile = 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 32virusA_detailed_description    ACGTGACGAT CCCCAAACGT GACGATCCCC AAvirusB_detailed_description    ACGTGACGAT CGGGAAACGT GACGATCGGG AAvirusC_detailed_description    ACGTGACGAT CAAAAAACGT GACGATCAAA AAvirusD_detailed_description    ACGTGACGAT TTTTAAACGT GACGATTTTT AA

More

Upvote

VOTE

Downvote
Dustin Covey  Follow
is the solution ... huge thanks! :-)More
Upvote

VOTE

Downvote
Frank Popa  Follow
Wow! Thank you More
Upvote

VOTE

Downvote
Joshua Kabwe  Follow
PhylipWriterMore
Upvote

VOTE

Downvote