aboutsummaryrefslogtreecommitdiff
path: root/bh20simplewebuploader
diff options
context:
space:
mode:
authorPjotr Prins2020-07-21 09:28:43 +0100
committerPjotr Prins2020-07-21 09:28:43 +0100
commit56b5c444fd10cc569c4c0d7b76d034799ce679f9 (patch)
tree2ca3fdf27884c4dca9178a80f5916d04550209ea /bh20simplewebuploader
parent2e96d0d87abd6357868114b0b59ee66b08985235 (diff)
downloadbh20-seq-resource-56b5c444fd10cc569c4c0d7b76d034799ce679f9.tar.gz
bh20-seq-resource-56b5c444fd10cc569c4c0d7b76d034799ce679f9.tar.lz
bh20-seq-resource-56b5c444fd10cc569c4c0d7b76d034799ce679f9.zip
Working on search
Diffstat (limited to 'bh20simplewebuploader')
-rw-r--r--bh20simplewebuploader/api.py37
-rw-r--r--bh20simplewebuploader/main.py26
-rw-r--r--bh20simplewebuploader/static/main.js4
3 files changed, 37 insertions, 30 deletions
diff --git a/bh20simplewebuploader/api.py b/bh20simplewebuploader/api.py
index 8bd1a22..29fa2b8 100644
--- a/bh20simplewebuploader/api.py
+++ b/bh20simplewebuploader/api.py
@@ -1,10 +1,11 @@
# Public API for PubSeq
-import sys
+import os
import requests
+import sys
from flask import Flask, request, redirect, send_file, send_from_directory, render_template, jsonify
-from bh20simplewebuploader.main import app
+from bh20simplewebuploader.main import app, baseURL
@app.route('/api/version')
def version():
@@ -14,3 +15,35 @@ def version():
def ebi_sample(id):
page = render_template('ebi-sample.xml',**locals())
return page
+
+@app.route('/api/search', methods=['GET'])
+def search():
+ """
+ Execute a 'global search'
+ """
+ s = request.args.get('s')
+ if s == "":
+ s = "MT326090.1"
+ query = """
+ PREFIX pubseq: <http://biohackathon.org/bh20-seq-schema#MainSchema/>
+ PREFIX sio: <http://semanticscience.org/resource/>
+ PREFIX edam: <http://edamontology.org/>
+ select distinct ?id ?seq ?info
+ {
+ ?sample sio:SIO_000115 "%s" .
+ ?sample sio:SIO_000115 ?id .
+ ?seq pubseq:sample ?sample .
+ ?sample edam:data_2091 ?info .
+ } limit 100
+ """ % s
+ payload = {'query': query, 'format': 'json'}
+ r = requests.get(baseURL, params=payload)
+ result = r.json()['results']['bindings']
+ # metadata = file.name(seq)+"/metadata.yaml"
+ print(result)
+ return jsonify([{
+ 'id': x['id']['value'],
+ 'fasta': x['seq']['value'],
+ 'collection': os.path.dirname(x['seq']['value']),
+ 'info': x['info']['value'],
+ } for x in result])
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index c306749..62ec5cd 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -694,32 +694,6 @@ def getCountDB():
# print(result, file=sys.stderr)
return jsonify({'sequences': int(result[0]["num"]["value"])})
-# Execute a 'global search'
-@app.route('/api/search', methods=['GET'])
-def search():
- s = request.args.get('s')
- query = """
- PREFIX pubseq: <http://biohackathon.org/bh20-seq-schema#MainSchema/>
- PREFIX sio: <http://semanticscience.org/resource/>
- PREFIX edam: <http://edamontology.org/>
- select distinct ?id ?seq ?info
- {
- ?sample sio:SIO_000115 "%s" .
- ?sample sio:SIO_000115 ?id .
- ?seq pubseq:sample ?sample .
- ?sample edam:data_2091 ?info .
- } limit 100
- """ % s
- payload = {'query': query, 'format': 'json'}
- r = requests.get(baseURL, params=payload)
- result = r.json()['results']['bindings']
- print(result,file=sys.stderr);
- return jsonify([{
- 'id': x['id']['value'],
- 'seq': x['seq']['value'],
- 'info': x['info']['value'],
- } for x in result])
-
@app.route('/api/getAllaccessions', methods=['GET'])
def getAllaccessions():
query="""SELECT DISTINCT ?fasta ?value WHERE {?fasta ?x[ <http://edamontology.org/data_2091> ?value ]}"""
diff --git a/bh20simplewebuploader/static/main.js b/bh20simplewebuploader/static/main.js
index a12311e..c0bc23f 100644
--- a/bh20simplewebuploader/static/main.js
+++ b/bh20simplewebuploader/static/main.js
@@ -19,11 +19,11 @@ function toDIVTable(rows) {
html = '<div class="rTable">';
rows.forEach(row => {
id = row['id'];
- seq = row['seq'];
info = row['info'];
html += '<div class="rTableRow">';
html += cell('<a href="'+info+'">'+id+'</a>');
- html += cell('<a href="'+seq+'">FASTA</a>');
+ html += cell('<a href="'+row['collection']+'">Collection</a>');
+ html += cell('<a href="'+row['fasta']+'">FASTA</a>');
html += cell('<a href="/api/ebi/sample-'+id+'.xml">EBI/ENA export XML</a>');
html += '</div>';
});