[Biopython] Writting fasta file
Brad Chapman
chapmanb at 50mail.com
Thu Aug 26 11:55:17 UTC 2010
Hello;
> >Did you try looking in the tutorial? i.e.
> >http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec:SeqIO-reverse-complement
> >
> >You could modify your code to use a generator expression like this:
> >
> >def make_rc(record):
> > """Modifies a SeqRecord in place, and returns it."""
> > record.seq = record.seq.reverse_complement()
> > return record
> >records = (make_rc(r) for r in SeqIO.parse(in_opts.inputFasta, "fasta"))
> >SeqIO.write(records, out_opts.outputFasta, "fasta")
[...]
> In order to save memory is it possible to write each record ie. one
> by one with SeqIO.write instead of all records at once?
That's what Peter's code does. The write function pulls one record at
a time from the records generator. In addition to the Biopython
documentation, Andrew has a nice tutorial which goes into the
details of generators:
http://www.dalkescientific.com/writings/NBN/generators.html
Brad
More information about the Biopython
mailing list