aboutsummaryrefslogtreecommitdiff
path: root/r_qtl
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-10-14 13:18:56 -0500
committerFrederick Muriuki Muriithi2024-10-14 13:27:43 -0500
commit57fa9c35d25a7ca5e8d7e3fc021f12cecef06a60 (patch)
tree90684ed9f5d976c3d4a9b870dcbf9f4e74b679f1 /r_qtl
parent3062921c9436a351a34f7ebe523c5f4fa2bac856 (diff)
downloadgn-uploader-57fa9c35d25a7ca5e8d7e3fc021f12cecef06a60.tar.gz
Improve error messages for R/qtl2 code.
Diffstat (limited to 'r_qtl')
-rw-r--r--r_qtl/r_qtl2.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py
index 9da4081..d7d81d1 100644
--- a/r_qtl/r_qtl2.py
+++ b/r_qtl/r_qtl2.py
@@ -18,6 +18,10 @@ FILE_TYPES = (
"geno", "founder_geno", "pheno", "covar", "phenocovar", "gmap", "pmap",
"phenose")
+__CONTROL_FILE_ERROR_MESSAGE__ = (
+ "The zipped bundle that was provided does not contain a valid control file "
+ "in either JSON or YAML format.")
+
def __special_file__(filename):
"""
@@ -112,7 +116,7 @@ def __control_data_from_zipfile__(zfile: ZipFile) -> dict:
or filename.endswith(".json"))))
num_files = len(files)
if num_files == 0:
- raise InvalidFormat("Expected a json or yaml control file.")
+ raise InvalidFormat(__CONTROL_FILE_ERROR_MESSAGE__)
if num_files > 1:
raise InvalidFormat("Found more than one possible control file.")
@@ -129,7 +133,6 @@ def __control_data_from_zipfile__(zfile: ZipFile) -> dict:
else yaml.safe_load(zfile.read(files[0])))
}
-
def __control_data_from_dirpath__(dirpath: Path):
"""Load control data from a given directory path."""
files = tuple(path for path in dirpath.iterdir()
@@ -137,7 +140,7 @@ def __control_data_from_dirpath__(dirpath: Path):
and (path.suffix in (".yaml", ".json"))))
num_files = len(files)
if num_files == 0:
- raise InvalidFormat("Expected a json or yaml control file.")
+ raise InvalidFormat(__CONTROL_FILE_ERROR_MESSAGE__)
if num_files > 1:
raise InvalidFormat("Found more than one possible control file.")
@@ -200,8 +203,8 @@ def control_data(control_src: Union[Path, ZipFile]) -> dict:
if control_src.is_dir():
return __cleanup__(__control_data_from_dirpath__(control_src))
raise InvalidFormat(
- "Expects either a zipfile.ZipFile object or a pathlib.Path object "
- "pointing to a directory containing the R/qtl2 bundle.")
+ "Expects either a zipped bundle of files or a path-like object "
+ "pointing to the zipped R/qtl2 bundle.")
def replace_na_strings(cdata, val):