[Biopython] Generator expression for SeqIO

Mic mictadlo at gmail.com
Wed Dec 7 04:41:25 UTC 2011


No worries is was perfect.

I have the following code and I do not know how to combine the *header* and
*seq* variables from the '*with*' statement with generator expression?

from Bio import SeqIO
from Bio.SeqRecord import SeqRecord
from Bio.Seq import Seq
from pprint import pprint

if __name__ == '__main__':

    *with* open('input.txt') as f:
        for line in f:
            try:
                splited_line = line.split('\t')

                *header* = splited_line[0] +'_'+ splited_line[2]
                *seq* = splited_line[3]
            except IndexError:
                continue

    fasta_file = open('output.fasta', 'w')
    records = (SeqRecord(???), id=????, description="") for i in ???)

    SeqIO.write(records, fasta_file, "fasta")

Thank you in advance.

On Thu, Dec 1, 2011 at 6:52 PM, Peter Cock <p.j.a.cock at googlemail.com>wrote:

>
>
> On Wednesday, November 30, 2011, Mic <mictadlo at gmail.com> wrote:
> > Thank you it is working.
> >
>
> Excellent - sorry I couldn't think of a nice way to explain the syntax.
>
> Peter



More information about the Biopython mailing list