From abb55d7e03bf207ebf00b4c71f1bbdd8f58a0ad3 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 12 Feb 2024 10:44:35 +0300 Subject: Check for errors in the 'phenose' file. --- r_qtl/r_qtl2_qc.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'r_qtl/r_qtl2_qc.py') diff --git a/r_qtl/r_qtl2_qc.py b/r_qtl/r_qtl2_qc.py index a41c442..f62f142 100644 --- a/r_qtl/r_qtl2_qc.py +++ b/r_qtl/r_qtl2_qc.py @@ -97,6 +97,22 @@ def pheno_errors(zfile: ZipFile) -> Iterator[Union[InvalidValue, MissingFile]]: zfile, "pheno", (__min_3_decimal_places__,)) if error is not None) +def phenose_errors(zfile: ZipFile) -> Iterator[Union[InvalidValue, MissingFile]]: + """Check for and retrieve phenose errors.""" + def __min_6_decimal_places__( + lineno: int, field: str, value: str) -> Optional[InvalidValue]: + if not (re.search(r"^([0-9]+\.[0-9]{6,}|[0-9]+\.?0*)$", value) + or re.search(r"^0\.0+$", value) + or re.search("^0+$", value)): + return InvalidValue(lineno, field, value, ( + f"Invalid value '{value}'. Expected numerical value " + "with at least 6 decimal places.")) + return None + return ( + error for error in retrieve_errors( + zfile, "phenose", (__min_6_decimal_places__,)) + if error is not None) + def retrieve_errors(zfile: ZipFile, filetype: str, checkers: tuple[Callable]) -> Iterator[ Union[InvalidValue, MissingFile]]: """Check for and retrieve errors from files of type `filetype`.""" -- cgit v1.2.3