aboutsummaryrefslogtreecommitdiff
path: root/r_qtl
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-08 07:25:35 +0300
committerFrederick Muriuki Muriithi2024-01-08 07:25:35 +0300
commit8595c75345fb5849a4d8894f3ee7a926dd8cdf8f (patch)
treeee4a18e3aed146028b5a9463ecc2d5c12252d81c /r_qtl
parentea89a07e6d04c2fe58f94839eb9916b365b2f3f2 (diff)
downloadgn-uploader-8595c75345fb5849a4d8894f3ee7a926dd8cdf8f.tar.gz
Upload R/qtl2 zip bundle and check for errors.
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