from Bio import SeqIO
# Name of the input file
fh = open('out22.fas')
# Name of the output file
newfh = open('out3.fas','w')
for record in SeqIO.parse(fh,'fasta'):
    # Modify description
    record.description += '[Rattus norvegicus]'
    SeqIO.write([record],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.