Last active
August 3, 2019 12:58
-
-
Save renaud/7872024 to your computer and use it in GitHub Desktop.
python NCBI example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from Bio import Entrez | |
| Entrez.email = "[email protected]" | |
| handle = Entrez.esearch(db="pubmed", term="pyramidal cell") | |
| record = Entrez.read(handle) | |
| len(record) # this matches http://www.ncbi.nlm.nih.gov/pubmed/?term=pyramidal%20cell | |
| first = record["IdList"][0] | |
| # from http://stackoverflow.com/a/20149984/125617 | |
| def print_abstract(pmid): | |
| handle = Entrez.efetch(db='pubmed', id=pmid, retmode='text', rettype='abstract') | |
| print handle.read() | |
| print_abstract(first) | |
| def fetch_abstract(pmid): | |
| handle = Entrez.efetch(db='pubmed', id=pmid, retmode='xml') | |
| xml_data = Entrez.read(handle)[0] | |
| try: | |
| article = xml_data['MedlineCitation']['Article'] | |
| abstract = article['Abstract']['AbstractText'][0] | |
| return abstract | |
| except IndexError: | |
| return None | |
| fetch_abstract(first) ## some warnings, though... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment