aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan DeMasi <jonathan.demasi@colorado.edu>2019-06-18 12:09:24 -0600
committerJonathan DeMasi <jonathan.demasi@colorado.edu>2019-06-18 12:09:24 -0600
commit6f59cd431b1fba5fe06a6687c78f991878562d61 (patch)
tree0522c5c24405f4b2c714bd9a6dc4339b368cc442
parent3a6fe0de89aada99995b43f561ccb7bd53ef927d (diff)
downloadsnippets-6f59cd431b1fba5fe06a6687c78f991878562d61.tar
snippets-6f59cd431b1fba5fe06a6687c78f991878562d61.tar.gz
snippets-6f59cd431b1fba5fe06a6687c78f991878562d61.tar.bz2
snippets-6f59cd431b1fba5fe06a6687c78f991878562d61.tar.lz
snippets-6f59cd431b1fba5fe06a6687c78f991878562d61.tar.xz
snippets-6f59cd431b1fba5fe06a6687c78f991878562d61.tar.zst
snippets-6f59cd431b1fba5fe06a6687c78f991878562d61.zip
added helper functions
-rwxr-xr-xncbi/dbsnp/ncbiutils.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/ncbi/dbsnp/ncbiutils.py b/ncbi/dbsnp/ncbiutils.py
new file mode 100755
index 0000000..8fb998b
--- /dev/null
+++ b/ncbi/dbsnp/ncbiutils.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+import requests
+
+BASE_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?"
+
+# Example https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=snp&term=snp_pubmed_cited[sb]&retmax=200000&retstart=1000&retmode=json
+def db_query(**kwargs):
+ args = []
+ for key, value in kwargs.items():
+ args.append(key+"="+str(value))
+ qstring = "&".join(args)
+ print(qstring)
+ resp = requests.get(BASE_URL + qstring)
+ if resp.status_code == 200:
+ results = resp.json()
+ return(results)
+ else:
+ print("You've encountered an error and we can't return your results")
+
+def main():
+ results = db_query(db="snp", term="snp_pubmed_cited[sb]", retmax=200000, retstart=1000, retmode="json")
+ print(results)
+ return()
+
+if __name__ == '__main__':
+ main() \ No newline at end of file