From 2e7ff0e040a011e4bc3aae2c2816c7f3f4ed875d Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Wed, 28 Oct 2020 11:12:51 +0000 Subject: Adding more metadata to resource uri --- bh20simplewebuploader/main.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'bh20simplewebuploader/main.py') diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index 37f4590..4ec3251 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -670,21 +670,24 @@ sparqlURL='http://sparql.genenetwork.org/sparql/' ## # Example http://host/resource/MT326090.1 +# Example http://host/resource/SRR11621868 @app.route('/resource/') def resource(id): """Get a COVID19 resource using identifier""" - query=""" + query=f""" PREFIX pubseq: PREFIX sio: -select distinct ?sample ?geoname ?date ?source ?geo ?sampletype -{ - ?sample sio:SIO_000115 "MT326090.1" . +select distinct ?sample ?geoname ?date ?source ?geo ?sampletype ?institute ?sequenceuri +{{ + ?sample sio:SIO_000115 "{id}" . + ?sequenceuri pubseq:sample ?sample . ?sample ?geo . ?geo rdfs:label ?geoname . ?sample ?date . - OPTIONAL {?sample ?source } - OPTIONAL {?sample ?sampletype } -} + OPTIONAL {{ ?sample ?source }} + OPTIONAL {{ ?sample ?sampletype }} + OPTIONAL {{ ?sample ?institute }} +}} """ payload = {'query': query, 'format': 'json'} r = requests.get(sparqlURL, params=payload) @@ -694,12 +697,24 @@ select distinct ?sample ?geoname ?date ?source ?geo ?sampletype logging.info(sample) logging.info("^^^^^^^^^^^^^^^^^^^^^^^^^^^^") # return jsonify({'sequences': int(result[0]["num"]["value"])}) + sequenceuri=sample['sequenceuri']['value'] + collectionuri=sequenceuri.split('sequence.fasta')[0] + metauri=collectionuri+'metadata.yaml' 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) + if date == '1970-01-01': + date = '' + source='' + if 'source' in sample: + source=sample['source']['value'] + sampletype='' + if 'sampletype' in sample: + sampletype=sample['sampletype']['value'] + 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) ## Dynamic API functions starting here ## This is quick and dirty for now, just to get something out and demonstrate the queries -- cgit v1.2.3