From 82f0aa6e3183e759a61a873826ab9da7b6e12468 Mon Sep 17 00:00:00 2001 From: lltommy Date: Sat, 14 Nov 2020 16:39:40 +0100 Subject: SPARQLplayground: Adding additional example --- bh20simplewebuploader/main.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'bh20simplewebuploader/main.py') diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index 87ef212..73787c2 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -1298,3 +1298,25 @@ ORDER BY ?country_label [{'seq': x['seq']['value'], 'country_label': x['country_label']['value']} for x in result]) + + +@app.route('/api/demoGetSeqByAgeGender', methods=['GET']) +def demoGetSeqByAgeGender(): + prefix = """PREFIX obo: +""" + query="""SELECT DISTINCT ?seq ?gender ?age WHERE { + ?seq ?hostSchema [ obo:PATO_0000047 ?sex] . + ?seq ?hostSchema [ obo:PATO_0000011 ?age ] . + ?sex rdfs:label ?gender . +} +Order by ?age +""" + + description = "List all sequences that have an entry in the field 'host_sex' and 'host_age'. Instead of the IRI we want to show the human readable label and order results by age" + 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'], + 'gender': x['gender']['value'], + 'age': x['age']['value']} for x in result]) \ No newline at end of file -- cgit v1.2.3