diff options
Diffstat (limited to 'gn3')
| -rw-r--r-- | gn3/api/rqtl.py | 33 |
1 files changed, 1 insertions, 32 deletions
diff --git a/gn3/api/rqtl.py b/gn3/api/rqtl.py index 81bc5e4..f700afd 100644 --- a/gn3/api/rqtl.py +++ b/gn3/api/rqtl.py @@ -16,6 +16,7 @@ from gn3.computations.rqtl import ( process_rqtl_pairscan, process_perm_output, ) +from gn3.computations.streaming import run_process from gn3.fs_helpers import assert_path_exists, get_tmpdir rqtl = Blueprint("rqtl", __name__) @@ -102,35 +103,3 @@ def compute(): rqtl_output["significant"], ) = process_perm_output(rqtl_cmd.get("output_file")) return jsonify(rqtl_output) - - -def run_process(cmd, output_file, run_id): - """Function to execute an external process and - capture the stdout in a file - input: - cmd: the command to execute as a list of args. - output_file: abs file path to write the stdout. - run_id: unique id to identify the process - - output: - Dict with the results o either success or failure. - """ - try: - # phase: execute the rscript cmd - with subprocess.Popen( - cmd, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - ) as process: - for line in iter(process.stdout.readline, b""): - # phase: capture the stdout for eaching line allowing read and write - with open(output_file, "a+", encoding="utf-8") as file_handler: - file_handler.write(line.decode("utf-8")) - process.wait() - if process.returncode == 0: - return {"msg": "success", "code": 0, "run_id": run_id} - return {"msg": "error occurred", "error": "Process failed", - "code": process.returncode, "run_id": run_id} - except subprocess.CalledProcessError as error: - return {"msg": "error occurred", - "error": str(error), "run_id": run_id} |
