From 60212ade3721cc9eebc976d65c973ab6b690bd3e Mon Sep 17 00:00:00 2001
From: Pjotr Prins
Date: Sun, 19 Jul 2020 10:47:07 +0100
Subject: Search table
---
bh20simplewebuploader/main.py | 21 ++++++++++++-
bh20simplewebuploader/static/main.js | 49 ++++++++++++++++++++++++++---
bh20simplewebuploader/templates/export.html | 22 ++++++++++---
3 files changed, 81 insertions(+), 11 deletions(-)
(limited to 'bh20simplewebuploader')
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index b88055f..48520fe 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -692,7 +692,26 @@ def getCountDB():
# Execute a 'global search'
@app.route('/api/search', methods=['GET'])
def search():
- return jsonify(["TESTME"])
+ s = request.args.get('s')
+ query = """
+ PREFIX pubseq:
+ PREFIX sio:
+ select distinct ?id ?seq
+ {
+ ?sample sio:SIO_000115 "%s" .
+ ?sample sio:SIO_000115 ?id .
+ ?seq pubseq:sample ?sample .
+ ?sample ?p ?o .
+ }
+ """ % 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'],
+ } for x in result])
@app.route('/api/getAllaccessions', methods=['GET'])
def getAllaccessions():
diff --git a/bh20simplewebuploader/static/main.js b/bh20simplewebuploader/static/main.js
index dc0864b..8271d2c 100644
--- a/bh20simplewebuploader/static/main.js
+++ b/bh20simplewebuploader/static/main.js
@@ -2,6 +2,24 @@
* Menu and navigation
*/
+/* Convert a list of table items to an HTML DIV table */
+function toDIVTable(rows) {
+ if (rows.length == 0)
+ html = "no results";
+ else {
+ html = '
';
+ rows.forEach(row => {
+ html += '
';
+ html += '
';
+ html += row["id"];
+ html += '
';
+ html += '
';
+ });
+ html += '
';
+ }
+ document.getElementById("table").innerHTML = html;
+}
+
/* Toggle between adding and removing the "responsive" class to topnav
* when the user clicks on the icon */
function myFunction() {
@@ -13,13 +31,16 @@ function myFunction() {
}
}
-function fetchAPI(apiEndPoint) {
+function fetchAPI(apiEndPoint,injectHTML=NULL) {
fetch(scriptRoot + apiEndPoint)
.then(response => {
+ console.log("* response",response);
return response.json();
})
.then(data => {
- console.log(data);
+ console.log("* data",data);
+ if (injectHTML)
+ injectHTML(data);
});
}
@@ -48,11 +69,29 @@ function fetchHTMLTable(apiEndPoint) {
});
}
+/* Fetch record info using a 'global search'. Returns for example
+
+[
+ {
+ "id": "MT326090.1",
+ "seq": "http://collections.lugli.arvadosapi.com/c=10eaef75e0b875f81aa1f411c75370cf+126/sequence.fasta"
+ },
+ {
+ "id": "MT326090.1",
+ "seq": "http://collections.lugli.arvadosapi.com/c=5a4c815f3e076ad7760a91864c39dd07+126/sequence.fasta"
+ }
+]
+
-/* Fetch record info using a 'global search' */
-let searchGlobal = () => {
+ */
+let searchGlobal = (toHTML) => {
let m = document.getElementById('search-input').value;
- fetchAPI(scriptRoot + "/api/search?s=" + encodeURIComponent(m));
+ fetchAPI(scriptRoot + "/api/search?s=" + encodeURIComponent(m), toHTML);
+}
+
+// Same as above, but generates div table
+let searchGlobaltoDIVTable = () => {
+ searchGlobal(toDIVTable);
}
let searchSeq = () => {
diff --git a/bh20simplewebuploader/templates/export.html b/bh20simplewebuploader/templates/export.html
index f105290..1f0d9b7 100644
--- a/bh20simplewebuploader/templates/export.html
+++ b/bh20simplewebuploader/templates/export.html
@@ -11,24 +11,36 @@
COVID-19 PubSeq allows for exporting forms and data for other
services.
+
SPARQL
+
+
+ First of all, PubSeq exports a SPARQL endpoint
+ here that allows
+ you do do any query on the data. See this
+ document for
+ examples.
+
+
Export EBI/ENA Forms
- Uploading data to EBI/ENA with PubSeq is described
- here.
- To export, first search for an uploaded entry through its
- identifier:
+ Uploading data to EBI/ENA with PubSeq is described
+ here. To
+ export, first search for an uploaded entry through its
+ identifier: