From 56b5c444fd10cc569c4c0d7b76d034799ce679f9 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Tue, 21 Jul 2020 09:28:43 +0100 Subject: Working on search --- bh20simplewebuploader/api.py | 37 ++++++++++++++++++++++++++++++++++-- bh20simplewebuploader/main.py | 26 ------------------------- bh20simplewebuploader/static/main.js | 4 ++-- 3 files changed, 37 insertions(+), 30 deletions(-) (limited to 'bh20simplewebuploader') 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: + PREFIX sio: + PREFIX edam: + 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: - PREFIX sio: - PREFIX edam: - 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[ ?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 = ''; rows.forEach(row => { id = row['id']; - seq = row['seq']; info = row['info']; html += ''; html += cell(''+id+''); - html += cell('FASTA'); + html += cell('Collection'); + html += cell('FASTA'); html += cell('EBI/ENA export XML'); html += ''; }); -- cgit v1.2.3