aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations/gemma.py
diff options
context:
space:
mode:
authorBonfaceKilz2021-03-05 12:06:54 +0300
committerBonfaceKilz2021-03-08 21:09:58 +0300
commit8752937bc1e3cea84eefd3e363b429157f25acb5 (patch)
tree57ce328b6f0ac10adbb90f09e72962343fb83d49 /gn3/computations/gemma.py
parent5c56425d51ab6a6b4ffd6ec8f86121bd91ff5e63 (diff)
downloadgenenetwork3-8752937bc1e3cea84eefd3e363b429157f25acb5.tar.gz
Add generic fn for computing k and gwa values
Diffstat (limited to 'gn3/computations/gemma.py')
-rw-r--r--gn3/computations/gemma.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/gn3/computations/gemma.py b/gn3/computations/gemma.py
index 7b5f91d..3c6bd29 100644
--- a/gn3/computations/gemma.py
+++ b/gn3/computations/gemma.py
@@ -8,6 +8,7 @@ from typing import List
from typing import Optional
from typing import ValuesView
from gn3.commands import compose_gemma_cmd
+from gn3.file_utils import get_hash_of_files
def generate_hash_of_string(unhashed_str: str) -> str:
@@ -68,3 +69,32 @@ def generate_gemma_computation_cmd(
gemma_wrapper_kwargs=gemma_wrapper_kwargs,
gemma_kwargs=_kwargs,
gemma_args=["-gk", ">", output_file])
+
+
+# pylint: disable=R0913
+def generate_gemma_cmd(gemma_cmd: str,
+ output_dir: str,
+ token: str,
+ gemma_kwargs: Dict,
+ gemma_wrapper_kwargs: Dict = None,
+ chromosomes: str = None) -> Dict:
+ """Compute k values"""
+ _hash = get_hash_of_files(
+ [v for k, v in gemma_kwargs.items() if k in ["g", "p", "a", "c"]])
+ if chromosomes: # Only reached when calculating k-values
+ gemma_wrapper_kwargs = {"loco": f"--input {chromosomes}"}
+ _hash += f"-{generate_hash_of_string(chromosomes)[:6]}"
+ _output_filename = f"{_hash}-output.json"
+ return {
+ "output_file":
+ _output_filename,
+ "gemma_cmd":
+ compose_gemma_cmd(gemma_wrapper_cmd=gemma_cmd,
+ gemma_wrapper_kwargs=gemma_wrapper_kwargs,
+ gemma_kwargs=gemma_kwargs,
+ gemma_args=[
+ "-gk", ">",
+ (f"{output_dir}/"
+ f"{token}/{_output_filename}")
+ ])
+ }