about summary refs log tree commit diff
path: root/bh20simplewebuploader
diff options
context:
space:
mode:
Diffstat (limited to 'bh20simplewebuploader')
-rw-r--r--bh20simplewebuploader/main.py37
-rw-r--r--bh20simplewebuploader/static/main.js6
-rw-r--r--bh20simplewebuploader/templates/about.html13
-rw-r--r--bh20simplewebuploader/templates/blog.html13
-rw-r--r--bh20simplewebuploader/templates/demo.html6
-rw-r--r--bh20simplewebuploader/templates/download.html13
-rw-r--r--bh20simplewebuploader/templates/map.html13
7 files changed, 42 insertions, 59 deletions
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index 9132453..8a6794e 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -47,6 +47,7 @@ def type_to_heading(type_name):
     Turn a type name like "sampleSchema" from the metadata schema into a human-readable heading.
     """
 
+    print(type_name,file=sys.stderr)
     # Remove camel case
     decamel = re.sub('([A-Z])', r' \1', type_name)
     # Split
@@ -227,8 +228,13 @@ def generate_form(schema, options):
 
 
 # At startup, we need to load the metadata schema from the uploader module, so we can make a form for it
-METADATA_SCHEMA = yaml.safe_load(pkg_resources.resource_stream("bh20sequploader", "bh20seq-schema.yml"))
-METADATA_OPTION_DEFINITIONS = yaml.safe_load(pkg_resources.resource_stream("bh20sequploader", "bh20seq-options.yml"))
+if os.path.isfile("bh20sequploader/bh20seq-schema.yml"):
+    METADATA_SCHEMA = yaml.safe_load(open("bh20sequploader/bh20seq-schema.yml","r").read())
+    METADATA_OPTION_DEFINITIONS = yaml.safe_load(open("bh20sequploader/bh20seq-options.yml","r").read())
+else:
+    METADATA_SCHEMA = yaml.safe_load(pkg_resources.resource_stream("bh20sequploader", "bh20seq-schema.yml"))
+    METADATA_OPTION_DEFINITIONS = yaml.safe_load(pkg_resources.resource_stream("bh20sequploader", "bh20seq-options.yml"))
+# print(METADATA_SCHEMA,file=sys.stderr)
 FORM_ITEMS = generate_form(METADATA_SCHEMA, METADATA_OPTION_DEFINITIONS)
 
 @app.route('/')
@@ -505,7 +511,7 @@ def status_page():
     Processing status
     """
 
-    api = arvados.api(host=ARVADOS_API, token=ANONYMOUS_TOKEN)
+    api = arvados.api(host=ARVADOS_API, token=ANONYMOUS_TOKEN, insecure=True)
     pending = arvados.util.list_all(api.collections().list, filters=[["owner_uuid", "=", UPLOADER_PROJECT]])
     out = []
     status = {}
@@ -567,11 +573,34 @@ baseURL='http://sparql.genenetwork.org/sparql/'
 
 @app.route('/api/getCount', methods=['GET'])
 def getCount():
-    api = arvados.api(host=ARVADOS_API, token=ANONYMOUS_TOKEN)
+    """
+    Get sequence counts from Arvados record
+    """
+    api = arvados.api(host=ARVADOS_API, token=ANONYMOUS_TOKEN, insecure=True)
     c = api.collections().list(filters=[["owner_uuid", "=", VALIDATED_PROJECT]], limit=1).execute()
 
     return jsonify({'sequences': c["items_available"]})
 
+@app.route('/api/getCountDB', methods=['GET'])
+def getCountDB():
+    """
+    Get sequence counts from Virtuoso DB
+    """
+    query="""
+    PREFIX pubseq: <http://biohackathon.org/bh20-seq-schema#MainSchema/>
+    select (COUNT(distinct ?dataset) as ?num)
+    {
+    ?dataset pubseq:submitter ?id .
+    ?id ?p ?submitter
+    }
+    """
+    payload = {'query': query, 'format': 'json'}
+    r = requests.get(baseURL, params=payload)
+    result = r.json()['results']['bindings']
+    # [{'num': {'type': 'typed-literal', 'datatype': 'http://www.w3.org/2001/XMLSchema#integer', 'value': '1352'}}]
+    # print(result, file=sys.stderr)
+    return jsonify({'sequences': int(result[0]["num"]["value"])})
+
 @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 a9dfc10..4703047 100644
--- a/bh20simplewebuploader/static/main.js
+++ b/bh20simplewebuploader/static/main.js
@@ -89,6 +89,10 @@ let fetchCount = () => {
   fetchAPI("/api/getCount");
 }
 
+let fetchCountDB = () => {
+  fetchAPI("/api/getCountDB");
+}
+
 let fetchSEQCountBySpecimen = () => {
   fetchAPIV2("/api/getSEQCountbySpecimenSource");
 }
