from Bio import SeqIO
fh = open('out22.fas')
newfh = open('out22-GOOD.fas','w')
for record in SeqIO.parse(fh,'fasta'):
    if len(record.seq)!=0:
        SeqIO.write([record],newfh,'fasta')
        # Try (record,) as an alternative to [record]
newfh.close()

This code is part of the book "Python for Bioinformatics", by Sebastian Bassi (sbassi@genesdigitales.com). Return to home page.