根據(jù)PMID批量獲取NCBI摘要頁(yè)內(nèi)容

根據(jù)PMID批量獲取NCBI摘要頁(yè)內(nèi)容

'根據(jù)PMID號(hào),獲取Pubmed摘要頁(yè)面的所有內(nèi)容(題目和摘要等。)NBK開(kāi)頭的PMID在程序自動(dòng)搜索時(shí)會(huì)自動(dòng)將NBK去掉,所以不適用于此代碼生成。'

__author__ = 'shixq'
# source:http://www.itdecent.cn/p/b36adf266c3d
from Bio import Entrez

Entrez.email = "2576755886@qq.com" # 輸入自己的郵箱,這里使用一個(gè)我隨便申請(qǐng)的QQ郵箱
# with open('PMID.txt') as pmid_file
pmid_file = open('PMID.txt')# 輸入文件不要有空行,篩掉NBK開(kāi)頭的文獻(xiàn)。
output = open('PMID_abstract.txt', 'w', encoding='utf-8')
id_list = []
abstracts = []
for element in pmid_file:
    id_list.append(element.strip())# 去掉'/n'
pmid_file.close()
count = 0
for pid in id_list:
    handle = Entrez.efetch(db="pubmed", id=pid, rettype="abstract", retmode="text")# Entrez 里的efetch模塊獲取摘要頁(yè)面的text內(nèi)容。
    re =[line.strip() for line in handle.readlines()] #將所有的換行輸出排列在一行上
    # print(re)
    # record = [handle.read().strip()]
    # all_ab.append(record)
    # print(record)
    # all_ab.append(record)
    # for sab in record:
    #     print(pid + '\t' + sab + '\n')
    output.write(pid + '\t' + ''.join(re) + '\n')#將一個(gè)list內(nèi)的所有元素不換行輸出
    output.close()
    count += 1
    print('complete', '%.1f%%'%((count/len(id_list))*100))# 在屏幕上打印完成的進(jìn)度百分比
    # try:
    # ab = record['PubmedArticle']
    # print(ab)
        # for a in ab:
        #     print(a)
    # except KeyError:
    #     ab = ['none abstract']
    # except IndexError:
    #     ab = ['AAA:This PMID may be a book & Documents, no abstract']    
    # for abstract in ab:
    #     if pid == pid:
    #         abstract = abstract +
    #     count += 1
    #     print('complete', '%.1f%%'%((count/len(id_list))*100))
    # output.write(pid + '\t' + sab + '\n')ssss
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容