from Bio import SeqIO
# Name of the input file
fh = open('out22.fas')
# Name of the output file
newfh = open('out22-GOOD.fas','w')

def retseq(seqfh):
    for record in SeqIO.parse(seqfh,'fasta'):
        if len(record.seq)!=0:
            yield record

SeqIO.write(retseq(fh),newfh,'fasta')
newfh.close()
fh.close()

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