2016-12-22 14 views
5

我想使用Entrez將發佈數據導入到數據庫中。搜索部分工作正常,但是當我嘗試解析:使用Entrez解析PubMed的發佈數據問題

from Bio import Entrez 

def create_publication(pmid): 

    handle = Entrez.efetch("pubmed", id=pmid, retmode="xml") 
    records = Entrez.parse(handle) 
    item_data = records.next() 
    handle.close() 

...我收到以下錯誤:

File "/venv/lib/python2.7/site-packages/Bio/Entrez/Parser.py", line 296, in parse raise ValueError("The XML file does not represent a list. Please use Entrez.read instead of Entrez.parse") ValueError: The XML file does not represent a list. Please use Entrez.read instead of Entrez.parse

該代碼使用,直到前幾天的工作。任何想法可能會在這裏出錯?

另外,查看源代碼(http://biopython.org/DIST/docs/api/Bio.Entrez-pysrc.html),並試圖按照上市爲例,給出了同樣的錯誤:

from Bio import Entrez 
Entrez.email = "[email protected]" 
handle = Entrez.efetch("pubmed", id="19304878,14630660", retmode="xml")  
records = Entrez.parse(handle) 
for record in records: 
    print(record['MedlineCitation']['Article']['ArticleTitle']) 
handle.close() 
+1

愚蠢的問題,但你嘗試過使用'Entrez.read()',然後解析結果? – MattDMo

+0

read()主要工作,但是這裏有一大堆其他代碼。所以當我嘗試時,我只是不斷得到不同的錯誤。所以要麼parse()有一個簡單的修復,要麼我需要重寫其餘的。 – apiljic

+0

這個過去一直工作到三天前,但最近似乎在PubMed上發生了一些變化,所以現在失敗了。 – apiljic

回答

2

的問題,因爲記錄在其他意見和GitHub Issue,由引起由NCBI Entrez公用事業開發人員進行故意更改。正如Jhird在這個問題記錄,您可以更改您的代碼如下:

from Bio import Entrez 
Entrez.email = "[email protected]" 
handle = Entrez.efetch("pubmed", id="19304878,14630660", retmode="xml") 

records = Entrez.read(handle)  # Difference here 
records = records['PubmedArticle'] # New line here 

for record in records: 
    print(record['MedlineCitation']['Article']['ArticleTitle']) 
handle.close()