[Biopython] changing record attributes while iterating
Mic
mictadlo at gmail.com
Thu Oct 27 01:14:16 UTC 2011
Thank you it is working.
I would like to to put sequences id in a list in the following way:
>>> c = (i.id for i in b)
SyntaxError: invalid syntax
>>> c[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'generator' object is not subscriptable
How is it possible to generate a list of sequence ids?
Thank you in advance.
On Thu, Oct 20, 2011 at 7:58 PM, Peter Cock <p.j.a.cock at googlemail.com>wrote:
> 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