diff options
-rw-r--r-- | gn3/api/gemma.py | 26 | ||||
-rw-r--r-- | gn3/api/rqtl.py | 5 | ||||
-rw-r--r-- | gn3/computations/gemma.py | 10 | ||||
-rw-r--r-- | tests/integration/test_gemma.py | 20 |
4 files changed, 28 insertions, 33 deletions
diff --git a/gn3/api/gemma.py b/gn3/api/gemma.py index 6b0b20e..c862d91 100644 --- a/gn3/api/gemma.py +++ b/gn3/api/gemma.py @@ -12,7 +12,7 @@ from gn3.commands import run_cmd from gn3.fs_helpers import cache_ipfs_file from gn3.fs_helpers import jsonfile_to_dict from gn3.computations.gemma import generate_gemma_cmd -from gn3.computations.gemma import do_paths_exist +from gn3.computations.gemma import assert_paths_exist gemma = Blueprint("gemma", __name__) @@ -55,8 +55,7 @@ traitfile, and snpsfile are extracted from a metadata.json file. genofile = cache_ipfs_file( ipfs_file=_dict.get("geno"), cache_dir=current_app.config.get('CACHEDIR')) - if not do_paths_exist([genofile, phenofile, snpsfile]): - raise FileNotFoundError + assert_paths_exist([genofile, phenofile, snpsfile]) gemma_kwargs = {"g": genofile, "p": phenofile, "a": snpsfile} results = generate_gemma_cmd( gemma_cmd=current_app.config.get("GEMMA_" @@ -97,8 +96,7 @@ values. ipfs_file=_dict.get("geno"), cache_dir=current_app.config.get('CACHEDIR') ) - if not do_paths_exist([genofile, phenofile, snpsfile]): - raise FileNotFoundError + assert_paths_exist([genofile, phenofile, snpsfile]) gemma_kwargs = {"g": genofile, "p": phenofile, "a": snpsfile} results = generate_gemma_cmd( gemma_cmd=current_app.config.get("GEMMA_" @@ -235,8 +233,7 @@ def compute_gwa_with_loco_maf(k_filename, maf, token): ipfs_file=_dict.get("geno"), cache_dir=current_app.config.get('CACHEDIR') ) - if not do_paths_exist([genofile, phenofile, snpsfile]): - raise FileNotFoundError + assert_paths_exist([genofile, phenofile, snpsfile]) gemma_kwargs = { "g": genofile, "p": phenofile, @@ -286,8 +283,7 @@ def compute_gwa_with_loco_covar(k_filename, maf, token): ipfs_file=_dict.get("geno"), cache_dir=current_app.config.get('CACHEDIR') ) - if not do_paths_exist([genofile, phenofile, snpsfile, covarfile]): - raise FileNotFoundError + assert_paths_exist([genofile, phenofile, snpsfile, covarfile]) gemma_kwargs = { "g": genofile, "p": phenofile, @@ -340,8 +336,7 @@ covars; lmm defaults to 9! ipfs_file=_dict.get("geno"), cache_dir=current_app.config.get('CACHEDIR') ) - if not do_paths_exist([genofile, phenofile, snpsfile]): - raise FileNotFoundError + assert_paths_exist([genofile, phenofile, snpsfile]) gemma_kwargs = {"g": genofile, "p": phenofile, "a": snpsfile} gemma_k_cmd = generate_gemma_cmd( gemma_cmd=current_app.config.get("GEMMA_" @@ -396,8 +391,7 @@ covars; lmm defaults to 9! ipfs_file=_dict.get("geno"), cache_dir=current_app.config.get('CACHEDIR') ) - if not do_paths_exist([genofile, phenofile, snpsfile]): - raise FileNotFoundError + assert_paths_exist([genofile, phenofile, snpsfile]) gemma_kwargs = {"g": genofile, "p": phenofile, "a": snpsfile} gemma_k_cmd = generate_gemma_cmd( gemma_cmd=current_app.config.get("GEMMA_" @@ -451,8 +445,7 @@ def compute_k_gwa_with_loco_only(chromosomes, maf, token): ipfs_file=_dict.get("geno"), cache_dir=current_app.config.get('CACHEDIR') ) - if not do_paths_exist([genofile, phenofile, snpsfile]): - raise FileNotFoundError + assert_paths_exist([genofile, phenofile, snpsfile]) gemma_kwargs = {"g": genofile, "p": phenofile, "a": snpsfile} gemma_k_cmd = generate_gemma_cmd( gemma_cmd=current_app.config.get("GEMMA_" @@ -509,8 +502,7 @@ def compute_k_gwa_with_loco_and_cavar(chromosomes, maf, token): ipfs_file=_dict.get("geno"), cache_dir=current_app.config.get('CACHEDIR') ) - if not do_paths_exist([genofile, phenofile, snpsfile]): - raise FileNotFoundError + assert_paths_exist([genofile, phenofile, snpsfile]) gemma_kwargs = {"g": genofile, "p": phenofile, "a": snpsfile} gemma_k_cmd = generate_gemma_cmd( gemma_cmd=current_app.config.get("GEMMA_" diff --git a/gn3/api/rqtl.py b/gn3/api/rqtl.py index ae0110d..bfb191e 100644 --- a/gn3/api/rqtl.py +++ b/gn3/api/rqtl.py @@ -8,7 +8,7 @@ from flask import request from gn3.computations.rqtl import generate_rqtl_cmd, process_rqtl_mapping, \ process_rqtl_pairscan, process_perm_output -from gn3.computations.gemma import do_paths_exist +from gn3.computations.gemma import assert_paths_exist rqtl = Blueprint("rqtl", __name__) @@ -21,8 +21,7 @@ run the rqtl_wrapper script and return the results as JSON genofile = request.form['geno_file'] phenofile = request.form['pheno_file'] - if not do_paths_exist([genofile, phenofile]): - raise FileNotFoundError + assert_paths_exist([genofile, phenofile]) # Split kwargs by those with values and boolean ones that just convert to True/False kwargs = ["covarstruct", "model", "method", "nperm", "scale", "control"] diff --git a/gn3/computations/gemma.py b/gn3/computations/gemma.py index 03e1a76..5a2616b 100644 --- a/gn3/computations/gemma.py +++ b/gn3/computations/gemma.py @@ -1,4 +1,5 @@ """Procedures related gemma computations""" +import errno import os from base64 import b64encode @@ -40,11 +41,14 @@ def generate_pheno_txt_file(trait_filename: str, return f"{tmpdir}/gn2/{trait_filename}" -def do_paths_exist(paths: ValuesView) -> bool: - """Given a list of PATHS, return False if any of them do not exist.""" +def assert_paths_exist(paths: ValuesView) -> bool: + """Given a list of PATHS, throw error if any of them do not exist.""" for path in paths: if not os.path.isfile(path): - return False + if throw_error: + raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), path) + else: + return False return True diff --git a/tests/integration/test_gemma.py b/tests/integration/test_gemma.py index 79ddaca..53a1596 100644 --- a/tests/integration/test_gemma.py +++ b/tests/integration/test_gemma.py @@ -60,7 +60,7 @@ class GemmaAPITest(unittest.TestCase): @mock.patch("gn3.api.gemma.queue_cmd") @mock.patch("gn3.computations.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.assert_paths_exist") @mock.patch("gn3.api.gemma.redis.Redis") @mock.patch("gn3.api.gemma.cache_ipfs_file") def test_k_compute(self, mock_ipfs_cache, @@ -103,7 +103,7 @@ class GemmaAPITest(unittest.TestCase): @mock.patch("gn3.api.gemma.queue_cmd") @mock.patch("gn3.computations.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.assert_paths_exist") @mock.patch("gn3.api.gemma.redis.Redis") @mock.patch("gn3.api.gemma.cache_ipfs_file") def test_k_compute_loco(self, mock_ipfs_cache, @@ -147,7 +147,7 @@ class GemmaAPITest(unittest.TestCase): @mock.patch("gn3.api.gemma.queue_cmd") @mock.patch("gn3.computations.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.assert_paths_exist") @mock.patch("gn3.api.gemma.redis.Redis") @mock.patch("gn3.api.gemma.cache_ipfs_file") def test_gwa_compute(self, mock_ipfs_cache, @@ -198,7 +198,7 @@ class GemmaAPITest(unittest.TestCase): @mock.patch("gn3.api.gemma.queue_cmd") @mock.patch("gn3.computations.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.assert_paths_exist") @mock.patch("gn3.api.gemma.redis.Redis") @mock.patch("gn3.api.gemma.cache_ipfs_file") def test_gwa_compute_with_covars(self, mock_ipfs_cache, @@ -252,7 +252,7 @@ class GemmaAPITest(unittest.TestCase): @mock.patch("gn3.api.gemma.queue_cmd") @mock.patch("gn3.computations.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.assert_paths_exist") @mock.patch("gn3.api.gemma.redis.Redis") @mock.patch("gn3.api.gemma.cache_ipfs_file") def test_gwa_compute_with_loco_only(self, mock_ipfs_cache, @@ -305,7 +305,7 @@ class GemmaAPITest(unittest.TestCase): @mock.patch("gn3.api.gemma.queue_cmd") @mock.patch("gn3.computations.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.assert_paths_exist") @mock.patch("gn3.api.gemma.redis.Redis") @mock.patch("gn3.api.gemma.cache_ipfs_file") def test_gwa_compute_with_loco_covars(self, mock_ipfs_cache, @@ -360,7 +360,7 @@ class GemmaAPITest(unittest.TestCase): @mock.patch("gn3.api.gemma.queue_cmd") @mock.patch("gn3.computations.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.assert_paths_exist") @mock.patch("gn3.api.gemma.redis.Redis") @mock.patch("gn3.api.gemma.cache_ipfs_file") def test_k_gwa_compute_without_loco_covars(self, mock_ipfs_cache, @@ -416,7 +416,7 @@ class GemmaAPITest(unittest.TestCase): @mock.patch("gn3.api.gemma.queue_cmd") @mock.patch("gn3.computations.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.assert_paths_exist") @mock.patch("gn3.api.gemma.redis.Redis") @mock.patch("gn3.api.gemma.cache_ipfs_file") def test_k_gwa_compute_with_covars_only(self, mock_ipfs_cache, @@ -481,7 +481,7 @@ class GemmaAPITest(unittest.TestCase): @mock.patch("gn3.api.gemma.queue_cmd") @mock.patch("gn3.computations.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.assert_paths_exist") @mock.patch("gn3.api.gemma.redis.Redis") @mock.patch("gn3.api.gemma.cache_ipfs_file") def test_k_gwa_compute_with_loco_only(self, mock_ipfs_cache, @@ -547,7 +547,7 @@ class GemmaAPITest(unittest.TestCase): @mock.patch("gn3.api.gemma.queue_cmd") @mock.patch("gn3.computations.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.assert_paths_exist") @mock.patch("gn3.api.gemma.redis.Redis") @mock.patch("gn3.api.gemma.cache_ipfs_file") def test_k_gwa_compute_with_loco_and_covar(self, mock_ipfs_cache, |