ser*_*ain 1 python biopython pubmed
快速问题——第一次使用 biopython,我只是想根据教程快速搭建一些真正的东西。
我似乎无法Entrez.efetch()返回给定文章的网格项,唯一的方法似乎是我正在做的,即:
handle = Entrez.efetch(db="pubmed", id=pmids, rettype="medline", retmode="xml")
records = Entrez.read(handle)
Run Code Online (Sandbox Code Playgroud)
其中 pmids 是发布的ID列表
这将返回以下内容:http : //pastie.org/5459700
我试过根据http://www.ncbi.nlm.nih.gov/books/NBK25499/调整 rettype 和 retmode 参数,但没有成功。有什么明显的我失踪了吗?
这对我有用:
from Bio import Entrez # install with 'pip install biopython'
from Bio.Entrez import efetch, read
Entrez.email = "your@email.com" # register your email
def get_mesh(pmid):
# call PubMed API
handle = efetch(db='pubmed', id=str(pmid), retmode='xml')
xml_data = read(handle)[0]
# skip articles without MeSH terms
if u'MeshHeadingList' in xml_data['MedlineCitation']:
for mesh in xml_data['MedlineCitation'][u'MeshHeadingList']:
# grab the qualifier major/minor flag, if any
major = 'N'
qualifiers = mesh[u'QualifierName']
if len(qualifiers) > 0:
major = str(qualifiers[0].attributes.items()[0][1])
# grab descriptor name
descr = mesh[u'DescriptorName']
name = descr.title()
yield(name, major)
# example output
for name, major in get_mesh(128):
print '{}, {}'.format(name, major)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1468 次 |
| 最近记录: |