about summary refs log tree commit diff
path: root/bh20simplewebuploader/main.py
diff options
context:
space:
mode:
authorlltommy2020-11-11 09:56:12 +0100
committerlltommy2020-11-11 09:56:12 +0100
commitd6aa323b6fc7a82e45cc1df51fc72c2d547146eb (patch)
tree6e8b77bde4dc34fab3fa8804906f3cb821f61dae /bh20simplewebuploader/main.py
parentc5fe5de7e4c77bfb48b1ae2f662c2d9cc120c06e (diff)
parentc872248e43c1c66e5fed8ef341f7b4ac21d63e6f (diff)
downloadbh20-seq-resource-d6aa323b6fc7a82e45cc1df51fc72c2d547146eb.tar.gz
bh20-seq-resource-d6aa323b6fc7a82e45cc1df51fc72c2d547146eb.tar.lz
bh20-seq-resource-d6aa323b6fc7a82e45cc1df51fc72c2d547146eb.zip
Merge branch 'master' of https://github.com/arvados/bh20-seq-resource
Diffstat (limited to 'bh20simplewebuploader/main.py')
-rw-r--r--bh20simplewebuploader/main.py53
1 files changed, 48 insertions, 5 deletions
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index 73503b4..1d7154c 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -7,6 +7,7 @@ import logging
 import os
 import sys
 import re
+import redis
 import string
 import ruamel.yaml as yaml
 import pkg_resources
@@ -252,8 +253,19 @@ def send_home():
     """
     Send the front page.
     """
-
-    return render_template('home.html', menu='HOME', load_map=True)
+    redis_client = redis.Redis(host=os.environ.get('HOST', 'localhost'),
+                               port=os.environ.get('PORT', 6379),
+                               db=os.environ.get('REDIS_DB', 0))
+    tweets = []
+    for tweet_id in redis_client.zrevrange('bh20-tweet-score:',
+                                           0, -1):
+        tweets.append(
+            {k.decode("utf-8"): v.decode("utf-8") for k, v in
+             redis_client.hgetall(tweet_id).items()}
+        )
+    return render_template('home.html', menu='HOME',
+                           tweets=tweets,
+                           load_map=True)
 
 
 @app.route('/upload')
@@ -675,13 +687,32 @@ sparqlURL='http://sparql.genenetwork.org/sparql/'
 @app.route('/resource/<id>')
 def resource(id):
     """Get a COVID19 resource using identifier"""
+
     query=f"""
 PREFIX pubseq: <http://biohackathon.org/bh20-seq-schema#MainSchema/>
 PREFIX sio: <http://semanticscience.org/resource/>
 select distinct ?sample ?geoname ?date ?source ?geo ?sampletype ?institute ?sequenceuri
+where {{
 {{
    ?sample sio:SIO_000115 "{id}" .
    ?sequenceuri pubseq:sample ?sample .
+}}
+union
+{{
+   <http://collections.lugli.arvadosapi.com/c={id}/sequence.fasta> pubseq:sample ?sample .
+   ?sequenceuri pubseq:sample ?sample .
+}}
+union
+{{
+   <http://covid19.genenetwork.org/resource/{id}> pubseq:sample ?sample .
+   ?sequenceuri pubseq:sample ?sample .
+}}
+union
+{{
+   ?sequenceuri <http://biohackathon.org/bh20-seq-schema/collection_pdh> "{id}" .
+   ?sequenceuri pubseq:sample ?sample .
+}}
+
    ?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 .
@@ -699,8 +730,9 @@ select distinct ?sample ?geoname ?date ?source ?geo ?sampletype ?institute ?sequ
     logging.info("^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
     # return jsonify({'sequences': int(result[0]["num"]["value"])})
     sequenceuri=sample['sequenceuri']['value']
-    collectionuri=sequenceuri.split('sequence.fasta')[0]
-    metauri=collectionuri+'metadata.yaml'
+    m = re.match(r"http://collections.lugli.arvadosapi.com/c=([^/]*)/sequence.fasta|http://covid19.genenetwork.org/resource/(.*)", sequenceuri)
+    fastauri = "http://collections.lugli.arvadosapi.com/c=%s/sequence.fasta" % m.group(1)
+    metauri = "http://collections.lugli.arvadosapi.com/c=%s/metadata.yaml" % m.group(1)
     locationuri=sample['geo']['value']
     location=sample['geoname']['value']
     date=sample['date']['value']
@@ -715,7 +747,18 @@ select distinct ?sample ?geoname ?date ?source ?geo ?sampletype ?institute ?sequ
     institute=''
     if 'institute' in sample:
         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)
+    return render_template('permalink.html',
+                           id=id,
+                           menu='',
+                           uri=f"http://covid19.genenetwork.org/resource/{id}",
+                           sequenceuri=fastauri,
+                           locationuri=locationuri,
+                           location=location,
+                           date=date,
+                           source=source,
+                           sampletype=sampletype,
+                           institute=institute,
+                           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