diff options
| author | Alexander_Kabui | 2025-02-05 12:27:53 +0300 |
|---|---|---|
| committer | BonfaceKilz | 2025-02-06 12:43:15 +0300 |
| commit | 2177766bd1b48257caa3adb8fa4250f6eabb0e4f (patch) | |
| tree | ebbf56b307f37497fa5c8637ec8bc26ca77ed7f3 | |
| parent | 82e1c0441ce702ae8881a9a5c6f386cdeeae19c1 (diff) | |
| download | genenetwork3-2177766bd1b48257caa3adb8fa4250f6eabb0e4f.tar.gz | |
refactor: code refactoring.
| -rw-r--r-- | gn3/api/rqtl2.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/gn3/api/rqtl2.py b/gn3/api/rqtl2.py index b584b12..5b27f3c 100644 --- a/gn3/api/rqtl2.py +++ b/gn3/api/rqtl2.py @@ -5,11 +5,12 @@ from flask import current_app from flask import jsonify from flask import Blueprint from flask import request -from gn3.computations.rqtl2 import compose_rqtl2_cmd -from gn3.computations.rqtl2 import prepare_files -from gn3.computations.rqtl2 import validate_required_keys -from gn3.computations.rqtl2 import write_input_file -from gn3.computations.rqtl2 import process_qtl2_results +from gn3.computations.rqtl2 import (compose_rqtl2_cmd, + prepare_files, + validate_required_keys, + write_input_file, + process_qtl2_results + ) from gn3.computations.streaming import run_process rqtl2 = Blueprint("rqtl2", __name__) @@ -21,18 +22,18 @@ def compute(): required_keys = ["crosstype", "geno_data","pheno_data", "geno_codes"] valid, error = validate_required_keys(required_keys,data) if not valid: - return jsonify({"Error" : error}), 400 + return jsonify(error=error), 400 # Provide atleast one of this data entries. if "physical_map_data" not in data and "geno_map_data" not in data: - return jsonify({ "Error":"You need to Provide\ - Either the Physical map or Geno Map data of markers"}), 400 + return jsonify(error="You need to Provide\ + Either the Physical map or Geno Map data of markers"), 400 run_id = request.args.get("id", "output") # prepare necessary files and dir for computation (workspace_dir, input_file, output_file, log_file) = prepare_files(current_app.config.get("TMPDIR")) # write the input file with data required for creating the cross write_input_file(input_file, workspace_dir, data) - # TODO fix this + # TODO : Implement a better way for fetching the file Path. rqtl_path =Path(__file__).absolute().parent.parent.parent.joinpath("scripts/rqtl2_wrapper.R") if not rqtl_path.is_file(): return jsonify({"error" : f"The script {rqtl_path} does not exists"}), 400 @@ -41,6 +42,7 @@ def compute(): data, current_app.config) process_output = run_process(rqtl2_cmd.split(),log_file, run_id) if process_output["code"] != 0: + # Err out for any non-zero status code return jsonify(process_output), 400 results = process_qtl2_results(output_file) shutil.rmtree(workspace_dir, ignore_errors=True, onerror=None) |
