aboutsummaryrefslogtreecommitdiff
path: root/r_qtl
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-09 09:50:18 +0300
committerFrederick Muriuki Muriithi2024-01-09 09:50:18 +0300
commit5491da18dda8c6f55bc2bc5d95f21b86908cd382 (patch)
tree6f8224a9056e18b855a2240ae0b8dd24c02f10a5 /r_qtl
parentb3f5a89aca45a3e803e7bc3b2ee1a3d048801eee (diff)
downloadgn-uploader-5491da18dda8c6f55bc2bc5d95f21b86908cd382.tar.gz
Raise exception on reading non-existing file
The validation checks ensure that whatever files are listed in the control file exist in the zip file bundle. It is still possible, however, that the code tries to read a file that does not exist in the file and is not listed in the control file. In those cases, raise the appropriate exception.
Diffstat (limited to 'r_qtl')
-rw-r--r--r_qtl/r_qtl2.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py
index a8958a0..d3a3805 100644
--- a/r_qtl/r_qtl2.py
+++ b/r_qtl/r_qtl2.py
@@ -189,23 +189,26 @@ def file_data(zfile: ZipFile,
[str, tuple[str, ...], tuple[str, ...]],
tuple[dict, ...]] = __default_process_value_transposed__) -> Iterator[dict]:
"""Load data from files in R/qtl2 zip bundle."""
- if isinstance(cdata[member_key], list):
- for row in (line for lines in
- (file_data(
- zfile, member_key, {**cdata, member_key: innerfile},
- process_value, process_transposed_value)
- for innerfile in cdata[member_key])
- for line in lines):
- yield row
- return
- if not cdata.get(f"{member_key}_transposed", False):
- for row in with_non_transposed(zfile, member_key, cdata, process_value):
- yield row
- return
+ try:
+ if isinstance(cdata[member_key], list):
+ for row in (line for lines in
+ (file_data(
+ zfile, member_key, {**cdata, member_key: innerfile},
+ process_value, process_transposed_value)
+ for innerfile in cdata[member_key])
+ for line in lines):
+ yield row
+ return
+ if not cdata.get(f"{member_key}_transposed", False):
+ for row in with_non_transposed(zfile, member_key, cdata, process_value):
+ yield row
+ return
- for row in with_transposed(
- zfile, member_key, cdata, process_transposed_value):
- yield row
+ for row in with_transposed(
+ zfile, member_key, cdata, process_transposed_value):
+ yield row
+ except KeyError as exc:
+ raise InvalidFormat(*exc.args) from exc
def cross_information(zfile: ZipFile, cdata: dict) -> Iterator[dict]:
"""Load cross information where present."""