about summary refs log tree commit diff
path: root/qc_app
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-20 09:57:23 +0300
committerFrederick Muriuki Muriithi2024-01-20 09:57:23 +0300
commitcdd4dc456e56bb4eb055e1cb7f2518d45fb3bfb9 (patch)
tree73248acbadd5014f2b26da41da3098f1ac5ecc1e /qc_app
parent53b1e7cb181380a24aab4cbc7a9634b2d8dd2d29 (diff)
downloadgn-uploader-cdd4dc456e56bb4eb055e1cb7f2518d45fb3bfb9.tar.gz
Fetch sample/case names from database
Fetch the sample/case names from the database rather than from a
static file in the repository.

Issue:
https://issues.genenetwork.org/issues/quality-control/read-samples-from-database-by-species
Diffstat (limited to 'qc_app')
-rw-r--r--qc_app/entry.py7
-rw-r--r--qc_app/jobs.py19
-rw-r--r--qc_app/parse.py25
-rw-r--r--qc_app/static/js/upload_progress.js3
-rw-r--r--qc_app/templates/index.html17
5 files changed, 58 insertions, 13 deletions
diff --git a/qc_app/entry.py b/qc_app/entry.py
index 0cd34c5..987fdcd 100644
--- a/qc_app/entry.py
+++ b/qc_app/entry.py
@@ -104,9 +104,10 @@ def upload_file():
         return render_template(
             "index.html", species=with_db_connection(species)), 400
 
-    return redirect(url_for(
-        "parse.parse", filename=filename,
-        filetype=request.form["filetype"]))
+    return redirect(url_for("parse.parse",
+                            speciesid=request.form["speciesid"],
+                            filename=filename,
+                            filetype=request.form["filetype"]))
 
 @entrybp.route("/data-review", methods=["GET"])
 def data_review():
diff --git a/qc_app/jobs.py b/qc_app/jobs.py
index a8257a3..f5e5173 100644
--- a/qc_app/jobs.py
+++ b/qc_app/jobs.py
@@ -32,17 +32,24 @@ def initialise_job(# pylint: disable=[too-many-arguments]
     redis_conn.expire(name=the_job["job_id"], time=timedelta(seconds=ttl_seconds))
     return the_job
 
-def build_file_verification_job(
-        redis_conn: Redis, filepath: str, filetype: str, redisurl: str,
+def build_file_verification_job(#pylint: disable=[too-many-arguments]
+        redis_conn: Redis,
+        dburi: str,
+        redisuri: str,
+        speciesid: int,
+        filepath: str,
+        filetype: str,
         ttl_seconds: int):
     "Build a file verification job"
-    job_id = str(uuid4())
+    jobid = str(uuid4())
     command = [
-        sys.executable, "-m", "scripts.validate_file", filetype, filepath, redisurl,
-        job_id
+        sys.executable, "-m", "scripts.validate_file",
+        dburi, redisuri, jobid,
+        "--redisexpiry", str(ttl_seconds),
+        str(speciesid), filetype, filepath,
     ]
     return initialise_job(
-        redis_conn, job_id, command, "file-verification", ttl_seconds, {
+        redis_conn, jobid, command, "file-verification", ttl_seconds, {
             "filetype": filetype,
             "filename": os.path.basename(filepath), "percent": 0
         })
diff --git a/qc_app/parse.py b/qc_app/parse.py
index ceb8fcf..40f7b44 100644
--- a/qc_app/parse.py
+++ b/qc_app/parse.py
@@ -7,7 +7,10 @@ from flask import flash, request, url_for, redirect, Blueprint, render_template
 from flask import current_app as app
 
 from quality_control.errors import InvalidValue, DuplicateHeading
-from . import jobs
+
+from qc_app import jobs
+from qc_app.dbinsert import species_by_id
+from qc_app.db_utils import with_db_connection
 
 parsebp = Blueprint("parse", __name__)
 
@@ -23,8 +26,25 @@ def isduplicateheading(item):
 def parse():
     """Trigger file parsing"""
     errors = False
+    speciesid = request.args.get("speciesid")
     filename = request.args.get("filename")
     filetype = request.args.get("filetype")
+    if speciesid is None:
+        flash("No species selected", "alert-error")
+        errors = True
+    else:
+        try:
+            speciesid = int(speciesid)
+            species = with_db_connection(
+                lambda con: species_by_id(con, speciesid))
+            if not bool(species):
+                flash("No such species.", "alert-error")
+                errors = True
+        except ValueError:
+            flash("Invalid speciesid provided. Expected an integer.",
+                  "alert-error")
+            errors = True
+
     if filename is None:
         flash("No file provided", "alert-error")
         errors = True
@@ -50,7 +70,8 @@ def parse():
     with Redis.from_url(redisurl, decode_responses=True) as rconn:
         job = jobs.launch_job(
             jobs.build_file_verification_job(
-                rconn, filepath, filetype, redisurl,
+                rconn, app.config["SQL_URI"], redisurl,
+                speciesid, filepath, filetype,
                 app.config["JOBS_TTL_SECONDS"]),
             redisurl,
             f"{app.config['UPLOAD_FOLDER']}/job_errors")
diff --git a/qc_app/static/js/upload_progress.js b/qc_app/static/js/upload_progress.js
index 98a503a..c98c33c 100644
--- a/qc_app/static/js/upload_progress.js
+++ b/qc_app/static/js/upload_progress.js
@@ -66,6 +66,9 @@ function selected_filetype(radios) {
 function setup_formdata(form) {
     var formdata = new FormData();
     formdata.append(
+	"speciesid",
+	form.querySelector("#select_species01").value)
+    formdata.append(
 	"qc_text_file",
 	form.querySelector("input[type='file']").files[0]);
     formdata.append(
diff --git a/qc_app/templates/index.html b/qc_app/templates/index.html
index a454dd2..358b521 100644
--- a/qc_app/templates/index.html
+++ b/qc_app/templates/index.html
@@ -1,4 +1,5 @@
 {%extends "base.html"%}
+{%from "flash_messages.html" import flash_all_messages%}
 
 {%block title%}Data Upload{%endblock%}
 
@@ -55,6 +56,18 @@
   {%endwith%}
 
   <fieldset>
+    <label for="select_species01">Species</label>
+    <select id="select_species01"
+	    name="speciesid"
+	    required="required">
+      <option value="">Select species</option>
+      {%for aspecies in species%}
+      <option value="{{aspecies.SpeciesId}}">{{aspecies.MenuName}}</option>
+      {%endfor%}
+    </select>
+  </fieldset>
+
+  <fieldset>
     <legend>file type</legend>
 
     <input type="radio" name="filetype" value="average" id="filetype_average"
@@ -111,8 +124,8 @@
 <form method="POST" action="{{url_for('samples.select_species')}}">
   <legend class="heading">upload samples</legend>
   <fieldset>
-    <label for="select:species">Species</label>
-    <select id="select:species" name="species_id" required="required">
+    <label for="select_species02">Species</label>
+    <select id="select_species02" name="species_id" required="required">
       <option value="">Select species</option>
       {%for spec in species%}
       <option value="{{spec.SpeciesId}}">{{spec.MenuName}}</option>