From 8595c75345fb5849a4d8894f3ee7a926dd8cdf8f Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 8 Jan 2024 07:25:35 +0300 Subject: Upload R/qtl2 zip bundle and check for errors. --- r_qtl/r_qtl2.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'r_qtl') 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 -- cgit v1.2.3