aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorBonfaceKilz2021-02-24 10:36:04 +0300
committerBonfaceKilz2021-02-24 14:20:29 +0300
commit2125450ffaf93e9500dc6360ecce8d6c7e8e4036 (patch)
treeaefa3fbe569714ae6cf5b9be636b4ae82f07060c /gn3
parent0a91d8eee64a47062f03c3e04a015cf3ae96a782 (diff)
downloadgenenetwork3-2125450ffaf93e9500dc6360ecce8d6c7e8e4036.tar.gz
Create a new helper function for generating k_values and GWA
Diffstat (limited to 'gn3')
-rw-r--r--gn3/computations/gemma.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/gn3/computations/gemma.py b/gn3/computations/gemma.py
index ae04c40..5741692 100644
--- a/gn3/computations/gemma.py
+++ b/gn3/computations/gemma.py
@@ -5,8 +5,11 @@ import string
from base64 import b64encode
from hashlib import md5
+from typing import Dict
from typing import List
+from typing import Optional
from typing import ValuesView
+from gn3.commands import compose_gemma_cmd
def generate_random_n_string(n_length: int) -> str:
"""Generate a random string that is N chars long"""
@@ -50,3 +53,26 @@ def do_paths_exist(paths: ValuesView) -> bool:
if not os.path.isfile(path):
return False
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"""
+ geno_filename = gemma_kwargs.get("geno_filename", "")
+ trait_filename = gemma_kwargs.get("trait_filename")
+ ext, snps_filename = geno_filename.partition(".")[-1], ""
+ if geno_filename:
+ 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")
+ 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_kwargs=_kwargs,
+ gemma_args=["-gk", ">",
+ output_file])