我正在尝试将 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'
我确信我可以从 GI 转换为加入,但最好避免额外的步骤。我缺少什么魔法?
提前谢谢您。
*特别是因为 NCBI 正在逐步淘汰 GI 编号
最佳答案
浏览 docs for esearch
在NCBI的网站上,只有两个rettype
可用 - uilist
,这是您当前获得的默认 XML 格式(它被 Entrez.read()
解析为字典),和 count
,它只显示 Count
值(查看 result
的完整内容,它就在那里),我不清楚它的确切含义,因为它并不代表 IdList
中的项目总数...
无论如何,Entrez.esearch()
将取 rettype
的任何值和retmode
你喜欢,但它只返回 uilist
或count
在xml
或json
模式 - 没有加入 ID,什么都没有。
Entrez.efetch()
会传给你 all sorts of cool stuff ,具体取决于您要查询的数据库。当然,缺点是您需要通过一个或多个 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']
所以,我不太确定我是否满意地回答了你的问题,但不幸的是我认为答案是“没有魔法”。
关于python - 使用 Biopython 的搜索词返回登录号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37059616/