aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPjotr Prins2020-10-28 10:01:31 +0000
committerPjotr Prins2020-10-28 10:01:31 +0000
commite8e150c85414f67e9f15dfdcd04bcbe2369ac44f (patch)
tree77ff7337c813f857222d7f73e36d95d6b63f96d0
parent38ee6ad0cfa86b40566c8d45a92400b38351a717 (diff)
downloadbh20-seq-resource-e8e150c85414f67e9f15dfdcd04bcbe2369ac44f.tar.gz
bh20-seq-resource-e8e150c85414f67e9f15dfdcd04bcbe2369ac44f.tar.lz
bh20-seq-resource-e8e150c85414f67e9f15dfdcd04bcbe2369ac44f.zip
Create permalink and some output
-rw-r--r--bh20simplewebuploader/api.py6
-rw-r--r--bh20simplewebuploader/main.py69
-rw-r--r--bh20simplewebuploader/static/main.css8
-rw-r--r--bh20simplewebuploader/templates/permalink.html91
4 files changed, 155 insertions, 19 deletions
diff --git a/bh20simplewebuploader/api.py b/bh20simplewebuploader/api.py
index 2a5529f..b1b505f 100644
--- a/bh20simplewebuploader/api.py
+++ b/bh20simplewebuploader/api.py
@@ -5,7 +5,7 @@ import requests
import sys
from flask import Flask, request, redirect, send_file, send_from_directory, render_template, jsonify
-from bh20simplewebuploader.main import app, baseURL
+from bh20simplewebuploader.main import app, sparqlURL
# Helper functions
@@ -31,7 +31,7 @@ def fetch_sample_metadata(id):
} limit 5
""" % id
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
return r.json()['results']['bindings']
# Main API routes
@@ -83,7 +83,7 @@ def search():
} limit 100
""" % s
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
# metadata = file.name(seq)+"/metadata.yaml"
print(result)
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index d3542c3..37f4590 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -663,11 +663,48 @@ def contact_page():
buf = get_html_body('doc/web/contact.html','https://github.com/arvados/bh20-seq-resource/blob/master/doc/web/contact.org')
return render_template('about.html',menu='CONTACT',embed=buf)
+##
+## Linked data permanent links/resources
+##
+sparqlURL='http://sparql.genenetwork.org/sparql/'
+
+##
+# Example http://host/resource/MT326090.1
+@app.route('/resource/<id>')
+def resource(id):
+ """Get a COVID19 resource using identifier"""
+ query="""
+PREFIX pubseq: <http://biohackathon.org/bh20-seq-schema#MainSchema/>
+PREFIX sio: <http://semanticscience.org/resource/>
+select distinct ?sample ?geoname ?date ?source ?geo ?sampletype
+{
+ ?sample sio:SIO_000115 "MT326090.1" .
+ ?sample <http://purl.obolibrary.org/obo/GAZ_00000448> ?geo .
+ ?geo rdfs:label ?geoname .
+ ?sample <http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C25164> ?date .
+ OPTIONAL {?sample <http://edamontology.org/data_2091> ?source }
+ OPTIONAL {?sample <http://purl.obolibrary.org/obo/OBI_0001479> ?sampletype }
+}
+ """
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(sparqlURL, params=payload)
+ result = r.json()['results']['bindings']
+ # for now we just take the first one
+ sample = result[0]
+ logging.info(sample)
+ logging.info("^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
+ # return jsonify({'sequences': int(result[0]["num"]["value"])})
+ locationuri=sample['geo']['value']
+ location=sample['geoname']['value']
+ date=sample['date']['value']
+ source=sample['source']['value']
+ sampletype=sample['sampletype']['value']
+ return render_template('permalink.html',id=id,menu='',uri=f"http://covid19.genenetwork.org/resource/{id}",locationuri=locationuri,location=location,date=date,source=source,sampletype=sampletype)
+
## 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
## but most likely you don't want to touch the queries, Cheers.
-baseURL='http://sparql.genenetwork.org/sparql/'
@app.route('/api/getCount', methods=['GET'])
def getCount():
@@ -693,7 +730,7 @@ def getCountDB():
}
"""
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
# [{'num': {'type': 'typed-literal', 'datatype': 'http://www.w3.org/2001/XMLSchema#integer', 'value': '1352'}}]
# print(result, file=sys.stderr)
@@ -703,7 +740,7 @@ def getCountDB():
def getAllaccessions():
query="""SELECT DISTINCT ?fasta ?value WHERE {?fasta ?x[ <http://edamontology.org/data_2091> ?value ]}"""
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return jsonify([{'uri': x['fasta']['value'],
'value': x['value']['value']} for x in result])
@@ -720,7 +757,7 @@ def getDetailsForSeq():
BIND(IF(BOUND(?key_tmp_label),?key_tmp_label, ?key) as ?key_label)}"""
query=query.replace("placeholder", seq_id)
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return jsonify([{'uri': x['key']['value'], 'key_label': x['key_label']['value'],
'value': x['value']['value']} for x in result])
@@ -737,7 +774,7 @@ def getCountByGPS():
GROUP BY ?location ?location_label ?GPS
"""
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return jsonify([{'count': x['fastaCount']['value'],
'Location': x['location']['value'],
@@ -754,7 +791,7 @@ def getSEQCountbytech():
GROUP BY ?tech ?tech_label ORDER BY DESC (?fastaCount)
"""
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return jsonify([{'count': x['fastaCount']['value'],
'key': x['tech']['value'],
@@ -770,7 +807,7 @@ def getSEQbytech():
tech = request.args.get('tech')
query=query.replace("placeholder", tech)
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return str(result)
@@ -783,7 +820,7 @@ def getSEQbyLocation():
query=query.replace("placeholder", location)
print(query)
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return str(result)
@@ -797,7 +834,7 @@ def getSEQCountbyLocation():
GROUP BY ?geoLocation ?geoLocation_label ORDER BY DESC (?fastaCount)
"""
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return jsonify([{'count': x['fastaCount']['value'],
'key': x['geoLocation']['value'],
@@ -816,7 +853,7 @@ def getSEQCountbyContinent():
GROUP BY ?continent ?continent_label
"""
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return jsonify([{'count': x['fastaCount']['value'],
'key': x['continent']['value'],
@@ -837,7 +874,7 @@ def getSEQCountbyCountryContinent():
continent = request.args.get('continent')
query = query.replace("placeholder", continent)
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return jsonify([{'count': x['fastaCount']['value'],
'key': x['location']['value'],
@@ -855,7 +892,7 @@ def getSEQCountbySpecimenSource():
ORDER BY DESC (?fastaCount)
"""
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return jsonify([{'count': x['fastaCount']['value'],
'key': x['specimen_source']['value'],
@@ -871,7 +908,7 @@ def getSEQBySpecimenSource():
specimen=request.args.get('specimen')
query = query.replace("placeholder", specimen)
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return str(result)
@@ -885,7 +922,7 @@ def getSEQCountbyHostHealthStatus():
ORDER BY DESC (?fastaCount)
"""
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return str(result)
@@ -899,7 +936,7 @@ def getSEQbyLocationAndTech():
query = query.replace("placeholderTech", tech)
print(query)
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return str(result)
@@ -917,6 +954,6 @@ def getSEQbyLocationAndSpecimenSource():
query = query.replace("placeholderSpecimen", specimen)
print(query)
payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
+ r = requests.get(sparqlURL, params=payload)
result = r.json()['results']['bindings']
return str(result)
diff --git a/bh20simplewebuploader/static/main.css b/bh20simplewebuploader/static/main.css
index 2773afb..bc4f705 100644
--- a/bh20simplewebuploader/static/main.css
+++ b/bh20simplewebuploader/static/main.css
@@ -140,6 +140,14 @@ form h4 {
border-radius: 20px;
}
+.content {
+ background-color: #B2F8F8;
+ margin: 30px auto;
+ padding: 20px;
+ width: 95%;
+ border-radius: 20px;
+}
+
.button {
border-radius: 5px;
background: #B2F8F8;
diff --git a/bh20simplewebuploader/templates/permalink.html b/bh20simplewebuploader/templates/permalink.html
new file mode 100644
index 0000000..f75c21e
--- /dev/null
+++ b/bh20simplewebuploader/templates/permalink.html
@@ -0,0 +1,91 @@
+<!DOCTYPE html>
+<html>
+ {% include 'header.html' %}
+ <body>
+ {% include 'banner.html' %}
+ {% include 'menu.html' %}
+
+ <hr>
+
+ <h1>{{id}}</h1>
+
+ <h2>
+ This is page represents a permanent COVID-19 PubSeq SARS-CoV-2 sequence resource
+ </h2>
+
+ <div class="content">
+ <section class="blog-entries">
+ <div class="blog-table">
+ <div class="blog-table-body">
+ <div class="blog-table-row">
+ <div class="blog-table-cell">
+ Identifier
+ </div>
+ <div class="blog-table-cell">
+ <a href="{{ uri }}">{{id}}</a>
+ </div>
+ </div>
+ </div>
+ <div class="blog-table-body">
+ <div class="blog-table-row">
+ <div class="blog-table-cell">
+ Permanent link
+ </div>
+ <div class="blog-table-cell">
+ <a href="{{ uri }}">{{uri}}</a>
+ </div>
+ </div>
+ </div>
+ <div class="blog-table-body">
+ <div class="blog-table-row">
+ <div class="blog-table-cell">
+ Location
+ </div>
+ <div class="blog-table-cell">
+ <a href="{{ locationuri }}">{{location}}</a>
+ </div>
+ </div>
+ </div>
+ <div class="blog-table-body">
+ <div class="blog-table-row">
+ <div class="blog-table-cell">
+ Sampling date
+ </div>
+ <div class="blog-table-cell">
+ {{ date }}
+ </div>
+ </div>
+ </div>
+ <div class="blog-table-body">
+ <div class="blog-table-row">
+ <div class="blog-table-cell">
+ Sample type
+ </div>
+ <div class="blog-table-cell">
+ <a href="{{ sampletype }}">{{sampletype}}</a>
+ </div>
+ </div>
+ </div>
+ <div class="blog-table-body">
+ <div class="blog-table-row">
+ <div class="blog-table-cell">
+ Source
+ </div>
+ <div class="blog-table-cell">
+ <a href="{{ source }}">{{source}}</a>
+ </div>
+ </div>
+ </div>
+ </div>
+ </section>
+
+ </div>
+
+ {% include 'footer.html' %}
+
+ <script type="text/javascript">
+ let scriptRoot = {{ request.script_root|tojson|safe }}; // examples
+ </script>
+ </body>
+
+</html>