diff options
Diffstat (limited to 'qc_app/upload')
-rw-r--r-- | qc_app/upload/rqtl2.py | 75 |
1 files changed, 62 insertions, 13 deletions
diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py index 3411f98..0d80776 100644 --- a/qc_app/upload/rqtl2.py +++ b/qc_app/upload/rqtl2.py @@ -19,6 +19,9 @@ from r_qtl.errors import InvalidFormat from qc_app.files import save_file, fullpath from qc_app.dbinsert import species as all_species from qc_app.db_utils import with_db_connection, database_connection + +from qc_app.db.tissues import all_tissues, tissue_by_id +from qc_app.db.platforms import platform_by_id, platforms_by_species from qc_app.db import ( species_by_id, save_population, @@ -28,6 +31,8 @@ from qc_app.db.datasets import ( geno_dataset_by_id, geno_datasets_by_species_and_population, + probeset_study_by_id, + probeset_create_study, probeset_datasets_by_study, probeset_studies_by_species_and_population) @@ -311,17 +316,59 @@ def select_probeset_study(species_id: int, population_id: int): 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)), + species_id=species_id, + population_id=population_id), code=307) - if not bool(probe_study_by_id(conn, int(request.form["probe-study-id"]))): + if not bool(probeset_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/create-probeset-study"), + methods=["POST"]) +def create_probeset_study(species_id: int, population_id: int): + """Create a new probeset study.""" + 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 + + form = request.form + select_study_page = redirect( + url_for("upload.rqtl2.select_probeset_study", + species_id=species_id, + population_id=population_id), + code=307) + + if not (bool(form.get("platformid")) and + bool(platform_by_id(conn, int(form["platformid"])))): + flash("Invalid platform selected.", "alert-error alert-rqtl2") + return select_study_page + + if not (bool(form.get("tissueid")) and + bool(tissue_by_id(conn, int(form["tissueid"])))): + flash("Invalid tissue selected.", "alert-error alert-rqtl2") + return select_study_page + + study = probeset_create_study( + conn, population_id, int(form["platformid"]), int(form["tissueid"]), + form["studyname"], form.get("studyfullname") or "", + form.get("studyshortname") or "") + return render_template( + "rqtl2/create-probe-study-success.html", + species=species_by_id(conn, species_id), + population=population_by_species_and_id( + conn, species_id, population_id), + rqtl2_bundle_file=request.form["rqtl2_bundle_file"], + geno_dataset=geno_dataset_by_id( + conn, + int(request.form["geno-dataset-id"])), + study=study) + +@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): @@ -359,17 +406,19 @@ def select_dataset_info(species_id: int, population_id: int): rqtl2_bundle_file=thefile.name, geno_dataset=geno_dataset, studies=probeset_studies_by_species_and_population( - conn, species_id, population_id)) + conn, species_id, population_id), + platforms=platforms_by_species(conn, species_id), + tissues=all_tissues(conn)) 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/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, |