biopython
biopython copied to clipboard
FastaIterator has no attribute `next`
Setup
I am reporting a problem with Biopython 1.79, Python 3.10, and operating system Windows 10.
I was trying to split a large fasta file into fragments with fixed sequence length by the batch_iterator method written here: https://biopython.org/wiki/Split_large_file
But when reading fasta file, the iterpreter complains that FastaIterator has no next() attribute.
Expected behaviour
Split the fasta file into fragments in batch size.
Actual behaviour

Steps to reproduce
- Define the
batch_iteratormethod as the wiki link demonstrates; - run
record_iter = SeqIO.parse(open('path/to/sequence.fna'), 'fasta')
for i, batch in enumerate(batch_iterator(record_iter, 3000)):
filename = 'reference_%i.fasta' % (i + 1)
with open('/path/files/' + filename, 'w') as output_handle:
count = SeqIO.write(batch, output_handle, 'fasta')
print('Wrote %i records to %s' % (count, filename))
The example needs updating for Python 3, to use the built-in next(...) function.
I wonder if there is a more elegant solution, nothing in https://docs.python.org/3/library/itertools.html looks quite right though...
change entry = iterator.next() in function batch_iterator -> entry = next(iterator)
@BrutalStark yes, that's what I meant. Since the original reported never replied, do you want to make the change?
Never mind now. It might just require a minor update in the document, I guess?🤔
Ah, the "next" was never in the example page - it was in the code. You must have used an older Biopython which lacked that Python 3 fix?