From 52e3569cca6b24d1318034f5ab004795e70135f5 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Mon, 1 Mar 2021 11:47:21 +0300 Subject: Fix failing tests --- gn3/api/gemma.py | 19 ++++++++++++------- gn3/computations/gemma.py | 14 ++++++++------ 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'gn3') diff --git a/gn3/api/gemma.py b/gn3/api/gemma.py index effae8a..7c76f2f 100644 --- a/gn3/api/gemma.py +++ b/gn3/api/gemma.py @@ -35,10 +35,12 @@ file output is returned. """ data = request.get_json() app_defaults = current_app.config.get('APP_DEFAULTS') - __hash = generate_hash_of_string("".join(data.get("values"))) + __hash = generate_hash_of_string( + f"{data.get('genofile_name')}_" + ''.join(data.get("values", ""))) gemma_kwargs = { "geno_filename": os.path.join(app_defaults.get("GENODIR"), "bimbam", - f"{data.get('genofile_name')}.txt"), + f"{data.get('geno_filename')}"), "trait_filename": generate_pheno_txt_file( tmpdir=app_defaults.get("TMPDIR"), values=data.get("values"), @@ -46,18 +48,21 @@ file output is returned. trait_filename=(f"{data.get('dataset_groupname')}_" f"{data.get('trait_name')}_" f"{__hash}.txt"))} + gemma_wrapper_kwargs = {} + if data.get("loco"): + gemma_wrapper_kwargs["loco"] = f"--input {data.get('loco')}" k_computation_cmd = generate_gemma_computation_cmd( - gemma_cmd=app_defaults.get("GEMMA_WRAPPER_CMD"), + gemma_cmd=app_defaults.get("GEMMA_WRAPPER_CMD") + "_haha", + gemma_wrapper_kwargs={"loco": f"--input {data.get('loco')}"}, gemma_kwargs=gemma_kwargs, output_file=(f"{app_defaults.get('TMPDIR')}/gn2/" f"{data.get('dataset_name')}_K_" f"{__hash}.json")) - if data.get("covariates"): - gemma_kwargs["c"] = os.path.join(app_defaults.get("GENODIR"), - "bimbam", - data.get("covariates")) gemma_kwargs["lmm"] = data.get("lmm", 9) + gemma_wrapper_kwargs["input"] = (f"{data.get('dataset_name')}_K_" + f"{__hash}.json") gwa_cmd = generate_gemma_computation_cmd( + gemma_wrapper_kwargs=gemma_wrapper_kwargs, gemma_cmd=app_defaults.get("GEMMA_WRAPPER_CMD"), gemma_kwargs=gemma_kwargs, output_file=(f"{data.get('dataset_name')}_GWA_" diff --git a/gn3/computations/gemma.py b/gn3/computations/gemma.py index 5741692..528f888 100644 --- a/gn3/computations/gemma.py +++ b/gn3/computations/gemma.py @@ -55,10 +55,12 @@ def do_paths_exist(paths: ValuesView) -> bool: return True -def generate_gemma_computation_cmd(gemma_cmd: str, - gemma_kwargs: Dict[str, str], - output_file: str) -> Optional[str]: - """Create a higher order function that generates a command""" +def generate_gemma_computation_cmd( + gemma_cmd: str, + gemma_kwargs: Dict[str, str], + output_file: str, + gemma_wrapper_kwargs: Dict[str, str]) -> Optional[str]: + """Create a computation cmd""" geno_filename = gemma_kwargs.get("geno_filename", "") trait_filename = gemma_kwargs.get("trait_filename") ext, snps_filename = geno_filename.partition(".")[-1], "" @@ -66,13 +68,13 @@ def generate_gemma_computation_cmd(gemma_cmd: str, snps_filename = geno_filename.replace(f".{ext}", "") snps_filename += f"_snps.{ext}" _kwargs = {"g": geno_filename, "p": trait_filename} - if gemma_kwargs.get("covar_filename"): - _kwargs["a"] = gemma_kwargs.get("covar_filename") + _kwargs["a"] = snps_filename if not do_paths_exist(_kwargs.values()): # Prevents injection! return None if _kwargs.get("lmm"): _kwargs["lmm"] = gemma_kwargs.get("lmm") return compose_gemma_cmd(gemma_wrapper_cmd=gemma_cmd, + gemma_wrapper_kwargs=gemma_wrapper_kwargs, gemma_kwargs=_kwargs, gemma_args=["-gk", ">", output_file]) -- cgit v1.2.3