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/parse.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'qc_app/parse.py') 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") -- cgit v1.2.3