aboutsummaryrefslogtreecommitdiff
path: root/bh20simplewebuploader
diff options
context:
space:
mode:
authorlltommy2020-04-23 22:50:58 +0200
committerlltommy2020-04-23 22:50:58 +0200
commita1a0e99acaccc95fafeffed489642af28d744d76 (patch)
treebee0bfe02490af4ce9bdf74c0c9a2a85618b668f /bh20simplewebuploader
parent0a883bef4f687843293ca71a7f8d8d3c13f681c9 (diff)
downloadbh20-seq-resource-a1a0e99acaccc95fafeffed489642af28d744d76.tar.gz
bh20-seq-resource-a1a0e99acaccc95fafeffed489642af28d744d76.tar.lz
bh20-seq-resource-a1a0e99acaccc95fafeffed489642af28d744d76.zip
Adding API endpoints to drive the homepage. Dirty but functional
Diffstat (limited to 'bh20simplewebuploader')
-rw-r--r--bh20simplewebuploader/main.py83
1 files changed, 82 insertions, 1 deletions
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index ceab8a6..e88eb4c 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -9,8 +9,9 @@ import string
import yaml
import pkg_resources
from flask import Flask, request, redirect, send_file, send_from_directory, render_template
-
import os.path
+import requests
+
if not os.path.isfile('bh20sequploader/mainx.py'):
print("WARNING: run FLASK from the root of the source repository!", file=sys.stderr)
@@ -343,3 +344,83 @@ def receive_files():
return render_template('success.html', log=result.stdout.decode('utf-8', errors='replace'))
finally:
shutil.rmtree(dest_dir)
+
+
+## Dynamic API functions starting here
+## This is quick and dirty for now, just to get something out and demonstrate the queries
+## Feel free to rename the functions/endpoints, feel free to process result so we get nicer JSON
+## but most likley you don't want to touch the queries, Cheers.
+baseURL='http://sparql.genenetwork.org/sparql/'
+
+@app.route('/api/getAllaccessions', methods=['GET'])
+def getAllaccessions():
+ query="""SELECT DISTINCT ?fasta ?value WHERE {?fasta ?x[ <http://edamontology.org/data_2091> ?value ]}"""
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
+ return str(result)
+
+
+# parameter must be encoded e.g. http://arvados.org/keep:6e6276698ed8b0e6cd21f523e4f91179+123/sequence.fasta must become
+# http%3A%2F%2Farvados.org%2Fkeep%3A6e6276698ed8b0e6cd21f523e4f91179%2B123%2Fsequence.fasta
+@app.route('/api/getDetailsForSeq', methods=['GET'])
+def getDetailsForSeq():
+ seq_id = request.args.get('seq')
+ query="""SELECT DISTINCT ?key ?value WHERE {<placeholder> ?x [?key ?value]}"""
+ query=query.replace("placeholder", seq_id)
+ print(query)
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
+ return str(result)
+
+@app.route('/api/getSEQbytech', methods=['GET'])
+def getSEQbytech():
+ query="""SELECT ?specimen_source ?specimen_source_label (count(?fasta) as ?fastaCount) WHERE
+ {?fasta ?x [<http://purl.obolibrary.org/obo/OBI_0600047> ?specimen_source]
+ BIND (concat(?specimen_source,"_label") as ?specimen_source_label)}
+ GROUP BY ?specimen_source ?specimen_source_label ORDER BY DESC (?fastaCount)
+ """
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
+ return str(result)
+
+@app.route('/api/getSEQbyLocation', methods=['GET'])
+def getSEQbyLocation():
+ query="""SELECT ?geoLocation ?geoLocation_label (count(?fasta) as ?fastaCount) WHERE
+ {?fasta ?x [<http://purl.obolibrary.org/obo/GAZ_00000448> ?geoLocation]
+ BIND (concat(?geoLocation,"_label") as ?geoLocation_label)}
+ GROUP BY ?geoLocation ?geoLocation_label ORDER BY DESC (?fastaCount)
+ """
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
+ return str(result)
+
+@app.route('/api/getSEQbySpecimenSource', methods=['GET'])
+def getSEQbySpecimenSource():
+ query="""SELECT ?specimen_source ?specimen_source_label (count(?fasta) as ?fastaCount) WHERE
+ {?fasta ?x [<http://purl.obolibrary.org/obo/OBI_0001479> ?specimen_source]
+ BIND (concat(?specimen_source,"_label") as ?specimen_source_label)}
+ GROUP BY ?specimen_source ?specimen_source_label
+ ORDER BY DESC (?fastaCount)
+ """
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
+ return str(result)
+
+#No data for this atm
+@app.route('/api/getSEQbyHostHealthStatus', methods=['GET'])
+def getSEQbyHostHealthStatus():
+ query="""SELECT ?health_status ?health_status_label (count(?fasta) as ?fastaCount) WHERE
+ {?fasta ?x [<http://purl.obolibrary.org/obo/NCIT_C25688> ?health_status]
+ BIND (concat(?health_status,"_label") as ?health_status_label)}
+ GROUP BY ?health_status ?health_status_label
+ ORDER BY DESC (?fastaCount)
+ """
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
+ return str(result) \ No newline at end of file