aboutsummaryrefslogtreecommitdiff
path: root/r_qtl
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-02-20 10:57:56 +0300
committerFrederick Muriuki Muriithi2024-02-20 10:57:56 +0300
commitce243a57b24d6adecb169487e706290d91b22d19 (patch)
tree6b0b06a444c16ffb8be1c65fa4e5b78ced6a0615 /r_qtl
parenta4324cd24b5a14fbcf19a6e04d2b76fb2838038e (diff)
downloadgn-uploader-ce243a57b24d6adecb169487e706290d91b22d19.tar.gz
Track filename in the errors
R/qtl2 bundles can contain more than one file, of the same type. When errors are encountered in any of the files, we need to be able to inform the user which file it is, in addition to the line and column number.
Diffstat (limited to 'r_qtl')
-rw-r--r--r_qtl/r_qtl2_qc.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/r_qtl/r_qtl2_qc.py b/r_qtl/r_qtl2_qc.py
index 43f7d94..be1eac4 100644
--- a/r_qtl/r_qtl2_qc.py
+++ b/r_qtl/r_qtl2_qc.py
@@ -63,12 +63,13 @@ def validate_bundle(zfile: ZipFile):
"The following files do not exist in the bundle: " +
", ".join(mfile[1] for mfile in missing))
-def make_genocode_checker(genocode: dict) -> Callable[[int, str, str], Optional[InvalidValue]]:
+def make_genocode_checker(genocode: dict, filename: str) -> Callable[
+ [int, str, str], Optional[InvalidValue]]:
"""Make a checker from the genotypes in the control data"""
def __checker__(lineno: int, field: str, value: str) -> Optional[InvalidValue]:
genotypes = tuple(genocode.keys())
if value not in genotypes:
- return InvalidValue(lineno, field, value, (
+ return InvalidValue(filename, lineno, field, value, (
f"Invalid value '{value}'. Expected one of {genotypes}."))
return None
return __checker__
@@ -78,14 +79,15 @@ def geno_errors(zfile: ZipFile) -> Iterator[Union[InvalidValue, MissingFile]]:
cdata = rqtl2.control_data(zfile)
return (
error for error in retrieve_errors(
- zfile, "geno", (make_genocode_checker(cdata.get("genotypes", {})),))
+ zfile, "geno", (make_genocode_checker(cdata.get("genotypes", {}), "geno"),))
if error is not None)
def pheno_errors(zfile: ZipFile) -> Iterator[Union[InvalidValue, MissingFile]]:
"""Check for and retrieve pheno errors."""
return (
error for error in retrieve_errors(
- zfile, "pheno", (partial(decimal_points_error, mini=3),))
+ zfile, "pheno", (partial(
+ decimal_points_error, mini=3, filename="pheno"),))
if error is not None)
def phenose_errors(zfile: ZipFile) -> Iterator[Union[InvalidValue, MissingFile]]:
@@ -108,7 +110,7 @@ def retrieve_errors(zfile: ZipFile, filetype: str, checkers: tuple[Callable]) ->
continue
if value is not None:
for checker in checkers:
- yield checker(lineno, field, value)
+ yield checker(lineno=lineno, field=field, value=value)
except rqe.MissingFileError:
fname = cdata.get(filetype)
yield MissingFile(filetype, fname, f"Missing '{filetype}' file '{fname}'.")