aboutsummaryrefslogtreecommitdiff
path: root/r_qtl
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-02-12 13:03:35 +0300
committerFrederick Muriuki Muriithi2024-02-12 18:17:42 +0300
commit092ae35512b3ef236622c4ab9dfe2bafb221ded7 (patch)
tree276d985f68b89051ed031486cac0b233b9345eec /r_qtl
parent68696caeedde3636aff34db048a4490fbf51edf3 (diff)
downloadgn-uploader-092ae35512b3ef236622c4ab9dfe2bafb221ded7.tar.gz
Refactor: Use new decimal places checker.
Diffstat (limited to 'r_qtl')
-rw-r--r--r_qtl/r_qtl2_qc.py26
1 files changed, 4 insertions, 22 deletions
diff --git a/r_qtl/r_qtl2_qc.py b/r_qtl/r_qtl2_qc.py
index f62f142..aa5c81e 100644
--- a/r_qtl/r_qtl2_qc.py
+++ b/r_qtl/r_qtl2_qc.py
@@ -1,7 +1,6 @@
"""Quality control checks for R/qtl2 data bundles."""
-import re
from zipfile import ZipFile
-from functools import reduce
+from functools import reduce, partial
from typing import Union, Iterator, Optional, Callable
from r_qtl import errors as rqe
@@ -10,6 +9,7 @@ from r_qtl.r_qtl2 import __FILE_TYPES__
from r_qtl.fileerrors import MissingFile
from quality_control.errors import InvalidValue
+from quality_control.checks import decimal_points_error
def bundle_files_list(cdata: dict) -> tuple[tuple[str, str], ...]:
"""Retrieve files listed in control file."""
@@ -83,34 +83,16 @@ def geno_errors(zfile: ZipFile) -> Iterator[Union[InvalidValue, MissingFile]]:
def pheno_errors(zfile: ZipFile) -> Iterator[Union[InvalidValue, MissingFile]]:
"""Check for and retrieve pheno errors."""
- def __min_3_decimal_places__(
- lineno: int, field: str, value: str) -> Optional[InvalidValue]:
- if not (re.search(r"^([0-9]+\.[0-9]{3,}|[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 3 decimal places."))
- return None
return (
error for error in retrieve_errors(
- zfile, "pheno", (__min_3_decimal_places__,))
+ zfile, "pheno", (partial(decimal_points_error, mini=3),))
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__,))
+ zfile, "phenose", (partial(decimal_points_error, mini=6),))
if error is not None)
def retrieve_errors(zfile: ZipFile, filetype: str, checkers: tuple[Callable]) -> Iterator[