forked from oneil512/INSIGHT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpubmed_api.py
35 lines (23 loc) · 968 Bytes
/
pubmed_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
pubmed_api = """
API Examples
Here is an example showing how to find a list of ids of pubmed articles about breast cancer, and then get the abstracts of those studies.
The retmax parameter controls how many abstracts you will get back.
The retstart parameter controls where to start looking for results in the result set. This is useful if you have searched this query before and would like to get further results
The sort parameter can take [relevance|pub_date]
===
import json
from Bio import Entrez
search_term = "breast cancer"
retmax=6
retstart=0
sort='relevance'
search_handle = Entrez.esearch(db="pubmed", term=search_term, retmax=retmax, retstart=retstart, sort=sort)
search_results = Entrez.read(search_handle)
search_handle.close()
pubmed_ids = search_results["IdList"]
fetch_handle = Entrez.efetch(db="pubmed", id=pubmed_ids, rettype="abstract", retmode="xml")
abstracts = fetch_handle.read()
fetch_handle.close()
ret = abstracts
===
""".strip()