diff options
Diffstat (limited to 'bh20simplewebuploader')
-rw-r--r-- | bh20simplewebuploader/main.py | 51 | ||||
-rw-r--r-- | bh20simplewebuploader/static/main.js | 37 | ||||
-rw-r--r-- | bh20simplewebuploader/templates/demo-run.html | 1 | ||||
-rw-r--r-- | bh20simplewebuploader/templates/map.html | 46 |
4 files changed, 133 insertions, 2 deletions
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index b67e1bf..40046c8 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -459,6 +459,13 @@ def about_page(): buf = get_html_body('doc/web/about.html') return render_template('about.html',menu='ABOUT',embed=buf) +## +@app.route('/map') +def map_page(): + return render_template('map.html',menu='DEMO') + + + ## 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 @@ -522,10 +529,10 @@ def getCountByGPS(): payload = {'query': query, 'format': 'json'} r = requests.get(baseURL, params=payload) result = r.json()['results']['bindings'] - return jsonify([{'Fasta Count': x['fastaCount']['value'], + return jsonify([{'count': x['fastaCount']['value'], 'Location': x['location']['value'], 'LocationLabel': x['location_label']['value'], - 'GPS' :x['GPS']['value']} for x in result]) + 'GPS' :x['GPS']['value'][6:-1]} for x in result]) @app.route('/api/getSEQCountbytech', methods=['GET']) @@ -587,6 +594,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[ <http://purl.obolibrary.org/obo/GAZ_00000448> ?location] . + ?location <http://www.wikidata.org/prop/direct/P30> ?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[ <http://purl.obolibrary.org/obo/GAZ_00000448> ?location] . + ?location <http://www.wikidata.org/prop/direct/P30> <placeholder> . + 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 diff --git a/bh20simplewebuploader/static/main.js b/bh20simplewebuploader/static/main.js index 149eb3c..f2e5d99 100644 --- a/bh20simplewebuploader/static/main.js +++ b/bh20simplewebuploader/static/main.js @@ -56,6 +56,7 @@ function fetchAPI(apiEndPoint) { } +// Copy from function above but now added as table instead of plain json function fetchAPIV2(apiEndPoint) { fetch(scriptRoot + apiEndPoint) .then(response => { @@ -115,6 +116,9 @@ let fetchSEQByLocation = () => { console.log("Missing - set parameter for request, retrieve data") }; +let fetchSEQCountbyContinent = () => { + fetchAPIV2("/api/getSEQCountbyContinent"); +} /* @@ -243,3 +247,36 @@ function on_submit_button() { return false; } } + + + +// + +function drawMap(){ + +// initialize the map on the "map" div with a given center and zoom +var mymap = L.map('mapid').setView([51.505, -0.09], 1); + +L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { + attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' +}).addTo(mymap); + +fetch(scriptRoot + "api/getCountByGPS") + .then(response => { + console.log(response) + return response.json(); + }) + .then(data => { + + for (var i=0; i<data.length;i++) { + gps=data[i]["GPS"].split(" ") + var circle = L.circle([gps[1], gps[0]], { + color: 'red', + fillColor: '#f03', + fillOpacity: 0.5, + radius: parseInt(data[i]["count"]) //not working for whatever reason + }).addTo(mymap); + } + + }); +}
\ No newline at end of file diff --git a/bh20simplewebuploader/templates/demo-run.html b/bh20simplewebuploader/templates/demo-run.html index a5b4150..a8f9edc 100644 --- a/bh20simplewebuploader/templates/demo-run.html +++ b/bh20simplewebuploader/templates/demo-run.html @@ -6,6 +6,7 @@ <button class="button" onclick="fetchSEQCountByLocation()">Count by Location</button> <button class="button" onclick="fetchSEQCountByTech()">Count by Sequencer</button> <button class="button" onclick="fetchAllaccessions()">Show All accessions</button> + <button class="button" onclick="fetchSEQCountbyContinent()">Count by Continent</button> <button class="button" onclick="fetchCountByGPS()">Map</button> </div> diff --git a/bh20simplewebuploader/templates/map.html b/bh20simplewebuploader/templates/map.html new file mode 100644 index 0000000..6d63c3c --- /dev/null +++ b/bh20simplewebuploader/templates/map.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<html> + {% include 'header.html' %} +<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" + integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" + crossorigin=""/> + + {% include 'banner.html' %} + {% include 'menu.html' %} + <div id="mapid" style="height: 500px;"></div> + + {% include 'footer.html' %} + + + + + <script type="text/javascript"> + let scriptRoot = {{ request.script_root|tojson|safe }}; // examples + + document.addEventListener("DOMContentLoaded", function(){ + var count = fetch("/api/getCount") + .then((resp) => resp.json()) + .then(function (data) { + count = data["sequences"]; + console.log(count); + span = document.getElementById("Counter"); + txt = document.createTextNode(count); + span.appendChild(txt); + }); + }); + + </script> + +<!-- Make sure you put this AFTER Leaflet's CSS --> + <script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" + integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" + crossorigin=""></script> + + <script> + //drawMap + drawMap() + </script> + + </body> + +</html> |