aboutsummaryrefslogtreecommitdiff
path: root/r_qtl
diff options
context:
space:
mode:
Diffstat (limited to 'r_qtl')
-rw-r--r--r_qtl/r_qtl2.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py
index 2c1e162..a8958a0 100644
--- a/r_qtl/r_qtl2.py
+++ b/r_qtl/r_qtl2.py
@@ -242,3 +242,27 @@ def sex_information(zfile: ZipFile, cdata: dict) -> Iterator[dict]:
yield {
key: thread_op(value, partial(replace_sex_info, cdata=cdata))
for key, value in row.items() if key not in ci_fields}
+
+def validate_bundle(zfile: ZipFile):
+ """Ensure the R/qtl2 bundle is valid."""
+ cdata = control_data(zfile)
+ def __member_exists_p__(zfile, member):
+ if isinstance(member, str):
+ zfile.getinfo(member)
+ else:
+ for inner in member:
+ zfile.getinfo(inner)
+
+ try:
+ for member in (key for key in cdata.keys() if key in (
+ "geno", "founder_geno", "pheno", "covar", "phenocovar", "gmap",
+ "pmap")):
+ __member_exists_p__(zfile, cdata[member])
+
+ if "file" in cdata.get("sex", {}):
+ __member_exists_p__(zfile, cdata["sex"]["file"])
+
+ if "file" in cdata.get("cross_info", {}):
+ __member_exists_p__(zfile, cdata["cross_info"]["file"])
+ except KeyError as kerr:
+ raise InvalidFormat(*kerr.args) from kerr