aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorBonfaceKilz2021-03-04 12:56:00 +0300
committerBonfaceKilz2021-03-08 21:09:58 +0300
commit13b66fddd5c905e1a7b320051cedeb9ea234e1c3 (patch)
tree7a40485746b6b2d5d21eb47c3735dc6a1d560a50 /gn3
parent62fca4bd4dc433230ce0ad8c2a2c785c3ea5b5b3 (diff)
downloadgenenetwork3-13b66fddd5c905e1a7b320051cedeb9ea234e1c3.tar.gz
Add new endpoint: "/gwa-compute/<k_filename>/<token>"
Diffstat (limited to 'gn3')
-rw-r--r--gn3/api/gemma.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/gn3/api/gemma.py b/gn3/api/gemma.py
index e5a1a72..709643d 100644
--- a/gn3/api/gemma.py
+++ b/gn3/api/gemma.py
@@ -171,3 +171,43 @@ values.
return jsonify(status=128,
# use better message
message="Metadata file non-existent!")
+
+
+@gemma.route("/gwa-compute/<k_filename>/<token>", methods=["POST"])
+def compute_gwa(k_filename, token):
+ """Compute GWA values. No loco no covariates provided.
+
+ """
+ working_dir = os.path.join(current_app.config.get("TMPDIR"),
+ token)
+ _dict = jsonfile_to_dict(os.path.join(working_dir,
+ "metadata.json"))
+ try:
+ genofile, phenofile, snpsfile = [
+ os.path.join(working_dir,
+ _dict.get(x))
+ for x in ["geno", "pheno", "snps"]]
+ gemma_kwargs = {"g": genofile, "p": phenofile,
+ "a": snpsfile, "lmm": _dict.get("lmm", 9)}
+ _hash = get_hash_of_files([genofile, phenofile, snpsfile])
+ _output_filename = f"{_hash}-gwa-output.json"
+ return jsonify(
+ unique_id=queue_cmd(
+ conn=redis.Redis(),
+ email=(request.get_json() or {}).get('email'),
+ job_queue=current_app.config.get("REDIS_JOB_QUEUE"),
+ cmd=generate_gemma_computation_cmd(
+ gemma_cmd=current_app.config.get("GEMMA_WRAPPER_CMD"),
+ gemma_wrapper_kwargs={
+ "input": os.path.join(working_dir, k_filename)
+ },
+ gemma_kwargs=gemma_kwargs,
+ output_file=(f"{current_app.config.get('TMPDIR')}/"
+ f"{token}/{_output_filename}"))),
+ status="queued",
+ output_file=_output_filename)
+ # pylint: disable=W0703
+ except Exception:
+ return jsonify(status=128,
+ # use better message
+ message="Metadata file non-existent!")