From cdd4dc456e56bb4eb055e1cb7f2518d45fb3bfb9 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Sat, 20 Jan 2024 09:57:23 +0300 Subject: 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 --- qc_app/entry.py | 7 ++++--- qc_app/jobs.py | 19 +++++++++++++------ qc_app/parse.py | 25 +++++++++++++++++++++++-- qc_app/static/js/upload_progress.js | 3 +++ qc_app/templates/index.html | 17 +++++++++++++++-- 5 files changed, 58 insertions(+), 13 deletions(-) (limited to 'qc_app') 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 @@ -65,6 +65,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]); 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%} @@ -54,6 +55,18 @@ {%endif%} {%endwith%} +
+ + +
+
file type @@ -111,8 +124,8 @@
upload samples
- - {%for spec in species%} -- cgit v1.2.3