From 8e4e15ae62989f07d3ca8512165ba2a93c42aa94 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 12 Apr 2024 09:17:49 +0300 Subject: Consistently check for possibly non-existent data The "geno-dataset", "tissue", "pheno-study" and "pheno-dataset" data "objects" might not exist for a particular uploaded bundle, so we check in a consistent manner to ensure they are provided when needed. --- qc_app/upload/rqtl2.py | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'qc_app/upload') diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py index bf392a9..8c80ef3 100644 --- a/qc_app/upload/rqtl2.py +++ b/qc_app/upload/rqtl2.py @@ -525,7 +525,7 @@ def create_geno_dataset(species_id: int, population_id: int): return with_errors(__thunk__, partial(check_species, conn=conn), - partial(check_population, conn=conn), + partial(check_population, conn=conn, species_id=species_id), partial(check_r_qtl2_bundle, species_id=species_id, population_id=population_id)) @@ -765,6 +765,8 @@ def create_probeset_dataset(species_id: int, population_id: int):#pylint: disabl flash("Dataset full name not provided!", errorclasses) return summary_page + tissue = tissue_by_id(conn, form.get("tissueid", "").strip()) + study = probeset_study_by_id(conn, int(form["probe-study-id"])) if not bool(study): flash("Invalid ProbeSet study provided!", errorclasses) @@ -806,6 +808,7 @@ def create_probeset_dataset(species_id: int, population_id: int):#pylint: disabl geno_dataset=geno_dataset_by_id( conn, int(request.form["geno-dataset-id"])), + tissue=tissue, study=study, avgmethod=avgmethod, dataset=dset) @@ -846,6 +849,9 @@ 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) + + geno_dataset = geno_dataset_by_id( + conn,form.get("geno-dataset-id", "").strip()) if "geno" in cdata and not bool(form.get("geno-dataset-id")): return render_template( "rqtl2/select-geno-dataset.html", @@ -854,21 +860,6 @@ def select_dataset_info(species_id: int, population_id: int): rqtl2_bundle_file=thefile.name, datasets=geno_datasets_by_species_and_population( conn, species_id, population_id)) - geno_dataset = geno_dataset_by_id(conn, int(form["geno-dataset-id"])) - - if "pheno" in cdata and not bool(form.get("probe-study-id")): - tissue = tissue_by_id(conn, form.get("tissueid", "").strip()) - if not bool(tissue): - return render_template( - "rqtl2/select-tissue.html", - species=species, - population=population, - rqtl2_bundle_file=thefile.name, - geno_dataset=geno_dataset, - studies=probeset_studies_by_species_and_population( - conn, species_id, population_id), - platforms=platforms_by_species(conn, species_id), - tissues=all_tissues(conn)) tissue = tissue_by_id(conn, form.get("tissueid", "").strip()) if "pheno" in cdata and not bool(tissue): @@ -883,6 +874,9 @@ def select_dataset_info(species_id: int, population_id: int): platforms=platforms_by_species(conn, species_id), tissues=all_tissues(conn)) + probeset_study = probeset_study_by_id( + conn, form.get("probe-study-id", "").strip()) + if "pheno" in cdata and not bool(probeset_study): return render_template( "rqtl2/select-probeset-study-id.html", species=species, @@ -896,7 +890,9 @@ def select_dataset_info(species_id: int, population_id: int): probeset_study = probeset_study_by_id( conn, int(form["probe-study-id"])) - if "pheno" in cdata and not bool(form.get("probe-dataset-id")): + probeset_dataset = probeset_dataset_by_id( + conn, form.get("probe-dataset-id", "").strip()) + if "pheno" in cdata and not bool(probeset_dataset): return render_template( "rqtl2/select-probeset-dataset.html", species=species, @@ -908,16 +904,13 @@ def select_dataset_info(species_id: int, population_id: int): datasets=probeset_datasets_by_study( conn, int(form["probe-study-id"])), avgmethods=averaging_methods(conn)) - probeset_study = probeset_study_by_id( - conn, int(form["probe-study-id"])) - probeset_dataset = probeset_dataset_by_id( - conn, int(form["probe-dataset-id"])) return render_template("rqtl2/summary-info.html", species=species, population=population, rqtl2_bundle_file=thefile.name, geno_dataset=geno_dataset, + tissue=tissue, probe_study=probeset_study, probe_dataset=probeset_dataset) -- cgit v1.2.3