aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPjotr Prins2020-07-20 11:31:13 +0100
committerPjotr Prins2020-07-20 11:31:13 +0100
commitf368b3e047d14055bc63899771c782ebbb8c6553 (patch)
treea6f77d435de3895fe61e52e791a3ebb431b2f473
parentd41ecc84e61048449538fbaabc1a777d95f42618 (diff)
downloadbh20-seq-resource-f368b3e047d14055bc63899771c782ebbb8c6553.tar.gz
bh20-seq-resource-f368b3e047d14055bc63899771c782ebbb8c6553.tar.lz
bh20-seq-resource-f368b3e047d14055bc63899771c782ebbb8c6553.zip
Start Public REST API
-rw-r--r--bh20simplewebuploader/__init__.py1
-rw-r--r--bh20simplewebuploader/api.py16
-rw-r--r--bh20simplewebuploader/main.py5
-rw-r--r--test/rest-api.org93
4 files changed, 110 insertions, 5 deletions
diff --git a/bh20simplewebuploader/__init__.py b/bh20simplewebuploader/__init__.py
index e69de29..2dcc632 100644
--- a/bh20simplewebuploader/__init__.py
+++ b/bh20simplewebuploader/__init__.py
@@ -0,0 +1 @@
+import bh20simplewebuploader.api
diff --git a/bh20simplewebuploader/api.py b/bh20simplewebuploader/api.py
new file mode 100644
index 0000000..8bd1a22
--- /dev/null
+++ b/bh20simplewebuploader/api.py
@@ -0,0 +1,16 @@
+# Public API for PubSeq
+
+import sys
+import requests
+
+from flask import Flask, request, redirect, send_file, send_from_directory, render_template, jsonify
+from bh20simplewebuploader.main import app
+
+@app.route('/api/version')
+def version():
+ return jsonify({ 'service': 'PubSeq', 'version': 0.10 })
+
+@app.route('/api/ebi/sample-<id>.xml', methods=['GET'])
+def ebi_sample(id):
+ page = render_template('ebi-sample.xml',**locals())
+ return page
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index b40db6f..aad607d 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -936,8 +936,3 @@ def getSEQbyLocationAndSpecimenSource():
r = requests.get(baseURL, params=payload)
result = r.json()['results']['bindings']
return str(result)
-
-@app.route('/api/ebi/sample-<id>.xml', methods=['GET'])
-def ebi_sample(id):
- page = render_template('ebi-sample.xml',**locals())
- return page
diff --git a/test/rest-api.org b/test/rest-api.org
new file mode 100644
index 0000000..c797cf3
--- /dev/null
+++ b/test/rest-api.org
@@ -0,0 +1,93 @@
+* PubSeq REST API
+
+Here we document the public REST API that comes with PubSeq. The tests
+are written and run in the amazing emacs [[https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html][org-babel]]. Execute a code
+block with C-c C-c. You may need to set
+
+#+begin_src elisp
+(org-babel-do-load-languages
+ 'org-babel-load-languages
+ '((python . t)))
+(setq org-babel-python-command "python3")
+#+end_src
+
+#+RESULTS:
+: python3
+
+To skip confirmations you may also want to set
+
+: (setq org-confirm-babel-evaluate nil)
+
+** Check the version
+
+#+begin_src python :session
+import requests
+response = requests.get("http://localhost:5000/api/version")
+response_body = response.json()
+assert response_body["service"] == "PubSeq", "PubSeq API not found"
+response_body
+#+end_src
+
+#+RESULTS:
+| service | : | PubSeq | version | : | 0.1 |
+
+** Fetch EBI XML
+
+#+begin_src python :session
+requests.get("http://localhost:5000/api/ebi/sample-MT32690.1.xml").text
+#+end_src
+
+#+RESULTS:
+#+begin_example
+<?xml version="1.0" encoding="UTF-8"?>
+<SAMPLE_SET>
+ <SAMPLE alias="MT32690.1" center_name="COVID-19 PubSeq">
+ <TITLE>COVID-19 PubSeq Sample</TITLE>
+ <SAMPLE_NAME>
+ <TAXON_ID>2697049</TAXON_ID>
+ <SCIENTIFIC_NAME>Severe acute respiratory syndrome coronavirus 2</SCIENTIFIC_NAME>
+ <COMMON_NAME>SARS-CoV-2</COMMON_NAME>
+ </SAMPLE_NAME>
+ <SAMPLE_ATTRIBUTES>
+ <SAMPLE_ATTRIBUTE>
+ <TAG>investigation type</TAG>
+ <VALUE></VALUE>
+ </SAMPLE_ATTRIBUTE>
+ <SAMPLE_ATTRIBUTE>
+ <TAG>sequencing method</TAG>
+ <VALUE></VALUE>
+ </SAMPLE_ATTRIBUTE>
+ <SAMPLE_ATTRIBUTE>
+ <TAG>collection date</TAG>
+ <VALUE></VALUE>
+ </SAMPLE_ATTRIBUTE>
+ <SAMPLE_ATTRIBUTE>
+ <TAG>geographic location (latitude)</TAG>
+ <VALUE></VALUE>
+ <UNITS>DD</UNITS>
+ </SAMPLE_ATTRIBUTE>
+ <SAMPLE_ATTRIBUTE>
+ <TAG>geographic location (longitude)</TAG>
+ <VALUE></VALUE>
+ <UNITS>DD</UNITS>
+ </SAMPLE_ATTRIBUTE>
+ <SAMPLE_ATTRIBUTE>
+ <TAG>geographic location (country and/or sea)</TAG>
+ <VALUE></VALUE>
+ </SAMPLE_ATTRIBUTE>
+ <SAMPLE_ATTRIBUTE>
+ <TAG>geographic location (region and locality)</TAG>
+ <VALUE></VALUE>
+ </SAMPLE_ATTRIBUTE>
+ <SAMPLE_ATTRIBUTE>
+ <TAG>environment (material)</TAG>
+ <VALUE></VALUE>
+ </SAMPLE_ATTRIBUTE>
+ <SAMPLE_ATTRIBUTE>
+ <TAG>ENA-CHECKLIST</TAG>
+ <VALUE>ERC000011</VALUE>
+ </SAMPLE_ATTRIBUTE>
+ </SAMPLE_ATTRIBUTES>
+ </SAMPLE>
+</SAMPLE_SET>
+#+end_example