[Biopython] gzip and SeqIo in python3: not working like before

Peter Cock p.j.a.cock at googlemail.com
Wed Mar 15 22:43:29 UTC 2017


Hi Alan,

Its a really strange error message isn't it? The good
news is its easy to fix.

Its due to a Python 3 bug / design choice, gzip.open
defaults to bytes so you need to use mode "rt". See:

http://bugs.python.org/issue13989

We've updated the examples in the tutorial ready for
Biopython 1.69

See eg

https://github.com/biopython/biopython/issues/1009
https://github.com/biopython/biopython/commit/63194ccff5d72ee78c4bcd1ba72173b8cf3d19f9

Peter

On Wed, Mar 15, 2017 at 9:25 PM, Alan <alanwilter at gmail.com> wrote:
> Please, what do I need to change in this example that works fine in python2
> but not in python3:
>
> from __future__ import print_function
> import gzip
> from Bio import SeqIO
> handle = gzip.open("file.fasta.gz", "r")
> record = SeqIO.parse(handle, "fasta")
> for rr in record:
>     print(rr.id)
>
> IndexError: index out of range
>
> Thanks,
>
> Alan
>
> _______________________________________________
> Biopython mailing list  -  Biopython at mailman.open-bio.org
> http://mailman.open-bio.org/mailman/listinfo/biopython


More information about the Biopython mailing list