diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index 7002ccd..15d2b6c 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -1066,12 +1066,86 @@ def recompute_means(# pylint: disable=[unused-argument]
job_id=_job["job_id"]))
-def recompute_phenotype_means_success_handler(job):
- """Handle loading new phenotypes into the database successfully."""
- flash("Means computed successfully!", "alert alert-success")
+def return_to_dataset_view_handler(job, msg: str):
+ flash(msg, "alert alert-success")
return redirect(url_for(
"species.populations.phenotypes.view_dataset",
species_id=job["metadata"]["species_id"],
population_id=job["metadata"]["population_id"],
dataset_id=job["metadata"]["dataset_id"],
job_id=job["job_id"]))
+
+def recompute_phenotype_means_success_handler(job):
+ """Handle loading new phenotypes into the database successfully."""
+ return return_to_dataset_view_handler(job, "Means computed successfully!")
+
+
+@phenotypesbp.route(
+ "<int:species_id>/populations/<int:population_id>/phenotypes/datasets"
+ "/<int:dataset_id>/rerun-qtlreaper",
+ methods=["POST"])
+@require_login
+@with_dataset(
+ species_redirect_uri="species.populations.phenotypes.index",
+ population_redirect_uri="species.populations.phenotypes.select_population",
+ redirect_uri="species.populations.phenotypes.list_datasets")
+def rerun_qtlreaper(# pylint: disable=[unused-argument]
+ species: dict,
+ population: dict,
+ dataset: dict,
+ **kwargs
+):
+ """(Re)run QTLReaper for phenotypes in a particular population."""
+ _jobs_db = app.config["ASYNCHRONOUS_JOBS_SQLITE_DB"]
+ _job_id = uuid.uuid4()
+ _loglevel = logging.getLevelName(app.logger.getEffectiveLevel()).lower()
+
+ _workingdir = Path(app.config["TEMPORARY_DIRECTORY"]).joinpath("qtlreaper")
+ _workingdir.mkdir(exist_ok=True)
+ command = [
+ sys.executable,
+ "-u",
+ "-m",
+ "scripts.run_qtlreaper",
+ "--log-level", _loglevel,
+ app.config["SQL_URI"],
+ str(species["SpeciesId"]),
+ str(population["Id"]),
+ str(Path(app.config["GENOTYPE_FILES_DIRECTORY"]).joinpath(
+ "genotype")),
+ str(_workingdir)
+ ] + [
+ str(_xref_id) for _xref_id in (
+ int(item.split("_")[-1])
+ for item in request.form.getlist("selected-phenotypes"))
+ ]
+ logger.debug("(Re)run QTLReaper: %s", command)
+ with sqlite3.connection(_jobs_db) as conn:
+ _job_id = uuid.uuid4()
+ _job = gnlibs_jobs.launch_job(
+ gnlibs_jobs.initialise_job(
+ conn,
+ _job_id,
+ command,
+ "(re)run-qtlreaper",
+ extra_meta={
+ "species_id": species["SpeciesId"],
+ "population_id": population["Id"],
+ "dataset_id": dataset["Id"],
+ "success_handler": (
+ "uploader.phenotypes.views."
+ "rerun_qtlreaper_success_handler")
+ }),
+ _jobs_db,
+ Path(f"{app.config['UPLOAD_FOLDER']}/job_errors"),
+ worker_manager="gn_libs.jobs.launcher",
+ loglevel=_loglevel)
+ return redirect(url_for("background-jobs.job_status",
+ job_id=_job["job_id"]))
+ return redirect(url_for(
+ "background-jobs.job_status", job_id=_job["job_id"]))
+
+
+def rerun_qtlreaper_success_handler(job):
+ """Handle success (re)running QTLReaper script."""
+ return return_to_dataset_view_handler(job, "QTLReaper ran successfully!")
|