[Biopython] changing record attributes while iterating

Peter Cock p.j.a.cock at googlemail.com
Thu Oct 20 09:58:05 UTC 2011


Hi Mic,

You should have started a new thread with a new title...

On Thu, Oct 20, 2011 at 10:38 AM, Mic <mictadlo at gmail.com> wrote:
> 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.

Sure, how about this:

from Bio import SeqIO
fa_parser = SeqIO.parse("../test_files/test.fasta", "fasta")
print ('N' * 3).join(str(rec.seq) for rec in fa_parser)

Peter




More information about the Biopython mailing list