diff options
-rw-r--r-- | gn3/api/gemma.py | 58 | ||||
-rw-r--r-- | tests/integration/test_gemma.py | 109 |
2 files changed, 0 insertions, 167 deletions
diff --git a/gn3/api/gemma.py b/gn3/api/gemma.py index ed698d3..21c4cf5 100644 --- a/gn3/api/gemma.py +++ b/gn3/api/gemma.py @@ -26,64 +26,6 @@ def get_version(): return jsonify(run_cmd(f"{gemma_cmd} -v | head -n 1")) -# This is basically extracted from genenetwork2 -# wqflask/wqflask/marker_regression/gemma_ampping.py -@gemma.route("/k-gwa-computation", methods=["POST"]) -def run_gemma(): - """Generates a command for generating K-Values and then later, generate a GWA -command that contains markers. These commands are queued; and the expected -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", ""))) - gemma_kwargs = { - "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")) - } - 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_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")) - 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_" - f"{__hash}.txt")) - 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")) - - @gemma.route("/status/<unique_id>", methods=["GET"]) def check_cmd_status(unique_id): """Given a (url-encoded) UNIQUE-ID which is returned when hitting any of the diff --git a/tests/integration/test_gemma.py b/tests/integration/test_gemma.py index bfce37a..7a7f520 100644 --- a/tests/integration/test_gemma.py +++ b/tests/integration/test_gemma.py @@ -39,115 +39,6 @@ class GemmaAPITest(unittest.TestCase): self.assertEqual(response.status_code, 200) @mock.patch("gn3.api.gemma.redis.Redis") - @mock.patch("gn3.api.gemma.queue_cmd") - @mock.patch("gn3.api.gemma.generate_gemma_computation_cmd") - def test_run_gemma_no_loco(self, mock_gemma_computation_cmd, - mock_queue_cmd, mock_redis): - """Test that gemma composes the command correctly without loco""" - _redis_conn = MockRedis(redis=mock.MagicMock(), hget=mock.MagicMock()) - mock_redis.return_value = _redis_conn - mock_gemma_computation_cmd.side_effect = [ - ("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_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")) - ]) - # 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" - }) - - @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): - """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" - }) - mock_queue_cmd.called_with( - 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")) - self.assertEqual( - 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): """Test that you can check the status of a given command""" mock_hget = mock.MagicMock() |