From 5867eb6953e2e6564eb79d6f824952ce0bf2e28b Mon Sep 17 00:00:00 2001 From: lltommy Date: Sat, 14 Nov 2020 18:51:42 +0100 Subject: SPARQL playground: additional examples --- bh20simplewebuploader/main.py | 72 ++++++++++++++++++++++++++++++- bh20simplewebuploader/static/main.js | 9 ++++ bh20simplewebuploader/templates/demo.html | 12 ++++-- 3 files changed, 88 insertions(+), 5 deletions(-) (limited to 'bh20simplewebuploader') diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index 73787c2..ea4ec10 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -1261,7 +1261,7 @@ PREFIX wikiE: """ } ORDER BY ?seq""" - description = "Get all samples and their information (key, values) that were taken in New York (Q1384)!" + description = "Get all sequences and all sequence information (key, values) that were taken in New York (Q1384)!" payload = {'query': prefix + query, 'format': 'json'} r = requests.get(sparqlURL, params=payload) result = r.json()['results']['bindings'] @@ -1319,4 +1319,72 @@ Order by ?age 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 + 'age': x['age']['value']} for x in result]) + + +@app.route('/api/demoGetSeqIllumina', methods=['GET']) +def demoGetSeqIllumina(): + prefix = """PREFIX obo: +PREFIX efo: """ + ##TODO adjust OBI_0600047 to NCIT_C153598 once new schema is live + query="""SELECT DISTINCT ?seq WHERE { +?seq ?technologySchema [obo:OBI_0600047 efo:EFO_0008635 ] +}""" + + + description = "List all sequences that have as 'sample_sequencing_technology' (NCIT_C153598) Illumina iSeq 100 (EFO_0008635)" + 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']} for x in result]) + + + + +@app.route('/api/demoGetSeqWithStrain', methods=['GET']) +def demoGetSeqWithStrain(): + prefix = """PREFIX SIO: """ + query="""SELECT DISTINCT ?strain ?seq WHERE { +?seq ?virusSchema [SIO:SIO_010055 ?strain] +}""" + + description = "List all sequences with data in 'virus_strain'. Show the strain and the relevant identifer!" + 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}], + [{'strain': x['strain']['value'], + 'seq': x['seq']['value']} for x in result]) + + + +@app.route('/api/demoGetContinentSpecimentSeqCount', methods=['GET']) +def demoGetContinentSpecimentSeqCount(): + prefix = """PREFIX obo: +PREFIX rdfs: +PREFIX wiki: """ + query="""SELECT ?continent_label ?specimen_source_label (count(?seq) as ?seqCount) WHERE + { + ?seq ?x [obo:OBI_0001479 ?specimen_source] . + ?seq ?y [ obo:GAZ_00000448 ?location] . + + ?location wiki:P17 ?country . + ?location wiki:P30 ?continent . + + ?specimen_source rdfs:label ?specimen_source_label . + ?continent rdfs:label ?continent_label. + } + + GROUP BY ?specimen_source ?specimen_source_label ?continent_label + ORDER BY ?continent_label DESC(?seqCount)""" + + description = "Show a count of sequences by continent and specimen_source. For readability the labels for specimen_source and ?continent are retrieved." + 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}], + [{'continent_label': x['continent_label']['value'], + 'specimen_source_label': x['specimen_source_label']['value'], + 'seqCount': x['seqCount']['value']} for x in result]) + diff --git a/bh20simplewebuploader/static/main.js b/bh20simplewebuploader/static/main.js index 1aa2582..aa1f06f 100644 --- a/bh20simplewebuploader/static/main.js +++ b/bh20simplewebuploader/static/main.js @@ -238,7 +238,16 @@ let demoGetSeqByAgeGender = () => { demofetchHTMLTable("/api/demoGetSeqByAgeGender") } +let demoGetSeqIllumina = () => { + demofetchHTMLTable("/api/demoGetSeqIllumina") +} +let demoGetSeqWithStrain = () => { + demofetchHTMLTable("/api/demoGetSeqWithStrain") +} +let demoGetContinentSpecimentSeqCount = () => { + demofetchHTMLTable("/api/demoGetContinentSpecimentSeqCount") +} ////****** SPARQL playground functions ***************//// diff --git a/bh20simplewebuploader/templates/demo.html b/bh20simplewebuploader/templates/demo.html index 742185b..dc6281d 100644 --- a/bh20simplewebuploader/templates/demo.html +++ b/bh20simplewebuploader/templates/demo.html @@ -21,17 +21,23 @@
- - + + + + - + + + + + -- cgit v1.2.3