[BioPython] qblast through a proxy

Andrew Dalke dalke at dalkescientific.com
Thu Jun 2 02:52:05 EDT 2005


Alexander A. Morgan wrote:
> However, Blast.NCBIWWW uses the socket library in '_send_to_qblast()'. 
>  There doesn't seem to be an easy way to get through a proxy using the 
> low level socket library.  Does anyone have a quick fix/workaround for 
> this?

I ran into that a couple months ago, but didn't have the time to
fix it then or now.

Something like this should work.  I've picked values ("User-Agent",
1024 bytes per copy block) to exactly equal the existing code, though
the 1024 seems limiting.

import urllib2, shutil

def _send_to_blasturl(query, outhandle):
   req = urllib2.Request(
      "http://www.ncbi.nlm.nih.gov/cgi-bin/BLAST/nph-blast_report",
      query, {"User-Agent: "BiopythonClient"})
   inhandle = urllib2.urlopen(req)
   shutil.copyfileobj(inhandle, outhandle, 1024)
   inhandle.close()


However, the upstream code might be fixed.  It's currently

     outhandle = cStringIO.StringIO()
     _send_to_blasturl(message, outhandle)
     outhandle.seek(0)   # Reset the handle to the beginning.
     return outhandle


and with a urllib2.open result it's a file-like object,
so the cStringIO is only needed if the code needs to
be reseekable.  I don't know if it does or doesn't.

Another difference is the urllib2 code parses in the
headers while the existing code doesn't.  I don't know
how that affects the actual parser; looks like it doesn't.

					Andrew
					dalke at dalkescientific.com



More information about the BioPython mailing list