I am trying to parse a few dozen sequences through BLAST, using Bio.Blast with NCBIWWW, in Python 2.7. Not a problem there with one or a couple sequences, but the NCBIWWW.qblast() always stops after about 5-7 iterative BLAST searches. Importantly, the program does not crash and exit with an error - it just stalls, and freezes for ever. I have to exit the application manually. This is not a problem with Internet connection, either - no errors that would suggest this.
I have no idea what is wrong. Is there a mistake in my code that prevents multiple BLAST searches, or are there alternative algorithms for this purpose?
My code:
from Bio.Blast import NCBIWWW
import urllib
def load_uniprot_fasta(identifier): #loads fasta file for a given UniProt identifier
link = "http://www.uniprot.org/uniprot/" + identifier + ".fasta"
f = urllib.urlopen(link)
content = f.read()
print content
print "\n"
new_file = open(str(identifier)+".seq", "w")
new_file.write(content)
evalue = 0.00001
id_list = open("list.list", "r") #this file is a list of UniProt identifiers, every line is a new identifier
for line in id_list:
uniprot_id = ""
uniprot_id = str(line).strip("\n")
load_uniprot_fasta(uniprot_id) #creates a <uniprot_id>.fasta file
fasta_object = open(str(uniprot_id)+".seq").read()
result_handle = NCBIWWW.qblast("blastp", "swissprot", fasta_object)
print "SUCCESS\n"