From 163c84b48a70b5a351f48a49339dbdb28da96469 Mon Sep 17 00:00:00 2001 From: lltommy Date: Sun, 26 Apr 2020 22:05:53 +0200 Subject: Pushing some new functions, rename some old ones --- bh20simplewebuploader/main.py | 86 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 8 deletions(-) diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index 75adc74..6ca9a78 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -376,8 +376,8 @@ def getDetailsForSeq(): 'value': x['value']['value']} for x in result]) -@app.route('/api/getSEQbytech', methods=['GET']) -def getSEQbytech(): +@app.route('/api/getSEQCountbytech', methods=['GET']) +def getSEQCountbytech(): query="""SELECT ?tech ?tech_label (count(?fasta) as ?fastaCount) WHERE {?fasta ?x [ ?tech] BIND (concat(?tech,"_label") as ?tech_label)} @@ -390,11 +390,22 @@ def getSEQbytech(): 'tech': x['tech']['value'], 'Label': x['tech_label']['value']} for x in result]) +## Is this one really necessary or should we just use getSEQCountbytech instead? +@app.route('/api/getAvailableTech', methods=['GET']) +def getAvailableTech(): + query="""SELECT distinct ?tech ?tech_label WHERE + {?fasta ?x [ ?tech] + BIND (concat(?tech,"_label") as ?tech_label) + } """ + payload = {'query': query, 'format': 'json'} + r = requests.get(baseURL, params=payload) + result = r.json()['results']['bindings'] + return str(result) ## List all Sequences/submissions by a given tech, as example e.g. http://purl.obolibrary.org/obo/OBI_0000759 ## Has to be encoded again so should be --> http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FOBI_0000759 -@app.route('/api/getSEQbySelectedtech', methods=['GET']) -def getSEQbySelectedtech(): +@app.route('/api/getSEQbytech', methods=['GET']) +def getSEQbytech(): query="""SELECT ?fasta WHERE {?fasta ?x [ ] } """ @@ -406,8 +417,21 @@ def getSEQbySelectedtech(): return str(result) +## Example location, encoded http%3A%2F%2Fwww.wikidata.org%2Fentity%2FQ1223 @app.route('/api/getSEQbyLocation', methods=['GET']) def getSEQbyLocation(): + query="""SELECT ?fasta WHERE {?fasta ?x[ ]}""" + location=request.args.get('location') + query=query.replace("placeholder", location) + print(query) + payload = {'query': query, 'format': 'json'} + r = requests.get(baseURL, params=payload) + result = r.json()['results']['bindings'] + return str(result) + + +@app.route('/api/getSEQCountbyLocation', methods=['GET']) +def getSEQCountbyLocation(): query="""SELECT ?geoLocation ?geoLocation_label (count(?fasta) as ?fastaCount) WHERE {?fasta ?x [ ?geoLocation] BIND (concat(?geoLocation,"_label") as ?geoLocation_label)} @@ -421,8 +445,8 @@ def getSEQbyLocation(): 'GeoLocation Label': x['geoLocation_label']['value']} for x in result]) -@app.route('/api/getSEQbySpecimenSource', methods=['GET']) -def getSEQbySpecimenSource(): +@app.route('/api/getSEQCountbySpecimenSource', methods=['GET']) +def getSEQCountbySpecimenSource(): query="""SELECT ?specimen_source ?specimen_source_label (count(?fasta) as ?fastaCount) WHERE {?fasta ?x [ ?specimen_source] BIND (concat(?specimen_source,"_label") as ?specimen_source_label)} @@ -436,9 +460,23 @@ def getSEQbySpecimenSource(): 'Specimen Source': x['specimen_source']['value'], 'Label': x['specimen_source_label']['value']} for x in result]) +# Example specimen http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FNCIT_C155831 +@app.route('/api/getSEQbySpecimenSource', methods=['GET']) +def getSEQBySpecimenSource(): + query="""SELECT ?fasta ?specimen_source ?specimen_source_label WHERE + {?fasta ?x [ ] + BIND (concat(?specimen_source,"_label") as ?specimen_source_label)} + """ + specimen=request.args.get('specimen') + query = query.replace("placeholder", specimen) + 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(): +@app.route('/api/getSEQCountbyHostHealthStatus', methods=['GET']) +def getSEQCountbyHostHealthStatus(): query="""SELECT ?health_status ?health_status_label (count(?fasta) as ?fastaCount) WHERE {?fasta ?x [ ?health_status] BIND (concat(?health_status,"_label") as ?health_status_label)} @@ -449,3 +487,35 @@ def getSEQbyHostHealthStatus(): r = requests.get(baseURL, params=payload) result = r.json()['results']['bindings'] return str(result) + +@app.route('/api/getSEQbyLocationAndTech', methods=['GET']) +def getSEQbyLocationAndTech(): + query="""SELECT ?fasta WHERE { ?fasta ?x [ + ; ]}""" + location=request.args.get('location') + tech=request.args.get('tech') + query=query.replace("placeholderLoc", location) + query = query.replace("placeholderTech", tech) + print(query) + payload = {'query': query, 'format': 'json'} + r = requests.get(baseURL, params=payload) + result = r.json()['results']['bindings'] + return str(result) + + +# Example Location http%3A%2F%2Fwww.wikidata.org%2Fentity%2FQ1223 +# Example specimen http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FNCIT_C155831 +@app.route('/api/getSEQbyLocationAndSpecimenSource', methods=['GET']) +def getSEQbyLocationAndSpecimenSource(): + query="""SELECT ?fasta WHERE { ?fasta ?x [ + ; ]} + """ + location = request.args.get('location') + specimen = request.args.get('specimen') + query = query.replace("placeholderLoc", location) + query = query.replace("placeholderSpecimen", specimen) + print(query) + 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 -- cgit v1.2.3