aboutsummaryrefslogtreecommitdiff
path: root/bh20simplewebuploader
diff options
context:
space:
mode:
authorBonfaceKilz2020-04-26 05:25:35 +0300
committerBonfaceKilz2020-04-26 05:25:35 +0300
commit5565338df4c172df2c140bfc1380262c3fb02aed (patch)
tree29b6fa2d304e1d3478e89b6e99f66c26fb66f446 /bh20simplewebuploader
parente158d57813b3cfe494b47d3a865200ecddd11c4d (diff)
downloadbh20-seq-resource-5565338df4c172df2c140bfc1380262c3fb02aed.tar.gz
bh20-seq-resource-5565338df4c172df2c140bfc1380262c3fb02aed.tar.lz
bh20-seq-resource-5565338df4c172df2c140bfc1380262c3fb02aed.zip
Jsonify response and pick the values
Diffstat (limited to 'bh20simplewebuploader')
-rw-r--r--bh20simplewebuploader/main.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index e88eb4c..53a4cda 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
@@ -358,7 +358,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,11 +369,12 @@ 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 str(result)
+ return jsonify([{'uri': x['key']['value'],
+ 'value': x['value']['value']} for x in result])
+
@app.route('/api/getSEQbytech', methods=['GET'])
def getSEQbytech():
@@ -384,7 +386,9 @@ def getSEQbytech():
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'],
+ 'Specimen Source': x['specimen_source']['value'],
+ 'Label': x['specimen_source_label']['value']} for x in result])
@app.route('/api/getSEQbyLocation', methods=['GET'])
def getSEQbyLocation():
@@ -396,7 +400,10 @@ 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():
@@ -409,7 +416,9 @@ def getSEQbySpecimenSource():
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'],
+ 'Specimen Source': x['specimen_source']['value'],
+ 'Label': x['specimen_source_label']['value']} for x in result])
#No data for this atm
@app.route('/api/getSEQbyHostHealthStatus', methods=['GET'])
@@ -423,4 +432,4 @@ def getSEQbyHostHealthStatus():
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
+ return str(result)