Fasta Module In Python/Biopython
1
2
Entering edit mode
12.9 years ago
openly ▴ 20

I am trying to run a python script http://globplot.embl.de/html/GlobPipe-2.3.tgz for predicing globular regions in proteins. Unfortunalte, there is a Python error which is probably related to biopython.

I don't speak python, so I am not sure what is going on, but it seems like the offending statment is line 9:

from Bio import Fasta

which results in the error

ImportError: cannot import name Fasta

I do have BioPython installed (and line 8 works fine although it is also an import from Bio).

I tried to get information from the BioPython page, but I wasn't even able to find a list of functions/procedures/modules that are provided by "Bio". Is this some call to a BioPython function that no longer exists? If so, is there a drop-in replacement?

python biopython fasta • 9.8k views
ADD COMMENT
0
Entering edit mode

Bio.Fasta was deprecated in version 1.48 and removed in 1.55. If you just want to get the script working you can manually install a version older than 1.55 (http://biopython.org/wiki/Download) and use it with your script. Brent has exactly the right answer for updating the code to work with current Biopython version.

ADD REPLY
0
Entering edit mode

Thanks for this explanation! This is what I suspected. I don't think it is a good idea to install an old Biopython version (and to make sure that it isn't updated with the rest of ubuntu). I will try to do it the hard way by changing the script.

ADD REPLY
8
Entering edit mode
12.9 years ago
brentp 24k

Have a look here.

You'll be using the SeqIO module. Here's the example from that page:

from Bio import SeqIO
handle = open("example.fasta", "rU")
for record in SeqIO.parse(handle, "fasta") :
    print record.id
handle.close()
ADD COMMENT
2
Entering edit mode

Here's an updated version of the function: https://gist.github.com/1527553 The code pre-dates some nice Python features like iterators, so we can now avoid all of the 'while 1' loop code (that means loop forever, and then the break is used to exit the loop).

ADD REPLY
0
Entering edit mode

Thanks for the suggestion! I tried to follow your advice and kind of succeeded. (I had to change a few other things, too, because the 'record' returned by SeqIO appears to have a different structure from that returned by Fasta). The bit that I still have to figure out is how to modify the loop that loads the next sequence in a multi-fasta file.

ADD REPLY
0
Entering edit mode

Changing the loop does not work as expected. In the original code, there was a line like "iterator = Fasta.Iterator(db,parser)" before the loop and then a line like "cur_record = iterator.next()" within a while-loop. After reading some biopython manual, I changed this to "cur_record = SeqIO.parse(db,"fasta").next()" within the loop, but this works only for the first sequence. After that, I get an error message. Maybe the loop condition is not correct? It is "while 1" in the original script, but I don't know what the "1" is supposed to mean

ADD REPLY
0
Entering edit mode

Wow! Thanks a lot!

ADD REPLY
0
Entering edit mode

thanks @Brad ! If you post an answer including the gist, it'll be more informative than my snippet.

ADD REPLY
0
Entering edit mode

Thanks brentp & Brad Chapman. I was facing the same problem with the same file; and you saved me from a lot of headache.

ADD REPLY

Login before adding your answer.

Traffic: 1625 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6