【发布时间】:2018-05-02 15:05:39
【问题描述】:
我目前正在从事一个课程项目,该项目需要我使用 biopython 从 NCBI 网站提取数据并将其写入 CSV 文件,然后我在 R 中进行分析。我得到了我需要的所有数据,但我没有完全确定如何将其写入 CSV 文件,因为我们从未在课堂上讨论过它。到目前为止,这是我的代码:
from Bio import Entrez, Medline
Entrez.email = "email.here"
handle = Entrez.esearch(db="pubmed", # database to search
term="Chan CS[Author] AND 2000:2017[Date - Publication]", # search term
retmax=200 # Maximum number of results to return
)
record = Entrez.read(handle)
handle.close()
pmid_list = record["IdList"]
print(pmid_list)
紧随其后
from Bio import Medline
handle = Entrez.efetch(db="pubmed", id=pmid_list, rettype="medline", retmode="text")
records = Medline.parse(handle)
journal_dict = []
datep_dict = []
place_dict = []
for record in records:
# retrieve journal titles
title = record['JT']
journal_dict.append(title)
#retrieve date published
date = record['DP']
datep_dict.append(date)
#retrieve place published
place = record['PL']
place_dict.append(place)
# Close the efetch handle
handle.close()
for title in journal_dict:
print(title)
for date in datep_dict:
print(date)
for place in place_dict:
print(place)
最后,我坚持的部分
import csv
我正在尝试让 csv 文件看起来像下面这样
[ID, Journal Title, Publication Date, Place of Publication]
[123, Title1, Date1, Place1]
[124, Title2, Date2, Place2]
任何帮助将不胜感激!
【问题讨论】:
标签: python csv bioinformatics biopython