From 802c4001340baa6f79c8107bb58add5dba9ad2b8 Mon Sep 17 00:00:00 2001 From: lltommy Date: Mon, 15 Jun 2020 17:31:17 +0200 Subject: Adding endpoints using grouping of continents --- bh20simplewebuploader/main.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'bh20simplewebuploader/main.py') diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index b67e1bf..840070d 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -587,6 +587,46 @@ def getSEQCountbyLocation(): 'label': x['geoLocation_label']['value']} for x in result]) +@app.route('/api/getSEQCountbyContinent', methods=['GET']) +def getSEQCountbyContinent(): + query="""SELECT DISTINCT ?continent ?continent_label (count(?fasta) as ?fastaCount) WHERE { + ?fasta ?x[ ?location] . + ?location ?continent . + OPTIONAL { ?continent rdfs:label ?key_tmp_label } + BIND(IF(BOUND(?key_tmp_label),?key_tmp_label, ?location) as ?continent_label) + } + GROUP BY ?continent ?continent_label + """ + payload = {'query': query, 'format': 'json'} + r = requests.get(baseURL, params=payload) + result = r.json()['results']['bindings'] + return jsonify([{'count': x['fastaCount']['value'], + 'key': x['continent']['value'], + 'label': x['continent_label']['value']} for x in result]) + + + +@app.route('/api/getSEQCountbyCountryContinent', methods=['GET']) +def getSEQCountbyCountryContinent(): + query="""SELECT DISTINCT ?location ?location_label (count(?fasta) as ?fastaCount) WHERE { + ?fasta ?x[ ?location] . + ?location . + OPTIONAL { ?location rdfs:label ?key_tmp_label } + BIND(IF(BOUND(?key_tmp_label),?key_tmp_label, ?location) as ?location_label) + } + GROUP BY ?location ?location_label + """ + continent = request.args.get('continent') + query = query.replace("placeholder", continent) + payload = {'query': query, 'format': 'json'} + r = requests.get(baseURL, params=payload) + result = r.json()['results']['bindings'] + return jsonify([{'count': x['fastaCount']['value'], + 'key': x['location']['value'], + 'label': x['location_label']['value']} for x in result]) + + + @app.route('/api/getSEQCountbySpecimenSource', methods=['GET']) def getSEQCountbySpecimenSource(): query="""SELECT ?specimen_source ?specimen_source_label (count(?fasta) as ?fastaCount) WHERE -- cgit v1.2.3