From ee8424f4c8a06ab37ada1c17039e5a36289587b8 Mon Sep 17 00:00:00 2001 From: lltommy Date: Sat, 14 Nov 2020 10:47:09 +0100 Subject: Adding an additional example to the SPARQL playground --- bh20simplewebuploader/main.py | 43 +++++++++++++++++---- bh20simplewebuploader/static/main.js | 62 ++++++++++++++++++------------- bh20simplewebuploader/templates/demo.html | 16 ++++---- 3 files changed, 80 insertions(+), 41 deletions(-) diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index 27dcd4b..87ef212 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -1066,7 +1066,7 @@ def getSEQbyLocationAndSpecimenSource(): return str(result) -################## SPARQL PLAYGORUND API function ################ +########################## SPARQL PLAYGORUND API function #################### @app.route('/api/demoGetSEQCountbySpecimenSource', methods=['GET']) def demoGetSEQCountbySpecimenSource(): @@ -1193,7 +1193,7 @@ PREFIX rdfs: """ @app.route('/api/demoGetSEQCountbytech', methods=['GET']) -def dempGetSEQCountbytech(): +def demoGetSEQCountbytech(): prefix="""PREFIX obo: PREFIX rdfs: """ @@ -1221,7 +1221,7 @@ def demoGetSequencePerDate(): FILTER ( xsd:date(?date) < xsd:date("2020-03-01") ) } ORDER BY ?date""" - description = "Show all sequences with a submission date before 2020-03-01! To accomplish this a FILTER expression is used. Since date is a string, we cast xsd:date(...)" + description = "Show all sequences with a collection date before 2020-03-01! To accomplish this a FILTER expression is used. Since date is a string, we cast xsd:date(...)" payload = {'query': prefix + query, 'format': 'json'} r = requests.get(sparqlURL, params=payload) result = r.json()['results']['bindings'] @@ -1229,8 +1229,8 @@ def demoGetSequencePerDate(): [{'seq': x['seq']['value'], 'date': x['date']['value']} for x in result]) -@app.route('/api/demoLocationGps', methods=['GET']) -def demoLocationGps(): +@app.route('/api/demoGetLocationGps', methods=['GET']) +def demoGetLocationGps(): prefix="""PREFIX obo: PREFIX wiki: """ @@ -1247,8 +1247,8 @@ PREFIX wiki: """ [{'location': x['location']['value'], 'GPS': x['GPS']['value']} for x in result]) -@app.route('/api/getNYsamples', methods=['GET']) -def getNYsamples(): +@app.route('/api/demoGetNYsamples', methods=['GET']) +def demoGetNYsamples(): prefix="""PREFIX obo: PREFIX wikiE: """ @@ -1270,4 +1270,31 @@ PREFIX wikiE: """ 'key_label': x['key_label']['value'], 'key': x['key']['value'], 'value_label': x['value_label']['value'], - 'value': x['value']['value']} for x in result]) \ No newline at end of file + 'value': x['value']['value']} for x in result]) + + +@app.route('/api/demoGetSouthAmericaSeq', methods=['GET']) +def demoGetSouthAmericaSeq(): + prefix = """PREFIX obo: +PREFIX wiki: +PREFIX rdfs: +""" + + query = """SELECT DISTINCT ?country_label ?seq WHERE + { + ?seq ?y [ obo:GAZ_00000448 ?location] . + ?location wiki:P17 ?country . + ?country rdfs:label ?country_label . + ?country wiki:P30 . + } +ORDER BY ?country_label +""" + + description = "Show all sequences that are on the continent (P30) South America (Q18)! List the sequence identifiers and the country they belong too." + payload = {'query': prefix + query, 'format': 'json'} + r = requests.get(sparqlURL, params=payload) + result = r.json()['results']['bindings'] + return jsonify([{'description': description}, {'prefix': prefix}, {'query': query}], + [{'seq': x['seq']['value'], + 'country_label': x['country_label']['value']} for x in result]) + diff --git a/bh20simplewebuploader/static/main.js b/bh20simplewebuploader/static/main.js index 0e642c1..da196cf 100644 --- a/bh20simplewebuploader/static/main.js +++ b/bh20simplewebuploader/static/main.js @@ -164,29 +164,52 @@ let fetchCountDB = () => { fetchAPI("/api/getCountDB"); } +////// old API functions, some might no be used // +let fetchSEQCountByTech = () => { + fetchHTMLTable("/api/getSEQCountbytech"); +} + +let fetchAllaccessions = () => { + fetchHTMLTable("/api/getAllaccessions"); +}; + +let fetchMap = () => { + fetchAPI("/api/getCountByGPS"); + updateMapMarkers(); +}; + +let fetchSEQByLocation = () => { + console.log("Missing - set parameter for request, retrieve data") +}; + +let fetchSEQCountbyContinent = () => { + fetchHTMLTable("/api/getSEQCountbyContinent"); +} +/////////////////////////////////// End "old" function + -//****** SPARQL playground functions // keep old functionality as comments for now, might be transfered elsewhere -let fetchSEQCountBySpecimen = (toHTML) => { +////****** SPARQL playground functions ***************//// +let demoFetchSEQCountBySpecimen = (toHTML) => { //fetchHTMLTable("/api/getSEQCountbySpecimenSource"); demofetchHTMLTable("/api/demoGetSEQCountbySpecimenSource") } -let fetchSEQCountByLocation = () => { +let demoFetchSEQCountByLocation = () => { //fetchHTMLTable("/api/getSEQCountbyLocation"); demofetchHTMLTable("/api/demoGetSEQCountbyLocation") } //Get authors and there country/contitent where they come from -let fetchAuthors = () => { +let demoGetAuthors = () => { demofetchHTMLTable("/api/demoGetAuthors") } // Fetch all institutes/originating labs and their associeted publications -let fetchInstitutesPublications = () => { +let demoFetchInstitutesPublications = () => { demofetchHTMLTable("/api/demoInstitutesPublications") } -//Fetch seqeenctechnologies used by continent +// Fetch sequence technology used by continent let demoGetSEQCountbytechContinent = () => { demofetchHTMLTable("/api/demoGetSEQCountbytechContinent") } @@ -199,35 +222,22 @@ let demoGetSequencePerDate = () => { demofetchHTMLTable('/api/demoGetSequencePerDate') } -let demoLocationGps = () => { - demofetchHTMLTable("/api/demoLocationGps") +let demoGetLocationGps = () => { + demofetchHTMLTable("/api/demoGetLocationGps") } -let getNYsamples = () => { - demofetchHTMLTable("/api/getNYsamples") +let demoGetNYsamples = () => { + demofetchHTMLTable("/api/demoGetNYsamples") } -//old/unused functions -let fetchSEQCountByTech = () => { - fetchHTMLTable("/api/getSEQCountbytech"); +let demoGetSouthAmericaSeq = () => { + demofetchHTMLTable("/api/demoGetSouthAmericaSeq") } -let fetchAllaccessions = () => { - fetchHTMLTable("/api/getAllaccessions"); -}; -let fetchMap = () => { - fetchAPI("/api/getCountByGPS"); - updateMapMarkers(); -}; -let fetchSEQByLocation = () => { - console.log("Missing - set parameter for request, retrieve data") -}; -let fetchSEQCountbyContinent = () => { - fetchHTMLTable("/api/getSEQCountbyContinent"); -} +////****** SPARQL playground functions ***************//// /* diff --git a/bh20simplewebuploader/templates/demo.html b/bh20simplewebuploader/templates/demo.html index ffebc91..393548c 100644 --- a/bh20simplewebuploader/templates/demo.html +++ b/bh20simplewebuploader/templates/demo.html @@ -21,17 +21,19 @@
- + - - + + - - - - + + + + + +