HTTP错误405用于以前用于查询Uniprot ID映射的代码

发布于 2025-02-11 13:01:23 字数 1715 浏览 0 评论 0 原文

在我的一个脚本中,我使用以下代码块来查询使用另一种ID的蛋白质ID:

import os
import sys
import urllib.request

uniprot = 'A0A0M3KKX3'
url = 'https://www.uniprot.org/uploadlists/'
params = {
'from': 'ACC',
'to': 'PDB_ID',
'format': 'tab',
'query': uniprot,
'species': 'human'
     }

dat = urllib.parse.urlencode(params)
dat = dat.encode('utf-8')
req = urllib.request.Request(url, dat)
with urllib.request.urlopen(req) as f:
    response = f.read()

在过去的几个月中,涉及此方法的代码可靠地起作用,使我能够在顶部构建我的算法这些功能。但是,截至昨晚,运行相同的代码,我收到以下错误:

Traceback (most recent call last):
  File "\\wsl.localhost\Ubuntu\home\defrondevillec\FASTAtest.py", line 21, in <module>
    with urllib.request.urlopen(req) as f:
  File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 525, in open
    response = meth(req, response)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
  File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 563, in error
    return self._call_chain(*args)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 405: Not Allowed

我该如何解决此问题?

In one of my scripts, I utilized the following block of code to query for the ID of a protein using another type of ID:

import os
import sys
import urllib.request

uniprot = 'A0A0M3KKX3'
url = 'https://www.uniprot.org/uploadlists/'
params = {
'from': 'ACC',
'to': 'PDB_ID',
'format': 'tab',
'query': uniprot,
'species': 'human'
     }

dat = urllib.parse.urlencode(params)
dat = dat.encode('utf-8')
req = urllib.request.Request(url, dat)
with urllib.request.urlopen(req) as f:
    response = f.read()

For the past few months, code involving this method has worked reliably, allowing me to build my algorithm on top of these features. However, as of last night, running the same code, I received the following error:

Traceback (most recent call last):
  File "\\wsl.localhost\Ubuntu\home\defrondevillec\FASTAtest.py", line 21, in <module>
    with urllib.request.urlopen(req) as f:
  File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 525, in open
    response = meth(req, response)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
  File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 563, in error
    return self._call_chain(*args)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 405: Not Allowed

How would I go about fixing this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多像笑话 2025-02-18 13:01:23

我只是遇到了同样的问题 - Uniprot已推出了一个新的网站和一系列服务。目前,旧的可以在 lagacy.uniprot.org

短期修复

使用 https://legacy.uniprot.org/uploadlists/ 作为代码中的URL。这是在我的代码中使用类似查询的代码(uniprotid - &gt; Gene名称)

长期修复

可能最好地迁移到新的ID映射服务,该服务已记录在此处:

https://wwwww.uniprot.org/help/help/help/id_mapping ID映射请求,该请求返回工作ID,然后对结果进行轮询,文档底部有一些示例python代码: https://www.uniprot.org/help/id_mapping#pypython-example (下面重现)

import requests
import time
import json

POLLING_INTERVAL = 3
API_URL = "https://rest.uniprot.org"


def submit_id_mapping(fromDB, toDB, ids):
    r = requests.post(
        f"{API_URL}/idmapping/run", data={"from": fromDB, "to": toDB, "ids": ids},
    )
    r.raise_for_status()
    return r.json()["jobId"]


def get_id_mapping_results(job_id):
    while True:
        r = requests.get(f"{API_URL}/idmapping/status/{job_id}")
        r.raise_for_status()
        job = r.json()
        if "jobStatus" in job:
            if job["jobStatus"] == "RUNNING":
                print(f"Retrying in {POLLING_INTERVAL}s")
                time.sleep(POLLING_INTERVAL)
            else:
                raise Exception(job["jobStatus"])
        else:
            return job


job_id = submit_id_mapping(
    fromDB="UniProtKB_AC-ID", toDB="ChEMBL", ids=["P05067", "P12345"]
)
results = get_id_mapping_results(job_id)
print(json.dumps(results, indent=2))

