使用Biopython搜索词返回登录号

使用Biopython搜索词返回登录号,python,biopython,Python,Biopython,我正在尝试使用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_phra

我正在尝试使用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转换为accession,但最好避免额外的步骤。我错过了什么魔法

先谢谢你

*特别是由于NCBI正在逐步淘汰GI编号

在NCBI的网站上查看,只有两个可用的
rettype
uilist,这是您当前获得的默认XML格式(它由
Entrez.read()
解析为dict)和
count
,它只显示了
计数
值(查看
结果的完整内容,它就在那里),我不清楚它的确切含义,因为它不代表
空闲列表
中的项目总数

无论如何,
Entrez.esearch()
将接受您喜欢的
rettype
retmode
的任何值,但它只返回
xml
json
模式中的
uilist
count
值-没有登录ID,什么都没有

将返回给您,具体取决于您查询的数据库。当然,缺点是您需要通过一个或多个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)
给予

7.1,“NZU HG941720.1”、“NZU HG941720.1”、“NZU HG941720.1”、“NZU HG941719.1”、“NZU HG941719.1”、“NZU HG941719.1”、“HF57577.2”、“HF57577.2”、“NZU HF57577.1”、“NZU HF57577.1”、“NUUUUUUUUUU0.1.1”、“NZZGGG947.1.1.1”、“NZZGGG94177.1.1”、“,”,”,”,”,”NZZUGGGGG941717.1.1.1.1.1”、“NZG941717.1.1.1、7.2.2.1”、“7.2.2.2.2.2.2,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”,”7.2.2.2.2.2,”,”,”1',M37402.1',AJ304858.2',FM206294.1',FM206293.1',AM886293.1']


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

我想一定有一个参数我遗漏了,但你的方法肯定是可以接受的。它工作得很好——非常感谢。@cer很高兴能提供帮助。我花了很多时间浏览文档和谷歌搜索,因为你可能会认为有一种方法可以通过
esearch
返回登录ID,但我认为找不到任何东西。我很高兴这对你有用。