2016-11-21 35 views
0

我目前使用BioPython從PMID查詢PubMed記錄。然後我存儲在一個變量被稱爲抽象用的數據類型所期望的信息:將Bio.Entrez類轉換爲字符串

class 'Bio.Entrez.Parser.StructureElement'> 

例如,如果我打印我收到此:

{u'AbstractText': ['Hypercholesterolemia and hypertension are frequently associated with elevated sympathetic activity. Both are independent cardiovascular ris....']} 

我希望寫的平方之間的文本括號內的字符串。我如何快速有效地做到這一點?

回答

0

我不知道您是如何從PubMed獲取您的數據,但是如果您需要查詢PubMed並獲取摘要,則可以使用以下代碼片段。

from Bio import Medline 
from Bio import Entrez 
Entrez.email = '[email protected]' 

#a list of pubmed IDs 
idlist = ['10024335'] 

#query PubMed 
handle = Entrez.efetch(db="pubmed", id=idlist, rettype="medline", retmode="text") 
records = Medline.parse(handle) 

#print the abstract of all records 
for r in records: 
    print(r['AB']) 

輸出

'高膽固醇血癥和高血壓經常與

相關聯...

在高膽固醇血癥高血壓對象結構損壞。'

0

你應該認識到這是一個Python字典:

{u'AbstractText': ['Hypercholesterolemia and hypertension are frequently associated with elevated sympathetic activity. Both are independent cardiovascular ris....']}

這裏'AbstractTest'是一本字典鍵,['Hypercholesterolemia and hypertension are frequently associated with elevated sympathetic activity. Both are independent cardiovascular ris....']及其關聯值。

注意['Hypercholesterolemia and hypertension are frequently associated with elevated sympathetic activity. Both are independent cardiovascular ris....']是一個Python列表,其中包含一個字符串(顯示爲用點截斷)。

所以像my_dict['AbstractTest'][0]這樣的東西會給你從這個列表中的第一個條目。