Question: AttributeError: module 'Bio.SeqIO' has no attribute 'parse'
gravatar for oooyueooo
21 months ago by
oooyueooo10 wrote:

The codes which import Biopython and parse the files have worked on my laptop. Now I have a very big file that I can only parse it on another computer which also have installed python and Biopython. But on that computer, it gives me error message. I have uninstalled and reinstalled the latest python and biopython. The problem is still there.

The entire code is:

from Bio import SeqIO

with open('/Users/yuewang/work/18s_tree/aligned_fungi_rna.fasta', 'w') as output:

with open('/Users/yuewang/work/18s_tree/SILVA_132_SSURef_tax_silva_full_align_trunc.fasta') as fastafile:
    record_iterator = SeqIO.parse(fastafile, 'fasta')

    fungi = 'Eukaryota;Opisthokonta;Nucletmycea;Fungi;'
        for record in record_iterator:
            if fungi in
                with open('/Users/yuewang/work/18s_tree/aligned_fungi_rna.fasta', 'a') as output:

Error message:

Traceback (most recent call last):
  File "", line 1, in <module>
    from Bio import SeqIO
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Bio/SeqIO/", line 391, in <module>
    from . import UniprotIO
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Bio/SeqIO/", line 34, in <module>
    from xml.etree import cElementTree as ElementTree
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/xml/etree/", line 3, in <module>
    from xml.etree.ElementTree import *
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/xml/etree/", line 1660, in <module>
    from _elementtree import *
  File "/Users/yuewang/work/18s_tree/", line 7, in <module>
    record_iterator = SeqIO.parse(fastafile, 'fasta')
AttributeError: module 'Bio.SeqIO' has no attribute 'parse'

Please let me know if my question is not clear enough.

biopython • 1.3k views
ADD COMMENTlink modified 10 months ago by kalilamali0 • written 21 months ago by oooyueooo10

I dont think this is likely to solve the issue, but try it first (I think there’s something messed up in your install still).

You do not need to use the open() construct when using SeqIO, it does that for you, and also you open your output file twice needlessly.

Try refactoring this code to:

from Bio import SeqIO

record_iterator = SeqIO.parse(‘/path/to/fastafile.fa’, ‘fasta’)
with open(‘/path/to/output.fa’, ‘w’) as output:
    for record in record_iterator:
        if ‘Eukaryota;Opisthokonta;Nucletmycea;Fungi’ in
ADD REPLYlink written 21 months ago by Joe17k

Thanks Healey. Although it doesn't solve the issue, it does make the script better. I also posted my question on stackoverflow yesterday and it solved with the answer.

ADD REPLYlink written 21 months ago by oooyueooo10

Interesting. I’ve been caught out by that before.

As a general rule, it’s a bad idea to name anything of your own the same as a python component. This means you’ll need to try and avoid names like copy, return, str which it might be tempting to name a script or a variable after etc.

ADD REPLYlink written 21 months ago by Joe17k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 958 users visited in the last hour