Question: Fasta Module In Python/Biopython
2
gravatar for openly
7.3 years ago by
openly20
openly20 wrote:

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?

fasta python biopython • 5.8k views
ADD COMMENTlink modified 5.0 years ago by Biostar ♦♦ 20 • written 7.3 years ago by openly20

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 REPLYlink written 7.3 years ago by Brad Chapman9.4k

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 REPLYlink written 7.3 years ago by openly20
8
gravatar for brentp
7.3 years ago by
brentp23k
Salt Lake City, UT
brentp23k wrote:

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 COMMENTlink written 7.3 years ago by brentp23k
2

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 REPLYlink written 7.3 years ago by Brad Chapman9.4k

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 REPLYlink written 7.3 years ago by openly20

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 REPLYlink written 7.3 years ago by openly20

Wow! Thanks a lot!

ADD REPLYlink written 7.3 years ago by openly20

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

ADD REPLYlink written 7.3 years ago by brentp23k

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

ADD REPLYlink written 6.1 years ago by alhossary0
Please log in to add an answer.

Help
Access

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