@@ -191,7 +195,7 @@ function addField(e) {
   // Increment the number and use the keypath and number to set IDs and cross
   // references.
   // TODO: Heavily dependent on the form field HTML. Maybe we want custom
-  // elements for the labeled controlsd that know how to be list items?
+  // elements for the labeled controls that know how to be list items?
   fieldNumber++
   newField.dataset.number = fieldNumber
   let newID = keypath + '[' + fieldNumber + ']'
diff --git a/bh20simplewebuploader/templates/about.html b/bh20simplewebuploader/templates/about.html
index 07b6951..4bd238e 100644
--- a/bh20simplewebuploader/templates/about.html
+++ b/bh20simplewebuploader/templates/about.html
@@ -11,19 +11,6 @@
 
       <script type="text/javascript">
         let scriptRoot = {{ request.script_root|tojson|safe }}; // examples
-
-        document.addEventListener("DOMContentLoaded", function(){
-            var count = fetch("/api/getCount")
-                .then((resp) => resp.json())
-                .then(function (data) {
-                    count = data["sequences"];
-              console.log(count);
-                    span = document.getElementById("Counter");
-                    txt = document.createTextNode(count);
-                    span.appendChild(txt);
-                });
-        });
-
       </script>
     </body>
 
diff --git a/bh20simplewebuploader/templates/blog.html b/bh20simplewebuploader/templates/blog.html
index 8f8ab66..dbc0b99 100644
--- a/bh20simplewebuploader/templates/blog.html
+++ b/bh20simplewebuploader/templates/blog.html
@@ -73,19 +73,6 @@
 
     <script type="text/javascript">
       let scriptRoot = {{ request.script_root|tojson|safe }}; // examples
-
-      document.addEventListener("DOMContentLoaded", function(){
-          var count = fetch("/api/getCount")
-              .then((resp) => resp.json())
-              .then(function (data) {
-                  count = data["sequences"];
-                  console.log(count);
-                  span = document.getElementById("Counter");
-                  txt = document.createTextNode(count);
-                  span.appendChild(txt);
-              });
-      });
-
     </script>
   </body>
 
diff --git a/bh20simplewebuploader/templates/demo.html b/bh20simplewebuploader/templates/demo.html
index 76c19c4..44aded0 100644
--- a/bh20simplewebuploader/templates/demo.html
+++ b/bh20simplewebuploader/templates/demo.html
@@ -5,6 +5,7 @@
     {% include 'banner.html' %}
     {% include 'menu.html' %}
     {% include 'search.html' %}
+      <p>The Virtuoso database contains <span id="CounterDB"></span> public sequences!</p>
     {% include 'demo-run.html' %}
     {% include 'footer.html' %}
 
@@ -12,16 +13,17 @@
       let scriptRoot = {{ request.script_root|tojson|safe }}; // examples
 
       document.addEventListener("DOMContentLoaded", function(){
-          var count = fetch("/api/getCount")
+          var count = fetch("/api/getCountDB")
               .then((resp) => resp.json())
               .then(function (data) {
                   count = data["sequences"];
                   console.log(count);
-                  span = document.getElementById("Counter");
+                  span = document.getElementById("CounterDB");
                   txt = document.createTextNode(count);
                   span.appendChild(txt);
               });
       });
+
     </script>
   </body>
 
diff --git a/bh20simplewebuploader/templates/download.html b/bh20simplewebuploader/templates/download.html
index 07b6951..4bd238e 100644
--- a/bh20simplewebuploader/templates/download.html
+++ b/bh20simplewebuploader/templates/download.html
@@ -11,19 +11,6 @@
 
       <script type="text/javascript">
         let scriptRoot = {{ request.script_root|tojson|safe }}; // examples
-
-        document.addEventListener("DOMContentLoaded", function(){
-            var count = fetch("/api/getCount")
-                .then((resp) => resp.json())
-                .then(function (data) {
-                    count = data["sequences"];
-              console.log(count);
-                    span = document.getElementById("Counter");
-                    txt = document.createTextNode(count);
-                    span.appendChild(txt);
-                });
-        });
-
       </script>
     </body>
 
diff --git a/bh20simplewebuploader/templates/map.html b/bh20simplewebuploader/templates/map.html
index 6d63c3c..595af0c 100644
--- a/bh20simplewebuploader/templates/map.html
+++ b/bh20simplewebuploader/templates/map.html
@@ -16,19 +16,6 @@
 
        <script type="text/javascript">
         let scriptRoot = {{ request.script_root|tojson|safe }}; // examples
-
-        document.addEventListener("DOMContentLoaded", function(){
-            var count = fetch("/api/getCount")
-                .then((resp) => resp.json())
-                .then(function (data) {
-                    count = data["sequences"];
-              console.log(count);
-                    span = document.getElementById("Counter");
-                    txt = document.createTextNode(count);
-                    span.appendChild(txt);
-                });
-        });
-
       </script>
 
 <!-- Make sure you put this AFTER Leaflet's CSS -->