2

I am trying to blast nucleotide sequence using NCBIWWW

from Bio.Blast import NCBIWWW
my_query = "TGCGTGCCGTGCAATGTGCGT"
result_handle = NCBIWWW.qblast("blastn", "nt", my_query)
blast_result = open("my_blast.xml", "w") 
blast_result.write(result_handle.read())
blast_result.close()
result_handle.close()

This was working well for the fist time, but when I tried to run it few days later I got an error:

>     result_handle = NCBIWWW.qblast("blastn", "nt", my_query)   File "/usr/local/lib/python2.7/dist-packages/biopython-1.63-py2.7-linux-x86_64.egg/Bio/Blast/NCBIWWW.py", line 123, in qblast
>     handle = _urlopen(request)   File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
>     return _opener.open(url, data, timeout)   File "/usr/lib/python2.7/urllib2.py", line 410, in open
>     response = meth(req, response)   File "/usr/lib/python2.7/urllib2.py", line 523, in http_response
>     'http', request, response, code, msg, hdrs)   File "/usr/lib/python2.7/urllib2.py", line 448, in error
>     return self._call_chain(*args)   File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
>     result = func(*args)   File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default
>     raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 403: Forbidden

I didn't change anything in the code so I don't understand what happened. What can be the problem?

Thanks!

reut
  • 21
  • 2
  • 1
    Did you by chance run it with python3 the first time but python2 this time? – Eli Sadoff Nov 15 '16 at 13:54
  • 1
    Sorry, I can't replicate your issue using the code you provided using BioPython 1.68 on Windows 10 with either Python 3.5.2 or 2.7.12. Are you using different versions of Biopython with 3 and 2? Have you tried again recently to see if it's working now? – MattDMo Nov 15 '16 at 21:00
  • I used Python 2.7.6 in both times. I run run it few times since than and still not working... – reut Nov 17 '16 at 08:28

2 Answers2

1

I got the exact same error message recently when I tried to use qblast on the protein database.

The fix:

I went to the Biopython github and got the source code for the qblast module.

https://github.com/biopython/biopython/blob/master/Bio/Blast/NCBIWWW.py

I opened it up in a text editor and added a simple script to the end

fasta_string = open("test500.fasta").read()

result_handle = qblast(
"blastp",
"swissprot",
fasta_string,
)
save_file = open("out.xml", "w")

save_file.write(result_handle.read())

save_file.close()

result_handle.close()

I then ran the whole program, and got the results I had gotten previously. Note that you don't need the import statements any more. In fact, it won't work if you have them. You're defining the function in your script now.

I am not sure why this is an issue now, but NCBI did make some formatting changes recently, so it might be related to that. Any clarification would be appreciate as I know this is more of script-kiddie work around than a solution.

1

I had the same error coming up using blastn. Looks like NCBI have moved from http to https (https://www.ncbi.nlm.nih.gov/home/develop/https-guidance.shtml). If you follow the link you'll see that you need Biopython version 1.67 or higher to use NCBIWWW now. I've just upgraded to biopython 1.68 and this has fixed my issue, hope that helps you too.

user3732664
  • 101
  • 1
  • 3