aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/api/gemma.py402
-rw-r--r--gn3/computations/gemma.py7
-rw-r--r--tests/integration/test_gemma.py133
-rw-r--r--tests/unit/computations/test_gemma.py20
4 files changed, 294 insertions, 268 deletions
diff --git a/gn3/api/gemma.py b/gn3/api/gemma.py
index a341f62..d82f5a5 100644
--- a/gn3/api/gemma.py
+++ b/gn3/api/gemma.py
@@ -24,8 +24,7 @@ gemma = Blueprint("gemma", __name__)
def get_version():
"""Display the installed version of gemma-wrapper"""
gemma_cmd = current_app.config["GEMMA_WRAPPER_CMD"]
- return jsonify(
- run_cmd(f"{gemma_cmd} -v | head -n 1"))
+ return jsonify(run_cmd(f"{gemma_cmd} -v | head -n 1"))
# This is basically extracted from genenetwork2
@@ -39,19 +38,21 @@ file output is returned.
"""
data = request.get_json()
app_defaults = current_app.config
- __hash = generate_hash_of_string(
- f"{data.get('genofile_name')}_"
- ''.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('geno_filename')}"),
- "trait_filename": generate_pheno_txt_file(
+ "geno_filename":
+ os.path.join(app_defaults.get("GENODIR"), "bimbam",
+ f"{data.get('geno_filename')}"),
+ "trait_filename":
+ generate_pheno_txt_file(
tmpdir=app_defaults.get("TMPDIR"),
values=data.get("values"),
# Generate this file on the fly!
trait_filename=(f"{data.get('dataset_groupname')}_"
f"{data.get('trait_name')}_"
- f"{__hash}.txt"))}
+ f"{__hash}.txt"))
+ }
gemma_wrapper_kwargs = {}
if data.get("loco"):
gemma_wrapper_kwargs["loco"] = f"--input {data.get('loco')}"
@@ -74,14 +75,14 @@ file output is returned.
if not all([k_computation_cmd, gwa_cmd]):
return jsonify(status=128,
error="Unable to generate cmds for computation!"), 500
- return jsonify(
- unique_id=queue_cmd(conn=redis.Redis(),
- email=data.get("email"),
- job_queue=app_defaults.get("REDIS_JOB_QUEUE"),
- cmd=f"{k_computation_cmd} && {gwa_cmd}"),
- status="queued",
- output_file=(f"{data.get('dataset_name')}_GWA_"
- f"{__hash}.txt"))
+ return jsonify(unique_id=queue_cmd(
+ conn=redis.Redis(),
+ email=data.get("email"),
+ job_queue=app_defaults.get("REDIS_JOB_QUEUE"),
+ cmd=f"{k_computation_cmd} && {gwa_cmd}"),
+ status="queued",
+ output_file=(f"{data.get('dataset_name')}_GWA_"
+ f"{__hash}.txt"))
@gemma.route("/status/<unique_id>", methods=["GET"])
@@ -90,8 +91,7 @@ def check_cmd_status(unique_id):
gemma endpoints, return the status of the command
"""
- status = redis.Redis().hget(name=unique_id,
- key="status")
+ status = redis.Redis().hget(name=unique_id, key="status")
if not status:
return jsonify(status=128,
error="The unique id you used does not exist!"), 500
@@ -105,39 +105,40 @@ 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.
"""
- working_dir = os.path.join(current_app.config.get("TMPDIR"),
- token)
- _dict = jsonfile_to_dict(os.path.join(working_dir,
- "metadata.json"))
+ 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"]]
+ 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}
_hash = get_hash_of_files([genofile, phenofile, snpsfile])
k_output_filename = f"{_hash}-k-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=compose_gemma_cmd(
- gemma_wrapper_cmd=current_app.config.get("GEMMA_"
- "WRAPPER_CMD"),
- gemma_wrapper_kwargs=None,
- gemma_kwargs=gemma_kwargs,
- gemma_args=["-gk", ">",
- (f"{current_app.config.get('TMPDIR')}/"
- f"{token}/{k_output_filename}")])),
- status="queued",
- output_file=k_output_filename)
+ 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=compose_gemma_cmd(gemma_wrapper_cmd=current_app.config.get(
+ "GEMMA_"
+ "WRAPPER_CMD"),
+ gemma_wrapper_kwargs=None,
+ gemma_kwargs=gemma_kwargs,
+ gemma_args=[
+ "-gk", ">",
+ (f"{current_app.config.get('TMPDIR')}/"
+ f"{token}/{k_output_filename}")
+ ])),
+ status="queued",
+ output_file=k_output_filename)
# pylint: disable=W0703
except Exception:
- return jsonify(status=128,
- # use better message
- message="Metadata file non-existent!")
+ return jsonify(
+ status=128,
+ # use better message
+ message="Metadata file non-existent!")
@gemma.route("/k-compute/loco/<chromosomes>/<token>", methods=["POST"])
@@ -146,39 +147,40 @@ def compute_k_loco(chromosomes, token):
values.
"""
- working_dir = os.path.join(current_app.config.get("TMPDIR"),
- token)
- _dict = jsonfile_to_dict(os.path.join(working_dir,
- "metadata.json"))
+ 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"]]
+ 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}
_hash = get_hash_of_files([genofile, phenofile, snpsfile])
k_output_filename = f"{_hash}-k-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=compose_gemma_cmd(
- gemma_wrapper_cmd=current_app.config.get("GEMMA_"
- "WRAPPER_CMD"),
- gemma_wrapper_kwargs={"loco": f"--input {chromosomes}"},
- gemma_kwargs=gemma_kwargs,
- gemma_args=["-gk", ">",
- (f"{current_app.config.get('TMPDIR')}/"
- f"{token}/{k_output_filename}")])),
- status="queued",
- output_file=k_output_filename)
+ 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=compose_gemma_cmd(
+ gemma_wrapper_cmd=current_app.config.get("GEMMA_"
+ "WRAPPER_CMD"),
+ gemma_wrapper_kwargs={"loco": f"--input {chromosomes}"},
+ gemma_kwargs=gemma_kwargs,
+ gemma_args=[
+ "-gk", ">",
+ (f"{current_app.config.get('TMPDIR')}/"
+ f"{token}/{k_output_filename}")
+ ])),
+ status="queued",
+ output_file=k_output_filename)
# pylint: disable=W0703
except Exception:
- return jsonify(status=128,
- # use better message
- message="Metadata file non-existent!")
+ return jsonify(
+ status=128,
+ # use better message
+ message="Metadata file non-existent!")
@gemma.route("/gwa-compute/<k_filename>/<token>", methods=["POST"])
@@ -186,41 +188,46 @@ 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"))
+ 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)}
+ 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=compose_gemma_cmd(
- gemma_wrapper_cmd=current_app.config.get("GEMMA_"
- "WRAPPER_CMD"),
- gemma_wrapper_kwargs={
- "input": os.path.join(working_dir, k_filename)
- },
- gemma_kwargs=gemma_kwargs,
- gemma_args=["gk", ">",
- (f"{current_app.config.get('TMPDIR')}/"
- f"{token}/{_output_filename}")])),
- status="queued",
- output_file=_output_filename)
+ 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=compose_gemma_cmd(gemma_wrapper_cmd=current_app.config.get(
+ "GEMMA_"
+ "WRAPPER_CMD"),
+ gemma_wrapper_kwargs={
+ "input":
+ os.path.join(working_dir, k_filename)
+ },
+ gemma_kwargs=gemma_kwargs,
+ gemma_args=[
+ "gk", ">",
+ (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!")
+ return jsonify(
+ status=128,
+ # use better message
+ message="Metadata file non-existent!")
@gemma.route("/gwa-compute/covars/<k_filename>/<token>", methods=["POST"])
@@ -228,42 +235,47 @@ def compute_gwa_with_covar(k_filename, token):
"""Compute GWA values. Covariates provided.
"""
- working_dir = os.path.join(current_app.config.get("TMPDIR"),
- token)
- _dict = jsonfile_to_dict(os.path.join(working_dir,
- "metadata.json"))
+ 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, covarfile = [
- os.path.join(working_dir,
- _dict.get(x))
- for x in ["geno", "pheno", "snps", "covar"]]
- gemma_kwargs = {"g": genofile, "p": phenofile,
- "a": snpsfile, "c": covarfile,
- "lmm": _dict.get("lmm", 9)}
+ os.path.join(working_dir, _dict.get(x))
+ for x in ["geno", "pheno", "snps", "covar"]
+ ]
+ gemma_kwargs = {
+ "g": genofile,
+ "p": phenofile,
+ "a": snpsfile,
+ "c": covarfile,
+ "lmm": _dict.get("lmm", 9)
+ }
_hash = get_hash_of_files([genofile, phenofile, snpsfile, covarfile])
_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=compose_gemma_cmd(
- gemma_wrapper_cmd=current_app.config.get("GEMMA_"
- "WRAPPER_CMD"),
- gemma_wrapper_kwargs={
- "input": os.path.join(working_dir, k_filename)
- },
- gemma_kwargs=gemma_kwargs,
- gemma_args=["-gk", ">",
- (f"{current_app.config.get('TMPDIR')}/"
- f"{token}/{_output_filename}")])),
- status="queued",
- output_file=_output_filename)
+ 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=compose_gemma_cmd(gemma_wrapper_cmd=current_app.config.get(
+ "GEMMA_"
+ "WRAPPER_CMD"),
+ gemma_wrapper_kwargs={
+ "input":
+ os.path.join(working_dir, k_filename)
+ },
+ gemma_kwargs=gemma_kwargs,
+ gemma_args=[
+ "-gk", ">",
+ (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!")
+ return jsonify(
+ status=128,
+ # use better message
+ message="Metadata file non-existent!")
@gemma.route("/gwa-compute/<k_filename>/loco/maf/<maf>/<token>",
@@ -272,45 +284,49 @@ def compute_gwa_with_loco_maf(k_filename, maf, token):
"""Compute GWA values. No Covariates provided. Only loco and maf vals given.
"""
- working_dir = os.path.join(current_app.config.get("TMPDIR"),
- token)
- _dict = jsonfile_to_dict(os.path.join(working_dir,
- "metadata.json"))
+ 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"]]
+ 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, "lmm": _dict.get("lmm", 9),
- 'maf': float(maf)}
+ gemma_kwargs = {
+ "g": genofile,
+ "p": phenofile,
+ "a": snpsfile,
+ "lmm": _dict.get("lmm", 9),
+ 'maf': float(maf)
+ }
_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=compose_gemma_cmd(
- gemma_wrapper_cmd=current_app.config.get("GEMMA_"
- "WRAPPER_CMD"),
- gemma_wrapper_kwargs={
- "loco": ("--input "
- f"{os.path.join(working_dir, k_filename)}")
- },
- gemma_kwargs=gemma_kwargs,
- gemma_args=["-gk", ">",
- (f"{current_app.config.get('TMPDIR')}/"
- f"{token}/{_output_filename}")])),
- status="queued",
- output_file=_output_filename)
+ 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=compose_gemma_cmd(
+ gemma_wrapper_cmd=current_app.config.get("GEMMA_"
+ "WRAPPER_CMD"),
+ gemma_wrapper_kwargs={
+ "loco": ("--input "
+ f"{os.path.join(working_dir, k_filename)}")
+ },
+ gemma_kwargs=gemma_kwargs,
+ gemma_args=[
+ "-gk", ">",
+ (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!")
+ return jsonify(
+ status=128,
+ # use better message
+ message="Metadata file non-existent!")
@gemma.route("/gwa-compute/<k_filename>/loco/covariates/maf/<maf>/<token>",
@@ -319,43 +335,47 @@ def compute_gwa_with_loco_covar(k_filename, maf, token):
"""Compute GWA values. No Covariates provided. Only loco and maf vals given.
"""
- working_dir = os.path.join(current_app.config.get("TMPDIR"),
- token)
- _dict = jsonfile_to_dict(os.path.join(working_dir,
- "metadata.json"))
+ 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, covarfile = [
- os.path.join(working_dir,
- _dict.get(x))
- for x in ["geno", "pheno", "snps", "covar"]]
+ os.path.join(working_dir, _dict.get(x))
+ for x in ["geno", "pheno", "snps", "covar"]
+ ]
if not do_paths_exist([genofile, phenofile, snpsfile, covarfile]):
raise FileNotFoundError
- gemma_kwargs = {"g": genofile, "p": phenofile,
- "a": snpsfile, "c": covarfile,
- "lmm": _dict.get("lmm", 9),
- "maf": float(maf)}
+ gemma_kwargs = {
+ "g": genofile,
+ "p": phenofile,
+ "a": snpsfile,
+ "c": covarfile,
+ "lmm": _dict.get("lmm", 9),
+ "maf": float(maf)
+ }
_hash = get_hash_of_files([genofile, phenofile, snpsfile, covarfile])
_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=compose_gemma_cmd(
- gemma_wrapper_cmd=current_app.config.get("GEMMA_"
- "WRAPPER_CMD"),
- gemma_wrapper_kwargs={
- "loco": ("--input "
- f"{os.path.join(working_dir, k_filename)}")
- },
- gemma_kwargs=gemma_kwargs,
- gemma_args=["-gk", ">",
- (f"{current_app.config.get('TMPDIR')}/"
- f"{token}/{_output_filename}")])),
- status="queued",
- output_file=_output_filename)
+ 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=compose_gemma_cmd(
+ gemma_wrapper_cmd=current_app.config.get("GEMMA_"
+ "WRAPPER_CMD"),
+ gemma_wrapper_kwargs={
+ "loco": ("--input "
+ f"{os.path.join(working_dir, k_filename)}")
+ },
+ gemma_kwargs=gemma_kwargs,
+ gemma_args=[
+ "-gk", ">",
+ (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!")
+ return jsonify(
+ status=128,
+ # use better message
+ message="Metadata file non-existent!")
diff --git a/gn3/computations/gemma.py b/gn3/computations/gemma.py
index 7ee70b0..7b5f91d 100644
--- a/gn3/computations/gemma.py
+++ b/gn3/computations/gemma.py
@@ -49,9 +49,7 @@ def do_paths_exist(paths: ValuesView) -> bool:
def generate_gemma_computation_cmd(
- gemma_cmd: str,
- gemma_kwargs: Dict[str, str],
- output_file: str,
+ 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", "")
@@ -69,5 +67,4 @@ def generate_gemma_computation_cmd(
return compose_gemma_cmd(gemma_wrapper_cmd=gemma_cmd,
gemma_wrapper_kwargs=gemma_wrapper_kwargs,
gemma_kwargs=_kwargs,
- gemma_args=["-gk", ">",
- output_file])
+ gemma_args=["-gk", ">", output_file])
diff --git a/tests/integration/test_gemma.py b/tests/integration/test_gemma.py
index 6d2116b..822f088 100644
--- a/tests/integration/test_gemma.py
+++ b/tests/integration/test_gemma.py
@@ -21,19 +21,21 @@ class GemmaAPITest(unittest.TestCase):
"""Test cases for the Gemma API"""
def setUp(self):
self.app = create_app({
- "GENODIR": os.path.abspath(
- os.path.join(os.path.dirname(__file__),
- "test_data/")),
- "REDIS_JOB_QUEUE": "GN3::job-queue",
- "GEMMA_WRAPPER_CMD": "gemma-wrapper"}).test_client()
+ "GENODIR":
+ os.path.abspath(
+ os.path.join(os.path.dirname(__file__), "test_data/")),
+ "REDIS_JOB_QUEUE":
+ "GN3::job-queue",
+ "GEMMA_WRAPPER_CMD":
+ "gemma-wrapper"
+ }).test_client()
@mock.patch("gn3.api.gemma.run_cmd")
def test_get_version(self, mock_run_cmd):
"""Test that the correct response is returned"""
mock_run_cmd.return_value = {"status": 0, "output": "v1.9"}
response = self.app.get("/api/gemma/version", follow_redirects=True)
- self.assertEqual(response.get_json(),
- {"status": 0, "output": "v1.9"})
+ self.assertEqual(response.get_json(), {"status": 0, "output": "v1.9"})
self.assertEqual(response.status_code, 200)
@mock.patch("gn3.api.gemma.redis.Redis")
@@ -59,60 +61,69 @@ class GemmaAPITest(unittest.TestCase):
"bxd_GWA_gUFhGu4rLG7k+CXLPk1OUg.txt")
]
mock_queue_cmd.return_value = "my-unique-id"
- response = self.app.post("/api/gemma/k-gwa-computation", json={
- "trait_filename": "BXD.txt",
- "geno_filename": "BXD_geno",
- "values": ["X", "N/A", "X"],
- "dataset_groupname": "BXD",
- "trait_name": "Height",
- "email": "me@me.com",
- "dataset_name": "BXD"
- })
- mock_queue_cmd.assert_has_calls(
- [mock.call(conn=_redis_conn,
- email="me@me.com",
- job_queue="GN3::job-queue",
- cmd=("gemma-wrapper --json -- -g "
- "genofile.txt -p test.txt "
- "-a genofile_snps.txt -gk > "
- "/tmp/gn2/bxd_K_gUFhGu4rLG7k+CXLPk1OUg.txt "
- "&& gemma-wrapper --json --input "
- "/tmp/gn2/bxd_K_gUFhGu4rLG7k+CXLPk1OUg.txt"
- " -- -a genofile_snps.txt -lmm 9 -g "
- "genofile.txt -p test.txt "
- "-a genofile_snps.txt "
- "-gk > "
- "/tmp/gn2/"
- "bxd_GWA_gUFhGu4rLG7k+CXLPk1OUg.txt"))]
- )
+ response = self.app.post("/api/gemma/k-gwa-computation",
+ json={
+ "trait_filename": "BXD.txt",
+ "geno_filename": "BXD_geno",
+ "values": ["X", "N/A", "X"],
+ "dataset_groupname": "BXD",
+ "trait_name": "Height",
+ "email": "me@me.com",
+ "dataset_name": "BXD"
+ })
+ mock_queue_cmd.assert_has_calls([
+ mock.call(conn=_redis_conn,
+ email="me@me.com",
+ job_queue="GN3::job-queue",
+ cmd=("gemma-wrapper --json -- -g "
+ "genofile.txt -p test.txt "
+ "-a genofile_snps.txt -gk > "
+ "/tmp/gn2/bxd_K_gUFhGu4rLG7k+CXLPk1OUg.txt "
+ "&& gemma-wrapper --json --input "
+ "/tmp/gn2/bxd_K_gUFhGu4rLG7k+CXLPk1OUg.txt"
+ " -- -a genofile_snps.txt -lmm 9 -g "
+ "genofile.txt -p test.txt "
+ "-a genofile_snps.txt "
+ "-gk > "
+ "/tmp/gn2/"
+ "bxd_GWA_gUFhGu4rLG7k+CXLPk1OUg.txt"))
+ ])
# mock_pheno_txt_file.return_value = "/tmp/gn2/BXD_6OBEPW."
self.assertEqual(
- response.get_json(),
- {"unique_id": 'my-unique-id',
- "status": "queued",
- "output_file": "BXD_GWA_WzxVcfhKAn4fJnSWpsBq0g.txt"})
+ response.get_json(), {
+ "unique_id": 'my-unique-id',
+ "status": "queued",
+ "output_file": "BXD_GWA_WzxVcfhKAn4fJnSWpsBq0g.txt"
+ })
@mock.patch("gn3.api.gemma.redis.Redis")
@mock.patch("gn3.api.gemma.queue_cmd")
- def test_run_gemma_with_loco(self,
- mock_queue_cmd, mock_redis):
+ def test_run_gemma_with_loco(self, mock_queue_cmd, mock_redis):
"""Test that gemma composes the command correctly with loco"""
_redis_conn = MockRedis(redis=mock.MagicMock(), hget=mock.MagicMock())
mock_redis.return_value = _redis_conn
mock_queue_cmd.return_value = "my-unique-id"
- response = self.app.post("/api/gemma/k-gwa-computation", json={
- "trait_filename": os.path.abspath(os.path.join(
- os.path.dirname(__file__),
- "test_data/"
- )),
- "geno_filename": "BXD_geno.txt.gz",
- "values": ["X", "N/A", "X"],
- "dataset_groupname": "BXD",
- "trait_name": "Height",
- "email": "me@me.com",
- "dataset_name": "BXD",
- "loco": "1,2,3,4,5,6"
- })
+ response = self.app.post("/api/gemma/k-gwa-computation",
+ json={
+ "trait_filename":
+ os.path.abspath(
+ os.path.join(
+ os.path.dirname(__file__),
+ "test_data/")),
+ "geno_filename":
+ "BXD_geno.txt.gz",
+ "values": ["X", "N/A", "X"],
+ "dataset_groupname":
+ "BXD",
+ "trait_name":
+ "Height",
+ "email":
+ "me@me.com",
+ "dataset_name":
+ "BXD",
+ "loco":
+ "1,2,3,4,5,6"
+ })
mock_queue_cmd.called_with(
conn=_redis_conn,
email="me@me.com",
@@ -130,10 +141,11 @@ class GemmaAPITest(unittest.TestCase):
"/tmp/gn2/"
"bxd_GWA_gUFhGu4rLG7k+CXLPk1OUg.txt"))
self.assertEqual(
- response.get_json(),
- {"unique_id": 'my-unique-id',
- "status": "queued",
- "output_file": "BXD_GWA_WzxVcfhKAn4fJnSWpsBq0g.txt"})
+ response.get_json(), {
+ "unique_id": 'my-unique-id',
+ "status": "queued",
+ "output_file": "BXD_GWA_WzxVcfhKAn4fJnSWpsBq0g.txt"
+ })
@mock.patch("gn3.api.gemma.redis.Redis")
def test_check_cmd_status(self, mock_redis):
@@ -146,18 +158,15 @@ class GemmaAPITest(unittest.TestCase):
"cmd%3A%3A2021-02-1217-3224-3224-1234"),
follow_redirects=True)
mock_hget.assert_called_once_with(
- name="cmd::2021-02-1217-3224-3224-1234",
- key="status")
- self.assertEqual(response.get_json(),
- {"status": "test"})
+ name="cmd::2021-02-1217-3224-3224-1234", key="status")
+ self.assertEqual(response.get_json(), {"status": "test"})
@mock.patch("gn3.api.gemma.queue_cmd")
@mock.patch("gn3.api.gemma.get_hash_of_files")
@mock.patch("gn3.api.gemma.jsonfile_to_dict")
@mock.patch("gn3.api.gemma.do_paths_exist")
@mock.patch("gn3.api.gemma.redis.Redis")
- def test_k_compute(self, mock_redis, mock_path_exist,
- mock_json, mock_hash,
+ def test_k_compute(self, mock_redis, mock_path_exist, mock_json, mock_hash,
mock_queue_cmd):
"""Test /gemma/k-compute/<token>"""
mock_path_exist.return_value, _redis_conn = True, mock.MagicMock()
diff --git a/tests/unit/computations/test_gemma.py b/tests/unit/computations/test_gemma.py
index b5ffbfd..2d2fbf9 100644
--- a/tests/unit/computations/test_gemma.py
+++ b/tests/unit/computations/test_gemma.py
@@ -12,8 +12,7 @@ class TestGemma(unittest.TestCase):
def test_generate_pheno_txt_file(self):
"""Test that the pheno text file is generated correctly"""
open_mock = mock.mock_open()
- with mock.patch("gn3.computations.gemma.open",
- open_mock, create=True):
+ with mock.patch("gn3.computations.gemma.open", open_mock, create=True):
_file = generate_pheno_txt_file(tmpdir="/tmp",
trait_filename="phenotype.txt",
values=["x", "x", "BXD07 438.700"])
@@ -24,7 +23,8 @@ class TestGemma(unittest.TestCase):
open_mock.return_value.write.assert_has_calls([
mock.call("NA\n"),
mock.call("NA\n"),
- mock.call("BXD07 438.700\n")])
+ mock.call("BXD07 438.700\n")
+ ])
def test_generate_hash_of_string(self):
"""Test that a string is hashed correctly"""
@@ -42,11 +42,11 @@ class TestGemma(unittest.TestCase):
gemma_kwargs={
"geno_filename": "genofile.txt",
"trait_filename": "test.txt",
- "covar_filename": "genofile_snps.txt"},
+ "covar_filename": "genofile_snps.txt"
+ },
output_file="/tmp/gn2/k_output_gUFhGu4rLG7k+CXLPk1OUg.txt",
- ),
- ("gemma-wrapper --json -- "
- "-g genofile.txt -p "
- "test.txt -a genofile_snps.txt "
- "-gk > /tmp/gn2/"
- "k_output_gUFhGu4rLG7k+CXLPk1OUg.txt"))
+ ), ("gemma-wrapper --json -- "
+ "-g genofile.txt -p "
+ "test.txt -a genofile_snps.txt "
+ "-gk > /tmp/gn2/"
+ "k_output_gUFhGu4rLG7k+CXLPk1OUg.txt"))