[Biopython] changing record attributes while iterating

Mic mictadlo at gmail.com
Thu Oct 20 09:38:56 UTC 2011


Hello,
would it be possible to using a generator expression for the following code?

from Bio import SeqIO

fa_parser = SeqIO.parse(open("../test_files/test.fasta", "rU"), "fasta")

sequence = fa_parser.next().seq

for record in fa_parser:
    sequence += 3*'N' + record.seq

print sequence

Input:
>1
1111111
>2
2222222
>3
3333333
>4
4444444

Output:
1111111NNN2222222NNN3333333NNN4444444

Thank you advance.


On Fri, Oct 7, 2011 at 5:22 PM, Peter Cock <p.j.a.cock at googlemail.com>wrote:

>
>
> On Friday, October 7, 2011, Michalwrote:
>
> > Hello,
> > Does your code with generator save the whole file in the
> > memory or does it read each entry and save it immediately?
> > Thank you in advance.
>
> Using a generator expression like that only one SeqRecord is in memory at a
> time. It goes through the input FASTA one record at a time, renames it,
> saves it immediately.
>
> Peter
>
> P.S. list CC'd



More information about the Biopython mailing list