import sys
from Bio import SeqIO
from Bio import AlignIO
from Bio import Alphabet 
from Bio.Align import MultipleSeqAlignment

# usage: python convert.py <infile> <outfile> <format>
with open(sys.argv[1], "rU") as handle:
    
    records = {}
    for seq in SeqIO.parse(handle, "fasta"):
        fields  = seq.description.split('|')
        seq.seq = seq.seq.upper()
        records[fields[0]] = seq
    
    aln = MultipleSeqAlignment([ records[key] for key in sorted(records.keys()) ])

    # if error, try adding argument alphabet=Alphabet.generic_dna
    AlignIO.write(aln, sys.argv[2], sys.argv[3] )
import sys
from Bio import SeqIO
from Bio import AlignIO
from Bio import Alphabet 
from Bio.Align import MultipleSeqAlignment

# usage: python convert.py <infile> <outfile> <format>
with open(sys.argv[1], "rU") as handle:
    
    records = {}
    for seq in SeqIO.parse(handle, "fasta"):
        fields  = seq.description.split('|')
        seq.seq = seq.seq.upper()
        records[fields[0]] = seq
    
    aln = MultipleSeqAlignment([ records[key] for key in sorted(records.keys()) ])

    # if error, try adding argument alphabet=Alphabet.generic_dna
    AlignIO.write(aln, sys.argv[2], sys.argv[3] )
# usage: python convert.py <infile> <outfile> <format> # if error, try adding argument alphabet=Alphabet.generic_dna