aboutsummaryrefslogtreecommitdiff
path: root/bh20simplewebuploader/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'bh20simplewebuploader/main.py')
-rw-r--r--bh20simplewebuploader/main.py59
1 files changed, 25 insertions, 34 deletions
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index 2aebe80..1dff207 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -48,10 +48,10 @@ def name_to_label(field_name):
"""
Turn a filed name like "host_health_status" from the metadata schema into a human-readable label.
"""
-
+
# May end in a number, which should be set off by a space
set_off_number = re.sub('([0-9]+)$', r' \1', field_name)
-
+
return string.capwords(set_off_number.replace('_', ' '))
def is_iri(string):
@@ -72,13 +72,13 @@ def generate_form(schema, options):
Each dict either has a 'heading' (in which case we put a heading for a
form section in the template) or an 'id', 'label', 'type', and 'required'
(in which case we make a form field in the template).
-
+
Non-heading dicts with type 'select' will have an 'options' field, with a
list of (name, value) tuples, and represent a form dropdown element.
-
+
Non-heading dicts with type 'number' may have a 'step', which, if <1 or
'any', allows the number to be a float.
-
+
Non-heading dicts may have a human-readable 'docstring' field describing
them.
@@ -125,7 +125,7 @@ def generate_form(schema, options):
docstring = None
if not isinstance(field_type, str):
# If the type isn't a string
-
+
# It may have documentation
docstring = field_type.get('doc', None)
@@ -159,7 +159,7 @@ def generate_form(schema, options):
optional = True
# Drop the ?
field_type = field_type[:-1]
-
+
# Decide if the field is a list (type ends in [])
is_list = False
if field_type.endswith('[]'):
@@ -259,7 +259,7 @@ def parse_input(input_string, html_type, number_step=None):
Raise NotImplementedError if we forgot to implement a type.
"""
- if html_type == 'text':
+ if html_type == 'text' or html_type == 'select':
return input_string
elif html_type == 'number':
# May be an int or a float.
@@ -310,7 +310,7 @@ def receive_files():
elif request.form.get('metadata_type', None) == 'fill':
# Build a metadata dict
metadata = {}
-
+
# When we have metadata for an item, use this to set it.
# If it is an item in a list, set is_list=True
def set_metadata(item_id, value, is_list=False):
@@ -324,7 +324,7 @@ def receive_files():
if parent not in dest_dict:
dest_dict[parent] = {}
dest_dict = dest_dict[parent]
-
+
if not is_list:
dest_dict[key] = value
else:
@@ -336,22 +336,22 @@ def receive_files():
# Pull all the field values we wanted from the form
if 'heading' in item:
continue
-
+
if item['list']:
# This is a list, serialized into form fields
-
+
# We count how many values we got
value_count = 0
-
+
for index in itertools.count():
# Get [0] through [n], until something isn't there.
entry_id = '{}[{}]'.format(item['id'], index)
-
+
if index == 1000:
# Don't let them provide too much stuff.
return (render_template('error.html',
error_message="You provided an extremely large number of values for the metadata item {}".format(item['id'])), 403)
-
+
if entry_id in request.form:
if len(request.form[entry_id]) > 0:
# Put an entry in the list
@@ -371,7 +371,7 @@ def receive_files():
else:
# We have run out of form fields for this list.
break
-
+
if item['required'] and value_count == 0:
# They forgot a required item. Maybe all entries were empty.
return (render_template('error.html',
@@ -439,18 +439,21 @@ def getAllaccessions():
@app.route('/api/getDetailsForSeq', methods=['GET'])
def getDetailsForSeq():
seq_id = request.args.get('seq')
- query="""SELECT DISTINCT ?key ?value WHERE {<placeholder> ?x [?key ?value]}"""
+ query="""SELECT DISTINCT ?key ?key_label ?value WHERE {
+ <http://arvados.org/keep:00a6af865453564f6a59b3d2c81cc7c1+123/sequence.fasta> ?x [?key ?value] .
+ OPTIONAL {?key <http://www.w3.org/2000/01/rdf-schema#label> ?key_tmp_label } .
+ 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)
result = r.json()['results']['bindings']
- return jsonify([{'uri': x['key']['value'],
+ return jsonify([{'uri': x['key']['value'], 'key_label': x['key_label']['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
+ query="""SELECT ?tech ?tech_label (count(?fasta) as ?fastaCount) WHERE
{?fasta ?x [<http://purl.obolibrary.org/obo/OBI_0600047> ?tech] .
OPTIONAL {?tech <http://www.w3.org/2000/01/rdf-schema#label> ?tech_tmp_label } .
BIND(IF(BOUND(?tech_tmp_label), ?tech_tmp_label,?tech) as ?tech_label)}
@@ -463,23 +466,11 @@ def getSEQCountbytech():
'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 ?fasta WHERE
+ query="""SELECT ?fasta WHERE
{?fasta ?x [<http://purl.obolibrary.org/obo/OBI_0600047> <placeholder>] }
"""
tech = request.args.get('tech')
@@ -565,7 +556,7 @@ def getSEQCountbyHostHealthStatus():
@app.route('/api/getSEQbyLocationAndTech', methods=['GET'])
def getSEQbyLocationAndTech():
- query="""SELECT ?fasta WHERE { ?fasta ?x [
+ 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')
@@ -582,7 +573,7 @@ def getSEQbyLocationAndTech():
# 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 [
+ 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')