Skip to content

Instantly share code, notes, and snippets.

@ahwagner
Created September 26, 2017 19:09
Show Gist options
  • Save ahwagner/037c304f12e46271ea5833a3628bbae7 to your computer and use it in GitHub Desktop.
Save ahwagner/037c304f12e46271ea5833a3628bbae7 to your computer and use it in GitHub Desktop.
Jupyter Notebook for extracting all PMIDs in CIViC
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import requests"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"url = \"https://civic.genome.wustl.edu/api/sources\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"pmids = set()\n",
"next_page = url\n",
"while next_page:\n",
" resp = requests.get(next_page)\n",
" resp.raise_for_status()\n",
" json = resp.json()\n",
" for record in json['records']:\n",
" pmid = record.get('pubmed_id', None)\n",
" if pmid is None:\n",
" continue\n",
" pmids.add(pmid)\n",
" next_page = json['_meta']['links']['next']"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1752"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(pmids)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"with open('pmids.txt', 'w') as out:\n",
" for pmid in pmids:\n",
" print(pmid, file=out)"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [py36]",
"language": "python",
"name": "Python [py36]"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@ahwagner
Copy link
Author

ahwagner commented Apr 5, 2018

Yup, doesn't work anymore. Go look at API docs and update url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment