aboutsummaryrefslogtreecommitdiff
path: root/bh20simplewebuploader
diff options
context:
space:
mode:
authorPjotr Prins2020-07-19 10:47:07 +0100
committerPjotr Prins2020-07-19 10:47:07 +0100
commit60212ade3721cc9eebc976d65c973ab6b690bd3e (patch)
treea4903f688b59cc4e692a7617a8b9da41e736779e /bh20simplewebuploader
parent7b2d388dbed11384c6a388a5437cca0b8f2914fd (diff)
downloadbh20-seq-resource-60212ade3721cc9eebc976d65c973ab6b690bd3e.tar.gz
bh20-seq-resource-60212ade3721cc9eebc976d65c973ab6b690bd3e.tar.lz
bh20-seq-resource-60212ade3721cc9eebc976d65c973ab6b690bd3e.zip
Search table
Diffstat (limited to 'bh20simplewebuploader')
-rw-r--r--bh20simplewebuploader/main.py21
-rw-r--r--bh20simplewebuploader/static/main.js49
-rw-r--r--bh20simplewebuploader/templates/export.html22
3 files changed, 81 insertions, 11 deletions
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: <http://biohackathon.org/bh20-seq-schema#MainSchema/>
+ PREFIX sio: <http://semanticscience.org/resource/>
+ 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 = '<div class="rTable">';
+ rows.forEach(row => {
+ html += '<div class="rTableRow">';
+ html += ' <div class="rTableCell">';
+ html += row["id"];
+ html += ' </div>';
+ html += '</div>';
+ });
+ html += '</div>';
+ }
+ 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.
+ <h2>SPARQL</h2>
+
+ <p>
+ First of all, PubSeq exports a SPARQL endpoint
+ <a href="http://sparql.genenetwork.org/sparql/">here</a> that allows
+ you do do any query on the data. See this
+ <a href="/blog?id=using-covid-19-pubseq-part1">document</a> for
+ examples.
+ </p>
+
<h2>Export EBI/ENA Forms</h2>
<p>
- Uploading data to EBI/ENA with PubSeq is described
- <a href="/blog?id=using-covid-19-pubseq-part6">here</a>.
- To export, first search for an uploaded entry through its
- identifier:
+ Uploading data to EBI/ENA with PubSeq is described
+ <a href="/blog?id=using-covid-19-pubseq-part6">here</a>. To
+ export, first search for an uploaded entry through its
+ identifier:
</p>
<div class="search">
<input id="search-input" type="search" placeholder="e.g. MT246484" required>
- <button class="button search-button" type="submit" onclick="searchGlobal()">
+ <button class="button search-button" type="submit" onclick="searchGlobaltoDIVTable()">
<span class="icon ion-search">
<span class="sr-only">Search</span>
</span>
</button>
</div>
+ <section id="table" />
+
</section>
{% include 'footer.html' %}