aboutsummaryrefslogtreecommitdiff
path: root/bh20simplewebuploader
diff options
context:
space:
mode:
authorPjotr Prins2020-10-28 16:19:38 +0000
committerPjotr Prins2020-10-28 16:19:38 +0000
commite9ea11c5332668af16c0497bf2b578433b05b32f (patch)
tree3f2207588efb35977e09af0c7a4165c41161a967 /bh20simplewebuploader
parent89ccd3ce507ea2abad408a9df559aa3bbcc0e377 (diff)
downloadbh20-seq-resource-e9ea11c5332668af16c0497bf2b578433b05b32f.tar.gz
bh20-seq-resource-e9ea11c5332668af16c0497bf2b578433b05b32f.tar.lz
bh20-seq-resource-e9ea11c5332668af16c0497bf2b578433b05b32f.zip
List by country and added to map
Diffstat (limited to 'bh20simplewebuploader')
-rw-r--r--bh20simplewebuploader/main.py44
-rw-r--r--bh20simplewebuploader/static/main.js8
-rw-r--r--bh20simplewebuploader/static/map.js4
-rw-r--r--bh20simplewebuploader/templates/list.html42
4 files changed, 82 insertions, 16 deletions
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: <http://biohackathon.org/bh20-seq-schema#MainSchema/>
+ PREFIX sio: <http://semanticscience.org/resource/>
+ select distinct ?name ?date where
+ {{
+ ?sample <http://purl.obolibrary.org/obo/GAZ_00000448> <{loc}> .
+ ?sample <http://semanticscience.org/resource/SIO_000115> ?name .
+ ?sample <http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C25164> ?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[ <http://edamontology.org/data_2091> ?value ]}"""
+ query="""
+ SELECT DISTINCT ?fasta ?value WHERE
+ {
+ ?fasta ?x[ <http://edamontology.org/data_2091> ?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[ <http://purl.obolibrary.org/obo/GAZ_00000448> ?location] .
- ?location <http://www.wikidata.org/prop/direct/P625> ?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[ <http://purl.obolibrary.org/obo/GAZ_00000448> ?location] .
+ ?location <http://www.wikidata.org/prop/direct/P625> ?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="<table>"
-
- // 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<data.length;i++) {
- htmlString=htmlString+"<tr><td><a href='#' onclick='fetchSEQByLocation(\""+data[i]["key"]+"\");'>"+data[i]["label"]+"</a></td><td>"+data[i]["count"]+"<td></tr>"
- }
- */
for (var i=0; i<data.length;i++) {
let url = data[i]["key"];
let label = data[i]["label"];
@@ -97,7 +90,6 @@ function fetchHTMLTable(apiEndPoint) {
}
]
-
*/
let searchGlobal = (toHTML) => {
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("<b>" + label + "</b><br/>" + "SARS-CoV-2<br/>sequences: " +fastaCount);
+ marker.bindPopup("<b>" + label + "</b><br/>" + "SARS-CoV-2<br/><a href=\"/location?label="+location+"\">sequences: " +fastaCount + "</a>");
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 @@
+<!DOCTYPE html>
+<html>
+ {% include 'header.html' %}
+ <body>
+ {% include 'banner.html' %}
+ {% include 'menu.html' %}
+
+ <hr>
+
+ <h1>{{id}}</h1>
+
+ <div class="content">
+ <section class="blog-entries">
+ <div class="blog-table">
+ {% for row in l: %}
+ <div class="blog-table-body">
+ <div class="blog-table-row">
+ {% for col in h: %}
+ <div class="blog-table-cell">
+ {% if col == 'name': %}
+ <a href="/resource/{{row[col]['value']}}">{{ row[col]['value'] }}</a>
+ {% else %}
+ {{ row[col]['value'] }}
+ {% endif %}
+ </div>
+ {% endfor %}
+ </div>
+ </div>
+ {% endfor %}
+ </div>
+ </section>
+
+ </div>
+
+ {% include 'footer.html' %}
+
+ <script type="text/javascript">
+ let scriptRoot = {{ request.script_root|tojson|safe }}; // examples
+ </script>
+ </body>
+
+</html>