[Biopython] Qblast

Michiel de Hoon mjldehoon at yahoo.com
Wed Mar 27 03:47:22 UTC 2013


You could put a try/except block around the call to qblast, and wait for 5 minutes and repeat qblast if you get an HTTPError. Something like this:

for seq_record in SeqIO.parse(args.infile,"fasta"):
    ...
    while True:
        try:
            blast_result_handle = NCBIWWW.qblast(...
        except urllib2.HTTPError:
            time.sleep(300)
         else:
            break
    ... # do something with the blast_result_handle here


Best,
-Michiel.

--- On Tue, 3/26/13, Dan <dan837446 at gmail.com> wrote:

> From: Dan <dan837446 at gmail.com>
> Subject: [Biopython] Qblast
> To: biopython at lists.open-bio.org
> Date: Tuesday, March 26, 2013, 11:12 PM
> Hi, I have a script that runs Qblast
> over a multiline fasta file
> (protein).. the relevant code is:
> 
> for seq_record in SeqIO.parse(args.infile,"fasta"):
> # For each individual fasta record in a multiline fasta
> file..
> # check that it's an appropriate time to search and wait if
> not
>     <random irrelevant code to do this: I only
> search between 10pm and 5AM
> EST>
> # do the search
> 
>     blast_result_handle =
> NCBIWWW.qblast(args.program, args.database, \
>    
> seq_record.format("fasta"),expect=args.expect,
> hitlist_size=args.num_hits, \
>     service=args.service)
>     time.sleep(5)
> 
> Most of the time it works fine, but every so often it fails,
> like so:
> 
> Traceback (most recent call last):
>   File "remote_blast_multiline_fasta.py", line 174, in
> <module>
>     service=args.service)
>   File
> "/usr/lib/pymodules/python2.7/Bio/Blast/NCBIWWW.py", line
> 122, in
> qblast
>     handle = urllib2.urlopen(request)
>   File "/usr/lib/python2.7/urllib2.py", line 126, in
> urlopen
>     return _opener.open(url, data, timeout)
>   File "/usr/lib/python2.7/urllib2.py", line 406, in
> open
>     response = meth(req, response)
>   File "/usr/lib/python2.7/urllib2.py", line 519, in
> http_response
>     'http', request, response, code, msg, hdrs)
>   File "/usr/lib/python2.7/urllib2.py", line 444, in
> error
>     return self._call_chain(*args)
>   File "/usr/lib/python2.7/urllib2.py", line 378, in
> _call_chain
>     result = func(*args)
>   File "/usr/lib/python2.7/urllib2.py", line 527, in
> http_error_default
>     raise HTTPError(req.get_full_url(), code, msg,
> hdrs, fp)
> urllib2.HTTPError: HTTP Error 502: Bad Gateway
> 
> I'm assuming that this is a "overloaded blast server"
> error..
> Is there any way of handling this error in better way? Sorry
> if this
> question is a bit general.
> _______________________________________________
> Biopython mailing list  -  Biopython at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biopython
> 




More information about the Biopython mailing list