From e9ea11c5332668af16c0497bf2b578433b05b32f Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Wed, 28 Oct 2020 16:19:38 +0000 Subject: List by country and added to map --- bh20simplewebuploader/main.py | 44 ++++++++++++++++++++++++++----- bh20simplewebuploader/static/main.js | 8 ------ bh20simplewebuploader/static/map.js | 4 +-- bh20simplewebuploader/templates/list.html | 42 +++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 bh20simplewebuploader/templates/list.html diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index 92cea2e..0be9d9f 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -668,6 +668,7 @@ def contact_page(): ## sparqlURL='http://sparql.genenetwork.org/sparql/' + ## # Example http://covid19.genenetwork.org/resource/MT326090.1 # Example http://host/resource/SRR11621868 @@ -716,6 +717,30 @@ select distinct ?sample ?geoname ?date ?source ?geo ?sampletype ?institute ?sequ institute=sample['institute']['value'] return render_template('permalink.html',id=id,menu='',uri=f"http://covid19.genenetwork.org/resource/{id}",sequenceuri=sequenceuri,locationuri=locationuri,location=location,date=date,source=source,sampletype=sampletype,institute=institute,collectionuri=collectionuri,metauri=metauri) +# http://covid19.genenetwork.org/location?label=http://www.wikidata.org/entity/Q114 +# http://localhost:5067/location?label=http://www.wikidata.org/entity/Q114 +@app.route('/location', methods=['GET']) +def location(): + """Show country resource""" + loc = request.args.get('label') + logging.info(loc) + logging.info("^^^^^^^^^^^^^^^^^^^^^^^^^^^^") + query = f""" + PREFIX pubseq: + PREFIX sio: + select distinct ?name ?date where + {{ + ?sample <{loc}> . + ?sample ?name . + ?sample ?date . + }} order by ?name + """ + payload = {'query': query, 'format': 'json'} + r = requests.get(sparqlURL, params=payload) + result = r.json()['results']['bindings'] + logging.info(result) + return render_template('list.html',id=loc,menu='',h=['name','date'],l=result) + ## Dynamic API functions starting here ## This is quick and dirty for now, just to get something out and demonstrate the queries ## Feel free to rename the functions/endpoints, feel free to process result so we get nicer JSON @@ -753,7 +778,12 @@ def getCountDB(): @app.route('/api/getAllaccessions', methods=['GET']) def getAllaccessions(): - query="""SELECT DISTINCT ?fasta ?value WHERE {?fasta ?x[ ?value ]}""" + query=""" + SELECT DISTINCT ?fasta ?value WHERE + { + ?fasta ?x[ ?value ] + } + """ payload = {'query': query, 'format': 'json'} r = requests.get(sparqlURL, params=payload) result = r.json()['results']['bindings'] @@ -780,11 +810,13 @@ def getDetailsForSeq(): # Endpoint should provide all necessary information to draw a map (!) @app.route('/api/getCountByGPS', methods=['GET']) def getCountByGPS(): - query="""SELECT DISTINCT ?location ?location_label ?GPS (count(?fasta) as ?fastaCount) WHERE { - ?fasta ?x[ ?location] . - ?location ?GPS . - OPTIONAL { ?location rdfs:label ?key_tmp_label } - BIND(IF(BOUND(?key_tmp_label),?key_tmp_label, ?location) as ?location_label) + query=""" + SELECT DISTINCT ?location ?location_label ?GPS (count(?fasta) as ?fastaCount) WHERE + { + ?fasta ?x[ ?location] . + ?location ?GPS . + 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 ?GPS """ diff --git a/bh20simplewebuploader/static/main.js b/bh20simplewebuploader/static/main.js index 6e63ed3..89bc603 100644 --- a/bh20simplewebuploader/static/main.js +++ b/bh20simplewebuploader/static/main.js @@ -66,13 +66,6 @@ function fetchHTMLTable(apiEndPoint) { .then(data => { console.log(data) htmlString="" - - // Depending on what we want to explore we'd have to call a different function ....? But how to Include that? - /* - for (var i=0; i" - } - */ for (var i=0; i { let m = document.getElementById('search-input').value; diff --git a/bh20simplewebuploader/static/map.js b/bh20simplewebuploader/static/map.js index cabb63d..c01659f 100644 --- a/bh20simplewebuploader/static/map.js +++ b/bh20simplewebuploader/static/map.js @@ -86,7 +86,7 @@ function buildMapMarkers(data) { }}}); // ---- Build the marker list for (let i = 0; i < data.length; i++) { - let {"count": fastaCount, GPS, LocationLabel: label } = data[i]; + let {"count": fastaCount, GPS, Location: location, LocationLabel: label } = data[i]; let countSeq = Number(fastaCount); let coordinates = GPS.split(" "); @@ -95,7 +95,7 @@ function buildMapMarkers(data) { [lon, lat] = coordinates.map(parseFloat); let point = L.point() marker = new seqMarker([lat, lon],markerOptions={title: fastaCount+" sequences",sequences: countSeq}); - marker.bindPopup("" + label + "
" + "SARS-CoV-2
sequences: " +fastaCount); + marker.bindPopup("" + label + "
" + "SARS-CoV-2
sequences: " +fastaCount + ""); markers.addLayer(marker); } } diff --git a/bh20simplewebuploader/templates/list.html b/bh20simplewebuploader/templates/list.html new file mode 100644 index 0000000..d50a045 --- /dev/null +++ b/bh20simplewebuploader/templates/list.html @@ -0,0 +1,42 @@ + + + {% include 'header.html' %} + + {% include 'banner.html' %} + {% include 'menu.html' %} + +
+ +

{{id}}

+ +
+
+
+ {% for row in l: %} +
+
+ {% for col in h: %} +
+ {% if col == 'name': %} + {{ row[col]['value'] }} + {% else %} + {{ row[col]['value'] }} + {% endif %} +
+ {% endfor %} +
+
+ {% endfor %} +
+
+ +
+ + {% include 'footer.html' %} + + + + + -- cgit v1.2.3
"+data[i]["label"]+""+data[i]["count"]+"