I'm using Biopython 1.56 compiled from source on Ubuntu 10.10 64-bit. It's a great piece of software and I love to work with it. But there is a very strange behavior of the "Bio.SeqIO.parse()" sequence parser, which cost me several hours to find out:
If I uncomment the for-statement with the print commands, "Bio.SeqIO.write()" refuses to write the sequences to the file.
Is this the desired behavior? Is the for-loop iterating the parser object to its end and leaves it there? Could anyone help me out? What am I getting wrong?
Thanks in advance!
handle = open("ls_orchid.fasta", "fasta") parsedfasta = Bio.SeqIO.parse(handle, "fasta") # If you uncomment the following part, 0 Sequences # (instead of many more) are written to the file! #for seq_record in parsedfasta: #print "Description:\t%s..." % seq_record.description #print "Length:\t\t%d" % len(seq_record) #print "Sequence:\t%s\n" % seq_record.seq[:40], seq_record.seq[44:50]) output_handle = open("example.fasta", "w") count = Bio.SeqIO.write(parsedfasta, output_handle, "fasta") output_handle.close() print "%d Sequences written to file" % count
Great answer! I'll try to integrate these ideas into my code. Thank you.