I've just hit the same issue - Uniprot have launched a new website and series of services. For now the old ones are available at legacy.uniprot.org

Short term fix

Use https://legacy.uniprot.org/uploadlists/ as the URL in your code. This is working in my code for a similar query (uniprotID -> gene name)

Longer term fix

Probably best to migrate to the new ID Mapping service, which is documented here:
https://www.uniprot.org/help/id_mapping

You are now required to make an ID Mapping request, which returns a job ID, then poll for the result, there is some sample python code at the bottom of the docs: https://www.uniprot.org/help/id_mapping#python-example (reproduced below)

import requests
import time
import json

POLLING_INTERVAL = 3
API_URL = "https://rest.uniprot.org"


def submit_id_mapping(fromDB, toDB, ids):
    r = requests.post(
        f"{API_URL}/idmapping/run", data={"from": fromDB, "to": toDB, "ids": ids},
    )
    r.raise_for_status()
    return r.json()["jobId"]


def get_id_mapping_results(job_id):
    while True:
        r = requests.get(f"{API_URL}/idmapping/status/{job_id}")
        r.raise_for_status()
        job = r.json()
        if "jobStatus" in job:
            if job["jobStatus"] == "RUNNING":
                print(f"Retrying in {POLLING_INTERVAL}s")
                time.sleep(POLLING_INTERVAL)
            else:
                raise Exception(job["jobStatus"])
        else:
            return job


job_id = submit_id_mapping(
    fromDB="UniProtKB_AC-ID", toDB="ChEMBL", ids=["P05067", "P12345"]
)
results = get_id_mapping_results(job_id)
print(json.dumps(results, indent=2))
北座城市 2025-02-18 13:01:23

现在,您可以使用迈克尔·米尔顿(Michael Milton)(@多聚元素)要在Python中进行ID映射,请参见公告。该软件包还可以与Uniprot在2022 REST API中的新产品配合使用。

示例在原始帖子中使用Unipredsed:

from unipressed import IdMappingClient
request = IdMappingClient.submit(
    source="UniProtKB_AC-ID", dest="PDB", ids={"A0A0M3KKX3"}
)
list(request.each_result())

结果:

[{'from': 'A0A0M3KKX3', 'to': '4U7N'},
 {'from': 'A0A0M3KKX3', 'to': '4U7O'},
 {'from': 'A0A0M3KKX3', 'to': '4ZKI'}]

请参阅使用它进行三个人类基因的ID映射到Uniprot标识符/登录代码在这里。该帖子还具有链接,以获取有关未经许可的软件包的更多信息,以及用于锻炼 source 和目标( dest )详细信息的建议。

查看更多示例使用Unipredsed访问Uniprot的新REST API 和在底部来自“从 - 到”结果的熊猫数据框。

更新:我做了一个存储库,允许在浏览器中运行此和其他未经许可的示例,而无需在计算机上安装任何内容。首先,Go 在这里,然后单击任何'启动binder '徽章。

You can now use the Unipressed package by Michael Milton (@multimeric) to do ID mapping in Python, see the announcement. This package also works with UniProt's new in 2022 REST API.

Example from original post using Unipressed:

from unipressed import IdMappingClient
request = IdMappingClient.submit(
    source="UniProtKB_AC-ID", dest="PDB", ids={"A0A0M3KKX3"}
)
list(request.each_result())

Result:

[{'from': 'A0A0M3KKX3', 'to': '4U7N'},
 {'from': 'A0A0M3KKX3', 'to': '4U7O'},
 {'from': 'A0A0M3KKX3', 'to': '4ZKI'}]

See an example of using it to do ID mapping of three human genes to UniProt identifier / accession code here. That post also has links for more information about the Unipressed package and advice for working out source and destination (dest) details.

See more examples of using Unipressed to access Uniprot's new REST API here in my reply to Biostar's post 'Accessing UNIPROT using REST API', and at the bottom here includes making a Pandas dataframe from the 'from - to' results.

UPDATE: I made a repo that allows running this and other Unipressed examples right in your browser without installing anything on your machine. To get started, go here and click any 'launch binder' badge.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文