Skip to main content
 首页 » 编程设计

python之从 biopython 使用 NCBIWWW 时出错

2025年04月02日9mfrbuaa

我正在尝试使用 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() 

这第一次运行良好,但几天后我尝试运行它时出现错误:

>     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 

我没有更改代码中的任何内容,所以我不明白发生了什么。 可能是什么问题?

谢谢!

请您参考如下方法:

最近当我尝试在蛋白质数据库上使用 qblast 时收到完全相同的错误消息。

修复:

我去了 Biopython github 并获得了 qblast 模块的源代码。

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

我在文本编辑器中打开它并在末尾添加了一个简单的脚本

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() 

然后我运行了整个程序,得到了我之前得到的结果。请注意,您不再需要导入语句。事实上,如果你有它们,它是行不通的。您现在正在脚本中定义函数。

我不确定为什么现在这是一个问题,但 NCBI 最近确实对格​​式进行了一些更改,因此可能与此有关。任何澄清将不胜感激,因为我知道这更多的是脚本小子工作而不是解决方案。