From 321cb85283dc0a182e86d0ee509cae9ced4e39cd Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 9 Aug 2024 14:20:17 -0500 Subject: Rename module: Module contains exceptions classes. --- r_qtl/errors.py | 13 ------------- r_qtl/exceptions.py | 13 +++++++++++++ r_qtl/r_qtl2.py | 6 +++--- r_qtl/r_qtl2_qc.py | 6 +++--- scripts/process_rqtl2_bundle.py | 2 +- scripts/qc_on_rqtl2_bundle.py | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) delete mode 100644 r_qtl/errors.py create mode 100644 r_qtl/exceptions.py diff --git a/r_qtl/errors.py b/r_qtl/errors.py deleted file mode 100644 index 417eb58..0000000 --- a/r_qtl/errors.py +++ /dev/null @@ -1,13 +0,0 @@ -"""R/qtl and R/qtl2 error types.""" - -class RQTLError(Exception): - """Base class for R/qtl and R/qtl2 errors.""" - -class InvalidFormat(RQTLError): - """Raised when the format of the file(s) is invalid.""" - -class MissingFileError(InvalidFormat): - """ - Raise when at least one file listed in the control file is missing from the - R/qtl2 bundle. - """ diff --git a/r_qtl/exceptions.py b/r_qtl/exceptions.py new file mode 100644 index 0000000..9620cf4 --- /dev/null +++ b/r_qtl/exceptions.py @@ -0,0 +1,13 @@ +"""R/qtl and R/qtl2 error types.""" + +class RQTLError(Exception): + """Base class for R/qtl and R/qtl2 errors.""" + +class InvalidFormat(RQTLError): + """Raised when the format of the file(s) is invalid.""" + +class MissingFileException(InvalidFormat): + """ + Raise when at least one file listed in the control file is missing from the + R/qtl2 bundle. + """ diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py index c2e1148..c6282c5 100644 --- a/r_qtl/r_qtl2.py +++ b/r_qtl/r_qtl2.py @@ -11,7 +11,7 @@ import yaml from functional_tools import take, chain -from r_qtl.errors import InvalidFormat, MissingFileError +from r_qtl.exceptions import InvalidFormat, MissingFileException FILE_TYPES = ( "geno", "founder_geno", "pheno", "covar", "phenocovar", "gmap", "pmap", @@ -157,7 +157,7 @@ def control_data(control_src: Union[Path, ZipFile]) -> dict: Raises ------ - r_qtl.errors.InvalidFormat + r_qtl.exceptions.InvalidFormat """ if isinstance(control_src, ZipFile): return __control_data_from_zipfile__(control_src) @@ -382,7 +382,7 @@ def file_data(zfile: ZipFile, zfile, member_key, cdata, process_transposed_value): yield row except KeyError as exc: - raise MissingFileError(*exc.args) from exc + raise MissingFileException(*exc.args) from exc def cross_information(zfile: ZipFile, cdata: dict) -> Iterator[dict]: """Load cross information where present.""" diff --git a/r_qtl/r_qtl2_qc.py b/r_qtl/r_qtl2_qc.py index be1eac4..7e93d23 100644 --- a/r_qtl/r_qtl2_qc.py +++ b/r_qtl/r_qtl2_qc.py @@ -3,8 +3,8 @@ from zipfile import ZipFile from functools import reduce, partial from typing import Union, Iterator, Optional, Callable -from r_qtl import errors as rqe from r_qtl import r_qtl2 as rqtl2 +from r_qtl import exceptions as rqe from r_qtl.r_qtl2 import FILE_TYPES from r_qtl.fileerrors import MissingFile @@ -59,7 +59,7 @@ def validate_bundle(zfile: ZipFile): """Ensure the R/qtl2 bundle is valid.""" missing = missing_files(zfile) if len(missing) > 0: - raise rqe.MissingFileError( + raise rqe.MissingFileException( "The following files do not exist in the bundle: " + ", ".join(mfile[1] for mfile in missing)) @@ -111,6 +111,6 @@ def retrieve_errors(zfile: ZipFile, filetype: str, checkers: tuple[Callable]) -> if value is not None: for checker in checkers: yield checker(lineno=lineno, field=field, value=value) - except rqe.MissingFileError: + except rqe.MissingFileException: fname = cdata.get(filetype) yield MissingFile(filetype, fname, f"Missing '{filetype}' file '{fname}'.") diff --git a/scripts/process_rqtl2_bundle.py b/scripts/process_rqtl2_bundle.py index a7e169d..20cfd3b 100644 --- a/scripts/process_rqtl2_bundle.py +++ b/scripts/process_rqtl2_bundle.py @@ -13,9 +13,9 @@ from redis import Redis from functional_tools import take -import r_qtl.errors as rqe import r_qtl.r_qtl2 as rqtl2 import r_qtl.r_qtl2_qc as rqc +import r_qtl.exceptions as rqe from uploader import jobs from uploader.db_utils import database_connection diff --git a/scripts/qc_on_rqtl2_bundle.py b/scripts/qc_on_rqtl2_bundle.py index 7784c06..fc95d13 100644 --- a/scripts/qc_on_rqtl2_bundle.py +++ b/scripts/qc_on_rqtl2_bundle.py @@ -20,9 +20,9 @@ from uploader import jobs from uploader.db_utils import database_connection from uploader.check_connections import check_db, check_redis -from r_qtl import errors as rqe from r_qtl import r_qtl2 as rqtl2 from r_qtl import r_qtl2_qc as rqc +from r_qtl import exceptions as rqe from r_qtl import fileerrors as rqfe from scripts.process_rqtl2_bundle import parse_job @@ -105,7 +105,7 @@ def retrieve_errors_with_progress(rconn: Redis,#pylint: disable=[too-many-locals __update_processed__(value) rconn.hset(fqjobid, f"{filetype}-linecount", count) - except rqe.MissingFileError: + except rqe.MissingFileException: fname = cdata.get(filetype) yield rqfe.MissingFile(filetype, fname, ( f"The file '{fname}' does not exist in the bundle despite it being " -- cgit v1.2.3