This is a test version of Biostars. For the public version, visit https://www.biostars.org.
I am running blast over internet using biopython but its giving connection error but when I am doing same thing on shell its working fine.
import Bio
import csv
from Bio.Blast import NCBIXML
from Bio.Blast import NCBIWWW

q_id = []
with open('C:\Users\Nadia\Desktop\imran-sequenceIDs.csv','rb') as f:
    reader=csv.reader(f)
    for row in reader:
        q_id.append(row[0])
print 'sequence tags read'

with open('C:\\Users\\Nadia\\Desktop\\01-01A-Unigene.txt','r') as seq_file:
    seq_file=seq_file.readlines()
print 'sequence file read'

for i in range(0,len(q_id)):
    seq=[]
    if i>=1:
        for j,k in enumerate(seq_file):
            if str(q_id[i])in k:
                print 'tag matched',i
                start=j
                print start
                counter=1
                seq.append(k)
                while counter==1:
                    for l in range(start+1,len(seq_file)-(start+1)):
                        if not seq_file[l][0]=='>':
                            seq.append(seq_file[l])
                        else:
                            counter=2
                            break

    if seq:
        seq=''.join(seq)
        result_handle=NCBIWWW.qblast("blastn","nt",seq)
        blast_record=NCBIXML.read(result_handle)
        if not blast_record.alignments:
            print q_id[i], 'is novel'
        else:
            print q_id[i],'is not novel!'

This is my script and its generating following error

Traceback (most recent call last):
  File "C:\Python27\blast.py", line 37, in <module>
    result_handle=NCBIWWW.qblast("blastn","nt",seq)
  File "C:\Python27\lib\site-packages\Bio\Blast\NCBIWWW.py", line 163, in qblast
    handle = _urlopen(request)
  File "C:\Python27\lib\urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "C:\Python27\lib\urllib2.py", line 404, in open
    response = self._open(req, data)
  File "C:\Python27\lib\urllib2.py", line 422, in _open
    '_open', req)
  File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\urllib2.py", line 1214, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "C:\Python27\lib\urllib2.py", line 1184, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

Any suggestion would be really helpful.

biopython blast

1 answer

Using any online resource there will be network errors from time to time, or problems at the remote server. This is best dealt with using a try/except to catch the error, pause, and retry (up to some reasonable limit like 3 times).

However, for any large BLAST job, I would recommend installing BLAST and the NT database locally - it even works on Windows but the database is quite big. Your institute might have a local Linux cluster you could use instead?

Thanks for the suggestion I runned it on linux cluster and its working just fine :)

If this answer solved your question, please "accept" the answer. That's part of how BioStars and similar sites like Stack Exchange work.

Log in to answer this question.