[Biopython] gzip and SeqIo in python3: not working like before
Alan
alanwilter at gmail.com
Wed Mar 15 23:06:59 UTC 2017
Thanks Peter,
As desperate solution, I've done that:
from __future__ import print_function
import gzip
from Bio import SeqIO
from io import StringIO
data = gzip.open("file.fasta.gz", "r").read()
record = SeqIO.parse(StringIO(data.decode()), "fasta")
for rr in record:
print(rr.id)
But I will follow your suggestion.
Cheers,
Alan
On 15 March 2017 at 22:43, Peter Cock <p.j.a.cock at googlemail.com> wrote:
> 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
>
--
Alan Wilter SOUSA da SILVA, DSc
Senior Bioinformatician, UniProt
European Bioinformatics Institute (EMBL-EBI)
European Molecular Biology Laboratory
Wellcome Trust Genome Campus
Hinxton
Cambridge CB10 1SD
United Kingdom
Tel: +44 (0)1223 494588
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20170315/950cd089/attachment.html>
More information about the Biopython
mailing list