about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-12-03 12:50:51 -0600
committerFrederick Muriuki Muriithi2025-12-03 12:50:51 -0600
commit9514647b70fe90a709b2881e50871a6e15f1236e (patch)
tree49543c1dedec800a65ff9cdb5eb1006edab3778c
parent9f550ba0d5e33995b9969caa0abcd1f6707e68cb (diff)
downloadgn-uploader-9514647b70fe90a709b2881e50871a6e15f1236e.tar.gz
Rerun QTLReaper script with provided details. HEAD main
-rw-r--r--uploader/phenotypes/views.py80
1 files changed, 77 insertions, 3 deletions
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!")