gpt4 book ai didi

biopython - 有什么方法可以获取给定的 pubmed id 列表的摘要吗?

转载 作者:行者123 更新时间:2023-12-03 07:45:35 24 4
gpt4 key购买 nike

我有 pmids 列表我想在单个网址点击中获取他们两个的摘要

    pmids=[17284678,9997]
abstract_dict={}
url = https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?
db=pubmed&id=**17284678,9997**&retmode=text&rettype=xml

我的要求是采用这种格式

   abstract_dict={"pmid1":"abstract1","pmid2":"abstract2"}

我可以通过尝试每个 id 并更新字典来获得上述格式,但为了优化时间,我想将所有 id 提供给 url 并进行处理,并仅获取摘要部分。

最佳答案

使用 BioPython,您可以将 Pubmed ID 的连接列表提供给 Entrez.efetch,这将执行单个 URL 查找:

from Bio import Entrez

Entrez.email = 'your_email@provider.com'

pmids = [17284678,9997]
handle = Entrez.efetch(db="pubmed", id=','.join(map(str, pmids)),
rettype="xml", retmode="text")
records = Entrez.read(handle)
abstracts = [pubmed_article['MedlineCitation']['Article']['Abstract']['AbstractText'][0]
for pubmed_article in records['PubmedArticle']]


abstract_dict = dict(zip(pmids, abstracts))

这给出了结果:

{9997: 'Electron paramagnetic resonance and magnetic susceptibility studies of Chromatium flavocytochrome C552 and its diheme flavin-free subunit at temperatures below 45 degrees K are reported. The results show that in the intact protein and the subunit the two low-spin (S = 1/2) heme irons are distinguishable, giving rise to separate EPR signals. In the intact protein only, one of the heme irons exists in two different low spin environments in the pH range 5.5 to 10.5, while the other remains in a constant environment. Factors influencing the variable heme iron environment also influence flavin reactivity, indicating the existence of a mechanism for heme-flavin interaction.',
17284678: 'Eimeria tenella is an intracellular protozoan parasite that infects the intestinal tracts of domestic fowl and causes coccidiosis, a serious and sometimes lethal enteritis. Eimeria falls in the same phylum (Apicomplexa) as several human and animal parasites such as Cryptosporidium, Toxoplasma, and the malaria parasite, Plasmodium. Here we report the sequencing and analysis of the first chromosome of E. tenella, a chromosome believed to carry loci associated with drug resistance and known to differ between virulent and attenuated strains of the parasite. The chromosome--which appears to be representative of the genome--is gene-dense and rich in simple-sequence repeats, many of which appear to give rise to repetitive amino acid tracts in the predicted proteins. Most striking is the segmentation of the chromosome into repeat-rich regions peppered with transposon-like elements and telomere-like repeats, alternating with repeat-free regions. Predicted genes differ in character between the two types of segment, and the repeat-rich regions appear to be associated with strain-to-strain variation.'}

编辑:

如果 pmids 没有相应的摘要,请注意您建议的修复:

abstracts = [pubmed_article['MedlineCitation']['Article']['Abstract'] ['AbstractText'][0] 
for pubmed_article in records['PubmedArticle'] if 'Abstract' in
pubmed_article['MedlineCitation']['Article'].keys()]

假设您有 Pubmed ID 列表 pmids = [1, 2, 3],但 pmid 2 没有摘要,因此 abstracts = ['abstract of 1' , '摘要 3']

这将在最后一步中导致问题,我将两个列表压缩在一起以创建字典:

>>> abstract_dict = dict(zip(pmids, abstracts))
>>> print(abstract_dict)
{1: 'abstract of 1',
2: 'abstract of 3'}

请注意,摘要现在与相应的 Pubmed ID 不同步,因为您没有过滤掉没有摘要的 pmids,并且 zip 会截断为最短的列表

相反,请执行以下操作:

abstract_dict = {}
without_abstract = []

for pubmed_article in records['PubmedArticle']:
pmid = int(str(pubmed_article['MedlineCitation']['PMID']))
article = pubmed_article['MedlineCitation']['Article']
if 'Abstract' in article:
abstract = article['Abstract']['AbstractText'][0]
abstract_dict[pmid] = abstract
else:
without_abstract.append(pmid)

print(abstract_dict)
print(without_abstract)

关于biopython - 有什么方法可以获取给定的 pubmed id 列表的摘要吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47559098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com