aboutsummaryrefslogtreecommitdiff
path: root/bh20simplewebuploader/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'bh20simplewebuploader/main.py')
-rw-r--r--bh20simplewebuploader/main.py127
1 files changed, 115 insertions, 12 deletions
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index e88eb4c..126b8dd 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -8,7 +8,7 @@ import re
import string
import yaml
import pkg_resources
-from flask import Flask, request, redirect, send_file, send_from_directory, render_template
+from flask import Flask, request, redirect, send_file, send_from_directory, render_template, jsonify
import os.path
import requests
@@ -197,6 +197,14 @@ def generate_form(schema, options):
record['type'] = 'number'
# Choose a reasonable precision for the control
record['step'] = '0.0001'
+
+ ### This is to fix the homepage for the moment ## needs more love though
+ # implementation of the [] stuff instead of just text fields
+ ## ToDo - implement lists
+ elif field_type == 'string[]':
+ record['type'] = 'text'
+ elif field_type == 'float[]':
+ record['type'] = 'text'
else:
raise NotImplementedError('Unimplemented field type {} in {} in metadata schema'.format(field_type, type_name))
yield record
@@ -358,7 +366,8 @@ def getAllaccessions():
payload = {'query': query, 'format': 'json'}
r = requests.get(baseURL, params=payload)
result = r.json()['results']['bindings']
- return str(result)
+ return jsonify([{'uri': x['fasta']['value'],
+ 'value': x['value']['value']} for x in result])
# parameter must be encoded e.g. http://arvados.org/keep:6e6276698ed8b0e6cd21f523e4f91179+123/sequence.fasta must become
@@ -368,26 +377,69 @@ def getDetailsForSeq():
seq_id = request.args.get('seq')
query="""SELECT DISTINCT ?key ?value WHERE {<placeholder> ?x [?key ?value]}"""
query=query.replace("placeholder", seq_id)
- print(query)
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
+ return jsonify([{'uri': x['key']['value'],
+ 'value': x['value']['value']} for x in result])
+
+
+@app.route('/api/getSEQCountbytech', methods=['GET'])
+def getSEQCountbytech():
+ query="""SELECT ?tech ?tech_label (count(?fasta) as ?fastaCount) WHERE
+ {?fasta ?x [<http://purl.obolibrary.org/obo/OBI_0600047> ?tech]
+ BIND (concat(?tech,"_label") as ?tech_label)}
+ GROUP BY ?tech ?tech_label ORDER BY DESC (?fastaCount)
+ """
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
+ return jsonify([{'Fasta Count': x['fastaCount']['value'],
+ 'tech': x['tech']['value'],
+ 'Label': x['tech_label']['value']} for x in result])
+
+## Is this one really necessary or should we just use getSEQCountbytech instead?
+@app.route('/api/getAvailableTech', methods=['GET'])
+def getAvailableTech():
+ query="""SELECT distinct ?tech ?tech_label WHERE
+ {?fasta ?x [<http://purl.obolibrary.org/obo/OBI_0600047> ?tech]
+ BIND (concat(?tech,"_label") as ?tech_label)
+ } """
payload = {'query': query, 'format': 'json'}
r = requests.get(baseURL, params=payload)
result = r.json()['results']['bindings']
return str(result)
+## List all Sequences/submissions by a given tech, as example e.g. http://purl.obolibrary.org/obo/OBI_0000759
+## Has to be encoded again so should be --> http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FOBI_0000759
@app.route('/api/getSEQbytech', methods=['GET'])
def getSEQbytech():
- query="""SELECT ?specimen_source ?specimen_source_label (count(?fasta) as ?fastaCount) WHERE
- {?fasta ?x [<http://purl.obolibrary.org/obo/OBI_0600047> ?specimen_source]
- BIND (concat(?specimen_source,"_label") as ?specimen_source_label)}
- GROUP BY ?specimen_source ?specimen_source_label ORDER BY DESC (?fastaCount)
+ query="""SELECT ?fasta WHERE
+ {?fasta ?x [<http://purl.obolibrary.org/obo/OBI_0600047> <placeholder>] }
"""
+ tech = request.args.get('tech')
+ query=query.replace("placeholder", tech)
payload = {'query': query, 'format': 'json'}
r = requests.get(baseURL, params=payload)
result = r.json()['results']['bindings']
return str(result)
+
+## Example location, encoded http%3A%2F%2Fwww.wikidata.org%2Fentity%2FQ1223
@app.route('/api/getSEQbyLocation', methods=['GET'])
def getSEQbyLocation():
+ query="""SELECT ?fasta WHERE {?fasta ?x[ <http://purl.obolibrary.org/obo/GAZ_00000448> <placeholder>]}"""
+ location=request.args.get('location')
+ query=query.replace("placeholder", location)
+ print(query)
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
+ return str(result)
+
+
+@app.route('/api/getSEQCountbyLocation', methods=['GET'])
+def getSEQCountbyLocation():
query="""SELECT ?geoLocation ?geoLocation_label (count(?fasta) as ?fastaCount) WHERE
{?fasta ?x [<http://purl.obolibrary.org/obo/GAZ_00000448> ?geoLocation]
BIND (concat(?geoLocation,"_label") as ?geoLocation_label)}
@@ -396,10 +448,13 @@ def getSEQbyLocation():
payload = {'query': query, 'format': 'json'}
r = requests.get(baseURL, params=payload)
result = r.json()['results']['bindings']
- return str(result)
+ return jsonify([{'Fasta Count': x['fastaCount']['value'],
+ 'GeoLocation': x['geoLocation']['value'],
+ 'GeoLocation Label': x['geoLocation_label']['value']} for x in result])
-@app.route('/api/getSEQbySpecimenSource', methods=['GET'])
-def getSEQbySpecimenSource():
+
+@app.route('/api/getSEQCountbySpecimenSource', methods=['GET'])
+def getSEQCountbySpecimenSource():
query="""SELECT ?specimen_source ?specimen_source_label (count(?fasta) as ?fastaCount) WHERE
{?fasta ?x [<http://purl.obolibrary.org/obo/OBI_0001479> ?specimen_source]
BIND (concat(?specimen_source,"_label") as ?specimen_source_label)}
@@ -409,11 +464,27 @@ def getSEQbySpecimenSource():
payload = {'query': query, 'format': 'json'}
r = requests.get(baseURL, params=payload)
result = r.json()['results']['bindings']
+ return jsonify([{'Fasta Count': x['fastaCount']['value'],
+ 'Specimen Source': x['specimen_source']['value'],
+ 'Label': x['specimen_source_label']['value']} for x in result])
+
+# Example specimen http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FNCIT_C155831
+@app.route('/api/getSEQbySpecimenSource', methods=['GET'])
+def getSEQBySpecimenSource():
+ query="""SELECT ?fasta ?specimen_source ?specimen_source_label WHERE
+ {?fasta ?x [<http://purl.obolibrary.org/obo/OBI_0001479> <placeholder>]
+ BIND (concat(?specimen_source,"_label") as ?specimen_source_label)}
+ """
+ specimen=request.args.get('specimen')
+ query = query.replace("placeholder", specimen)
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
return str(result)
#No data for this atm
-@app.route('/api/getSEQbyHostHealthStatus', methods=['GET'])
-def getSEQbyHostHealthStatus():
+@app.route('/api/getSEQCountbyHostHealthStatus', methods=['GET'])
+def getSEQCountbyHostHealthStatus():
query="""SELECT ?health_status ?health_status_label (count(?fasta) as ?fastaCount) WHERE
{?fasta ?x [<http://purl.obolibrary.org/obo/NCIT_C25688> ?health_status]
BIND (concat(?health_status,"_label") as ?health_status_label)}
@@ -423,4 +494,36 @@ def getSEQbyHostHealthStatus():
payload = {'query': query, 'format': 'json'}
r = requests.get(baseURL, params=payload)
result = r.json()['results']['bindings']
+ return str(result)
+
+@app.route('/api/getSEQbyLocationAndTech', methods=['GET'])
+def getSEQbyLocationAndTech():
+ query="""SELECT ?fasta WHERE { ?fasta ?x [
+ <http://purl.obolibrary.org/obo/GAZ_00000448> <placeholderLoc>; <http://purl.obolibrary.org/obo/OBI_0600047> <placeholderTech> ]}"""
+ location=request.args.get('location')
+ tech=request.args.get('tech')
+ query=query.replace("placeholderLoc", location)
+ query = query.replace("placeholderTech", tech)
+ print(query)
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
+ return str(result)
+
+
+# Example Location http%3A%2F%2Fwww.wikidata.org%2Fentity%2FQ1223
+# Example specimen http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FNCIT_C155831
+@app.route('/api/getSEQbyLocationAndSpecimenSource', methods=['GET'])
+def getSEQbyLocationAndSpecimenSource():
+ query="""SELECT ?fasta WHERE { ?fasta ?x [
+ <http://purl.obolibrary.org/obo/GAZ_00000448> <placeholderLoc>; <http://purl.obolibrary.org/obo/OBI_0001479> <placeholderSpecimen> ]}
+ """
+ location = request.args.get('location')
+ specimen = request.args.get('specimen')
+ query = query.replace("placeholderLoc", location)
+ query = query.replace("placeholderSpecimen", specimen)
+ print(query)
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
return str(result) \ No newline at end of file