aboutsummaryrefslogtreecommitdiff
path: root/ncbi/dbsnp/ncbiutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'ncbi/dbsnp/ncbiutils.py')
-rw-r--r--ncbi/dbsnp/ncbiutils.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/ncbi/dbsnp/ncbiutils.py b/ncbi/dbsnp/ncbiutils.py
index b3c199a..9bc1c94 100644
--- a/ncbi/dbsnp/ncbiutils.py
+++ b/ncbi/dbsnp/ncbiutils.py
@@ -2,10 +2,11 @@
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):
+"""
+Used to make an esearch and get the results back in json
+"""
+def esearch(**kwargs):
+ BASE_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?"
args = []
for key, value in kwargs.items():
args.append(key+"="+str(value))
@@ -15,4 +16,21 @@ def db_query(**kwargs):
results = resp.json()
return(results)
else:
+ print("You've encountered an error and we can't return your results")
+
+"""
+Used for an efetch, which is primarily to query specific IDs in dbsnp or pubmed
+Doesn't return json, but must return XML, apparently.
+"""
+def efetch(**kwargs):
+ BASE_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?"
+ args = []
+ for key, value in kwargs.items():
+ args.append(key+"="+str(value))
+ qstring = "&".join(args)
+ resp = requests.get(BASE_URL + qstring)
+ if resp.status_code == 200:
+ results = resp.text
+ return(results)
+ else:
print("You've encountered an error and we can't return your results") \ No newline at end of file