diff options
| author | Alexander_Kabui | 2024-11-22 12:16:08 +0300 |
|---|---|---|
| committer | Alexander_Kabui | 2024-11-22 12:16:08 +0300 |
| commit | 656014370380951577900f31e66e9a92c995b0bd (patch) | |
| tree | 973b63598967bcd0ea16a2d4b9f881726314aeab /gn3/api/rqtl2.py | |
| parent | e1641eb4bc9e0e069b08ee2948aea2d88fc83b32 (diff) | |
| download | genenetwork3-656014370380951577900f31e66e9a92c995b0bd.tar.gz | |
feat: implement ednpoint for computing qtl using rqtl2.
Capture stdout results to a file.
Diffstat (limited to 'gn3/api/rqtl2.py')
| -rw-r--r-- | gn3/api/rqtl2.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/gn3/api/rqtl2.py b/gn3/api/rqtl2.py new file mode 100644 index 0000000..e746918 --- /dev/null +++ b/gn3/api/rqtl2.py @@ -0,0 +1,38 @@ +""" File contains endpoints for rqlt2""" + +import subprocess +import uuid +import os +from flask import current_app +from flask import jsonify +from flask import Blueprint + +rqtl2 = Blueprint("rqtl2", __name__) + +@rqtl2.route("/compute", methods=["GET"]) +def compute(): + """Endpoint for computing QTL analysis using R/QTL2""" + wkdir = current_app.config.get("TMPDIR") + output_file = os.path.join(wkdir, "output.txt") + rscript_cmd = ( + f"Rscript ./scripts/rqtl2_wrapper.R " + f"-i /home/kabui/r_playground/meta_grav.json " + f"-d /home/kabui/r_playground " + f"-o /home/kabui/r_playground/rqtl_output.json " + f"--nperm 100 --threshold 1 --cores 0" + ) + process = subprocess.Popen( + rscript_cmd, shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + # TODO rethink where we write this file + with open(output_file, "a+") as file_handler: + for line in iter(process.stdout.readline, b""): + file_handler.write(line.decode("utf-8")) + process.stdout.close() + process.wait() + if process.returncode == 0: + return jsonify({"msg": "success", "results": "file_here"}) + else: + return jsonify({"msg": "fail", "error": "Process failed"}) |
