From 047df9c4a01f860f76c5c8c605780009e3e3ce03 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 24 Mar 2024 09:41:55 +0100 Subject: Move assert_paths_exist into fs_helpers --- gn3/api/gemma.py | 2 +- gn3/api/rqtl.py | 2 +- gn3/computations/gemma.py | 13 +------------ gn3/fs_helpers.py | 9 +++++++++ 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/gn3/api/gemma.py b/gn3/api/gemma.py index c862d91..2dd53ea 100644 --- a/gn3/api/gemma.py +++ b/gn3/api/gemma.py @@ -10,7 +10,7 @@ from flask import request from gn3.commands import queue_cmd from gn3.commands import run_cmd from gn3.fs_helpers import cache_ipfs_file -from gn3.fs_helpers import jsonfile_to_dict +from gn3.fs_helpers import jsonfile_to_dict, assert_paths_exist from gn3.computations.gemma import generate_gemma_cmd from gn3.computations.gemma import assert_paths_exist diff --git a/gn3/api/rqtl.py b/gn3/api/rqtl.py index bfb191e..3893275 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 assert_paths_exist +from gn3.fs_helpers import assert_paths_exist rqtl = Blueprint("rqtl", __name__) diff --git a/gn3/computations/gemma.py b/gn3/computations/gemma.py index 5a2616b..2c367ff 100644 --- a/gn3/computations/gemma.py +++ b/gn3/computations/gemma.py @@ -8,7 +8,7 @@ from typing import Optional, Dict from typing import List from typing import ValuesView from gn3.commands import compose_gemma_cmd -from gn3.fs_helpers import get_hash_of_files +from gn3.fs_helpers import get_hash_of_files, assert_paths_exist def generate_hash_of_string(unhashed_str: str) -> str: @@ -41,17 +41,6 @@ def generate_pheno_txt_file(trait_filename: str, return f"{tmpdir}/gn2/{trait_filename}" -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): - if throw_error: - raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), path) - else: - return False - return True - - # pylint: disable=R0913 def generate_gemma_cmd(gemma_cmd: str, output_dir: str, diff --git a/gn3/fs_helpers.py b/gn3/fs_helpers.py index e7366ac..6b0a00a 100644 --- a/gn3/fs_helpers.py +++ b/gn3/fs_helpers.py @@ -11,6 +11,15 @@ from typing import Dict from typing import List from werkzeug.utils import secure_filename +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): + if throw_error: + raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), path) + else: + return False + return True def get_hash_of_files(files: List[str]) -> str: """Given a list of valid of FILES, return their hash as a string""" -- cgit v1.2.3