From 72f9b2c96b2be87f028737957c3ab22be1ccea69 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Sun, 26 Apr 2020 05:25:35 +0300 Subject: Jsonify response and pick the values --- bh20simplewebuploader/main.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'bh20simplewebuploader/main.py') diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index e88eb4c..53a4cda 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -8,7 +8,7 @@ import re import string import yaml import pkg_resources -from flask import Flask, request, redirect, send_file, send_from_directory, render_template +from flask import Flask, request, redirect, send_file, send_from_directory, render_template, jsonify import os.path import requests @@ -358,7 +358,8 @@ def getAllaccessions(): payload = {'query': query, 'format': 'json'} r = requests.get(baseURL, params=payload) result = r.json()['results']['bindings'] - return str(result) + return jsonify([{'uri': x['fasta']['value'], + 'value': x['value']['value']} for x in result]) # parameter must be encoded e.g. http://arvados.org/keep:6e6276698ed8b0e6cd21f523e4f91179+123/sequence.fasta must become @@ -368,11 +369,12 @@ def getDetailsForSeq(): seq_id = request.args.get('seq') query="""SELECT DISTINCT ?key ?value WHERE { ?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) + return jsonify([{'uri': x['key']['value'], + 'value': x['value']['value']} for x in result]) + @app.route('/api/getSEQbytech', methods=['GET']) def getSEQbytech(): @@ -384,7 +386,9 @@ def getSEQbytech(): payload = {'query': query, 'format': 'json'} r = requests.get(baseURL, params=payload) result = r.json()['results']['bindings'] - return str(result) + return jsonify([{'Fasta Count': x['fastaCount']['value'], + 'Specimen Source': x['specimen_source']['value'], + 'Label': x['specimen_source_label']['value']} for x in result]) @app.route('/api/getSEQbyLocation', methods=['GET']) def getSEQbyLocation(): @@ -396,7 +400,10 @@ def getSEQbyLocation(): payload = {'query': query, 'format': 'json'} r = requests.get(baseURL, params=payload) result = r.json()['results']['bindings'] - return str(result) + return jsonify([{'Fasta Count': x['fastaCount']['value'], + 'GeoLocation': x['geoLocation']['value'], + 'GeoLocation Label': x['geoLocation_label']['value']} for x in result]) + @app.route('/api/getSEQbySpecimenSource', methods=['GET']) def getSEQbySpecimenSource(): @@ -409,7 +416,9 @@ def getSEQbySpecimenSource(): payload = {'query': query, 'format': 'json'} r = requests.get(baseURL, params=payload) result = r.json()['results']['bindings'] - return str(result) + return jsonify([{'Fasta Count': x['fastaCount']['value'], + 'Specimen Source': x['specimen_source']['value'], + 'Label': x['specimen_source_label']['value']} for x in result]) #No data for this atm @app.route('/api/getSEQbyHostHealthStatus', methods=['GET']) @@ -423,4 +432,4 @@ def getSEQbyHostHealthStatus(): 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 + return str(result) -- cgit v1.2.3 From fd29a73ae0ea231e91377776dd5b8fa18b5ba5e2 Mon Sep 17 00:00:00 2001 From: lltommy Date: Sun, 26 Apr 2020 12:22:55 +0200 Subject: Adding a function, correcting some variable names --- bh20simplewebuploader/main.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'bh20simplewebuploader/main.py') diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index 53a4cda..75adc74 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -378,17 +378,33 @@ def getDetailsForSeq(): @app.route('/api/getSEQbytech', methods=['GET']) def getSEQbytech(): - 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)} - GROUP BY ?specimen_source ?specimen_source_label ORDER BY DESC (?fastaCount) + query="""SELECT ?tech ?tech_label (count(?fasta) as ?fastaCount) WHERE + {?fasta ?x [ ?tech] + BIND (concat(?tech,"_label") as ?tech_label)} + GROUP BY ?tech ?tech_label ORDER BY DESC (?fastaCount) """ payload = {'query': query, 'format': 'json'} r = requests.get(baseURL, params=payload) result = r.json()['results']['bindings'] return jsonify([{'Fasta Count': x['fastaCount']['value'], - 'Specimen Source': x['specimen_source']['value'], - 'Label': x['specimen_source_label']['value']} for x in result]) + 'tech': x['tech']['value'], + 'Label': x['tech_label']['value']} for x in 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(): + query="""SELECT ?fasta WHERE + {?fasta ?x [ ] } + """ + tech = request.args.get('tech') + query=query.replace("placeholder", tech) + 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(): -- cgit v1.2.3 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(-) (limited to 'bh20simplewebuploader/main.py') 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 From c13c4d1a157d75d620f368775758c1e16c45c448 Mon Sep 17 00:00:00 2001 From: lltommy Date: Wed, 29 Apr 2020 16:48:19 +0200 Subject: fixing JS due to name changes so the demo works again --- bh20simplewebuploader/main.py | 8 ++++++++ bh20simplewebuploader/static/main.js | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'bh20simplewebuploader/main.py') diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index 6ca9a78..126b8dd 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -197,6 +197,14 @@ def generate_form(schema, options): record['type'] = 'number' # Choose a reasonable precision for the control record['step'] = '0.0001' + + ### This is to fix the homepage for the moment ## needs more love though + # implementation of the [] stuff instead of just text fields + ## ToDo - implement lists + elif field_type == 'string[]': + record['type'] = 'text' + elif field_type == 'float[]': + record['type'] = 'text' else: raise NotImplementedError('Unimplemented field type {} in {} in metadata schema'.format(field_type, type_name)) yield record diff --git a/bh20simplewebuploader/static/main.js b/bh20simplewebuploader/static/main.js index 0f79fdf..96199a0 100644 --- a/bh20simplewebuploader/static/main.js +++ b/bh20simplewebuploader/static/main.js @@ -19,15 +19,15 @@ let search = () => { } let fetchSEQBySpecimen = () => { - fetchAPI("/api/getSEQbySpecimenSource"); + fetchAPI("/api/getSEQCountbySpecimenSource"); } let fetchSEQByLocation = () => { - fetchAPI("/api/getSEQbyLocation"); + fetchAPI("/api/getSEQCountbyLocation"); } let fetchSEQByTech = () => { - fetchAPI("/api/getSEQbytech"); + fetchAPI("/api/getSEQCountbytech"); } let fetchAllaccessions = () => { -- cgit v1.2.3