diff options
author | BonfaceKilz | 2021-03-08 10:52:44 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-03-08 21:09:58 +0300 |
commit | 79f931b0fbe0712954201a15278f9088fd7cdb8a (patch) | |
tree | 170c7aedb13e32ea6b29aa78dbe23eb537aa007c /gn3/api | |
parent | 13428f9d9496dc2af44065f03fc7fc747a5a0ea9 (diff) | |
download | genenetwork3-79f931b0fbe0712954201a15278f9088fd7cdb8a.tar.gz |
Add "/gemma/k-gwa-compute/<token>"
Diffstat (limited to 'gn3/api')
-rw-r--r-- | gn3/api/gemma.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/gn3/api/gemma.py b/gn3/api/gemma.py index a69b73e..2d1fedf 100644 --- a/gn3/api/gemma.py +++ b/gn3/api/gemma.py @@ -349,3 +349,73 @@ def compute_gwa_with_loco_covar(k_filename, maf, token): status=128, # use better message message="Metadata file non-existent!") + + +@gemma.route("/k-gwa-compute/<token>", methods=["POST"]) +def compute_k_gwa(token): + """Given a genofile, traitfile, snpsfile, and the token, compute the k-values +and return <hash-of-inputs>.json with a UNIQUE-ID of the job. The genofile, +traitfile, and snpsfile are extracted from a metadata.json file. No Loco no +covars; lmm defaults to 9! + + """ + 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"] + ] + if not do_paths_exist([genofile, phenofile, snpsfile]): + raise FileNotFoundError + gemma_kwargs = {"g": genofile, "p": phenofile, "a": snpsfile} + gemma_k_cmd = generate_gemma_cmd( + gemma_cmd=current_app.config.get("GEMMA_" + "WRAPPER_CMD"), + output_dir=current_app.config.get('TMPDIR'), + token=token, + gemma_kwargs=gemma_kwargs) + gemma_kwargs["lmm"] = _dict.get("lmm", 9) + gemma_gwa_cmd = generate_gemma_cmd( + gemma_cmd=current_app.config.get("GEMMA_" + "WRAPPER_CMD"), + output_dir=current_app.config.get('TMPDIR'), + token=token, + gemma_kwargs=gemma_kwargs, + gemma_wrapper_kwargs={ + "input": os.path.join(working_dir, + gemma_k_cmd.get("output_file")) + }) + 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=(f"{gemma_k_cmd.get('gemma_cmd')} && " + f"{gemma_gwa_cmd.get('gemma_cmd')}")), + status="queued", + output_file=gemma_gwa_cmd.get("output_file")) + # pylint: disable=W0703 + except Exception: + return jsonify( + status=128, + # use better message + message="Metadata file non-existent!") + gemma_cmd=current_app.config.get("GEMMA_" + "WRAPPER_CMD"), + output_dir=current_app.config.get('TMPDIR'), + token=token, + gemma_kwargs=gemma_kwargs) + 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=(f"{gemma_k_cmd.get('gemma_cmd')} && " + f"{gemma_gwa_cmd.get('gemma_cmd')}")), + status="queued", + output_file=gemma_gwa_cmd.get("output_file")) + # pylint: disable=W0703 + except Exception: + return jsonify( + status=128, + # use better message + message="Metadata file non-existent!") |