From 4e3f6e51b92d9c56f77452bd4b723323a526bc52 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 17 Jan 2024 05:02:34 +0300 Subject: Enable selecting from existing genotype datasets. --- qc_app/upload/rqtl2.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'qc_app/upload') diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py index 146c301..7db005c 100644 --- a/qc_app/upload/rqtl2.py +++ b/qc_app/upload/rqtl2.py @@ -189,6 +189,15 @@ def check_errors(conn, *args, **kwargs) -> Optional[Response]: pgsrc="error"), code=307) + if ("geno-dataset" in args and + not bool(request.form.get("geno-dataset-id"))): + flash("No genotype dataset was provided!", "alert-error alert-rqtl2") + return redirect(url_for("upload.rqtl2.select_geno_dataset", + species_id=species_id, + population_id=population_id, + pgsrc="error"), + code=307) + return False @rqtl2.route(("/upload/species//population/" @@ -208,7 +217,7 @@ def select_dataset_info(species_id: int, population_id: int): thefile = fullpath(form["rqtl2_bundle_file"]) with ZipFile(str(thefile), "r") as zfile: cdata = r_qtl2.control_data(zfile) - if "geno" in cdata and not bool(form.get("geno_datasetid")): + if "geno" in cdata and not bool(form.get("geno-dataset-id")): return render_template( "rqtl2/select-geno-dataset.html", species=species_by_id(conn, species_id), @@ -225,7 +234,29 @@ def select_dataset_info(species_id: int, population_id: int): methods=["POST"]) def select_geno_dataset(species_id: int, population_id: int) -> Response: """Select from existing geno datasets.""" - return "IMPLEMENT THIS!!!" + with database_connection(app.config["SQL_URI"]) as conn: + error = check_errors( + conn, "species", "population", "rqtl2_bundle_file", "geno-dataset") + if bool(error): + return error + + geno_dset = geno_dataset_by_species_and_population( + conn, species_id, population_id) + if not bool(geno_dset): + flash("No genotype dataset was provided!", + "alert-error alert-rqtl2") + return redirect(url_for("upload.rqtl2.select_geno_dataset", + species_id=species_id, + population_id=population_id, + pgsrc="error"), + code=307) + + flash("Genotype accepted", "alert-success alert-rqtl2") + return redirect(url_for("upload.rqtl2.select_dataset_info", + species_id=species_id, + population_id=population_id, + pgsrc="upload.rqtl2.select_geno_dataset"), + code=307) @rqtl2.route(("/upload/species//population/" "/rqtl2-bundle/create-geno-dataset"), -- cgit v1.2.3