diff options
Diffstat (limited to 'qc_app/upload/rqtl2.py')
-rw-r--r-- | qc_app/upload/rqtl2.py | 132 |
1 files changed, 93 insertions, 39 deletions
diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py index 6ddc83f..3411f98 100644 --- a/qc_app/upload/rqtl2.py +++ b/qc_app/upload/rqtl2.py @@ -25,7 +25,11 @@ from qc_app.db import ( populations_by_species, population_by_species_and_id,) from qc_app.db.datasets import ( - geno_dataset_by_id, geno_dataset_by_species_and_population) + geno_dataset_by_id, + geno_datasets_by_species_and_population, + + probeset_datasets_by_study, + probeset_studies_by_species_and_population) rqtl2 = Blueprint("rqtl2", __name__) @@ -199,44 +203,16 @@ def check_errors(conn, *args, **kwargs): pgsrc="error"), code=307) - return None - -@rqtl2.route(("/upload/species/<int:species_id>/population/<int:population_id>" - "/rqtl2-bundle/dataset-info"), - methods=["POST"]) -def select_dataset_info(species_id: int, population_id: int): - """ - If `geno` files exist in the R/qtl2 bundle, prompt user to provide the - dataset the genotypes belong to. - """ - form = request.form - with database_connection(app.config["SQL_URI"]) as conn: - error_page = check_errors(conn, "species", "population", "rqtl2_bundle_file") - if bool(error_page): - return error_page - - species = species_by_id(conn, species_id) - population = population_by_species_and_id( - conn, species_id, population_id) - 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-dataset-id")): - return render_template( - "rqtl2/select-geno-dataset.html", - species=species, - population=population, - rqtl2_bundle_file=thefile.name, - datasets=geno_dataset_by_species_and_population( - conn, species_id, population_id)) - - geno_dataset = geno_dataset_by_id( - conn, int(form["geno-dataset-id"])) + if ("probe-study-id" in args and + not bool(request.form.get("probe-study-id"))): + flash("No probeset study was selected!", "alert-error alert-rqtl2") + return redirect(url_for("upload.rqtl2.select_probeset_study", + species_id=species_id, + population_id=population_id, + pgsrc="error"), + code=307) - return render_template("rqtl2/summary-info.html", - species=species, - population=population, - geno_dataset=geno_dataset) + return None @rqtl2.route(("/upload/species/<int:species_id>/population/<int:population_id>" "/rqtl2-bundle/select-geno-dataset"), @@ -249,7 +225,7 @@ def select_geno_dataset(species_id: int, population_id: int): if bool(error): return error - geno_dset = geno_dataset_by_species_and_population( + geno_dset = geno_datasets_by_species_and_population( conn, species_id, population_id) if not bool(geno_dset): flash("No genotype dataset was provided!", @@ -321,3 +297,81 @@ def create_geno_dataset(species_id: int, population_id: int): conn, species_id, population_id), rqtl2_bundle_file=request.form["rqtl2_bundle_file"], geno_dataset={**new_dataset, "id": cursor.lastrowid}) + +@rqtl2.route(("/upload/species/<int:species_id>/population/<int:population_id>" + "/rqtl2-bundle/select-probeset-study"), + methods=["POST"]) +def select_probeset_study(species_id: int, population_id: int): + """Select or create a probeset study.""" + with database_connection(app.config["SQL_URI"]) as conn: + error = check_errors( + conn, "species", "population", "rqtl2_bundle_file", "geno-dataset", + "probe-study-id") + if bool(error): + return error + + summary_page = redirect(url_for("upload.rqtl2.select_dataset_info", + species=species_by_id(conn, species_id), + population=population_by_species_and_id( + conn, species_id, population_id)), + code=307) + if not bool(probe_study_by_id(conn, int(request.form["probe-study-id"]))): + flash("Invalid study selected!", "alert-error alert-rqtl2") + return summary_page + + return summary_page + +@rqtl2.route(("/upload/species/<int:species_id>/population/<int:population_id>" + "/rqtl2-bundle/dataset-info"), + methods=["POST"]) +def select_dataset_info(species_id: int, population_id: int): + """ + If `geno` files exist in the R/qtl2 bundle, prompt user to provide the + dataset the genotypes belong to. + """ + form = request.form + with database_connection(app.config["SQL_URI"]) as conn: + error_page = check_errors(conn, "species", "population", "rqtl2_bundle_file") + if bool(error_page): + return error_page + + species = species_by_id(conn, species_id) + population = population_by_species_and_id( + conn, species_id, population_id) + 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-dataset-id")): + return render_template( + "rqtl2/select-geno-dataset.html", + species=species, + population=population, + 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")): + return render_template( + "rqtl2/select-probeset-study-id.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)) + + if "pheno" in cdata and not bool(form.get("probe-dataset-id")): + return render_template( + "rqtl2/select-probeset-dataset.html", + species=species, + population=population, + rqtl2_bundle_file=thefile.name, + geno_dataset=geno_dataset, + datasets=probeset_datasets_by_study( + conn, int(form["probe-study-id"]))) + + return render_template("rqtl2/summary-info.html", + species=species, + population=population, + geno_dataset=geno_dataset) |