使用 Biopython 的搜索词返回登录号

问题描述 投票:0回答:2

我正在尝试将 Biopython (Entrez) 与搜索词一起使用,该搜索词将返回登录号(而不是 GI*)。

这是我的代码的一小段摘录:

from Bio import Entrez

Entrez.email = 'myemailaddress'
search_phrase = 'Escherichia coli[organism]) AND (complete genome[keyword])'
handle = Entrez.esearch(db='nuccore', term=search_phrase, retmax=100, rettype='acc', retmode='text')
result = Entrez.read(handle)
handle.close()
gi_numbers = result['IdList']
print(gi_numbers)

'745369752', '910228862', '187736741', '802098270', '802098269', “802098267”、“387610477”、“544579032”、“544574430”、“215485161”、 '749295052', '387823261', '387605479', '641687520', '641682562', '594009615', '557270520', '313848522', '309700213', '284919779', “215263233”、“544345556”、“544340954”、“144661”、“51773702”、 '202957457', '202957451', '172051323'

我确信我可以从地理标志转换为加入,但最好避免额外的步骤。我缺少什么魔法?

提前谢谢您。

*特别是因为 NCBI 正在逐步淘汰 GI 数字

python biopython
2个回答
3
投票

查看 NCBI 网站上 esearch

文档,只有两个 
rettype
可用 -
uilist
,这是您当前获取的默认 XML 格式(它被
Entrez.read() 解析为字典) 
)和
count
,只显示
Count
值(看
result
的完整内容,就在那里),我不清楚它的确切含义,因为它不代表总数
IdList
...

中的项目数

无论如何,

Entrez.esearch()
将采用您喜欢的
rettype
retmode
的任何值,但它仅返回
uilist
count
模式下的
xml
json
- 没有加入ID,没有没什么。

Entrez.efetch()
会传回给你各种很酷的东西,具体取决于你正在查询哪个数据库。当然,缺点是您需要通过一个或多个 ID 进行查询,而不是通过搜索字符串进行查询,因此为了获取您的登录 ID,您需要运行两个查询:

search_phrase = "Escherichia coli[organism]) AND (complete genome[keyword])"
handle = Entrez.esearch(db="nuccore", term=search_phrase, retmax=100)
result = Entrez.read(handle)
handle.close()
fetch_handle = Entrez.efetch(db="nuccore", id=results["IdList"], rettype="acc", retmode="text")
acc_ids = [id.strip() for id in fetch_handle]
fetch_handle.close()
print(acc_ids)

给予

['HF572917.2', 'NZ_HF572917.1', 'NC_010558.1', 'NZ_HG941720.1', 'NZ_HG941719.1', 'NZ_HG941718.1', 'NC_017633.1', 'NC_022371.1', “NC_022370.1”、“NC_011601.1”、“NZ_HG738867.1”、“NC_012892.2”、“NC_017626.1”、“HG941719.1”、“HG941718.1”、“HG941720.1”、“HG738867” .1'、'AM946981.2'、'FN649414.1'、'FN554766.1'、'FM180568.1'、'HG428756.1'、'HG428755.1'、'M37402.1'、'AJ304858.2 ', 'FM206294.1', 'FM206293.1', 'AM886293.1']

所以,我不太确定我是否满意地回答了你的问题,但不幸的是我认为答案是“没有魔法”。


0
投票

刚刚在这里找到了一些文档:https://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.ESearch

看起来如果您在 Entrez.esearch 参数中将“idtype”设置为“acc”,则可以直接返回入藏号列表,而无需使用 Entrez.efetch 使用 IdList 中的 GI 编号。

这对我有用:

search_phrase =“啤酒花” 流 = Entrez.esearch(db="nuccore", idtype='acc', term=search_phrase, usehistory='y', retmax=10) 结果 = Entrez.read(stream) ID = 结果['IdList'] 对于 ID 中的 acc: 打印(ACC) 流.close()

© www.soinside.com 2019 - 2024. All rights reserved.