diff options
Diffstat (limited to 'scripts/qc_on_rqtl2_bundle.py')
-rw-r--r-- | scripts/qc_on_rqtl2_bundle.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/scripts/qc_on_rqtl2_bundle.py b/scripts/qc_on_rqtl2_bundle.py index 8dd6b7e..63729b4 100644 --- a/scripts/qc_on_rqtl2_bundle.py +++ b/scripts/qc_on_rqtl2_bundle.py @@ -1,9 +1,10 @@ """Run Quality Control checks on R/qtl2 bundle.""" import sys import json -from typing import Sequence +from pathlib import Path from zipfile import ZipFile from argparse import Namespace +from typing import Union, Sequence from logging import Logger, getLogger, StreamHandler from redis import Redis @@ -26,12 +27,11 @@ def add_to_errors(rconn: Redis, fqjobid: str, key: str, errors: Sequence[rqfe.Mi [error.message for error in errors])) rconn.hset(fqjobid, key, json.dumps(errs)) -def run_qc(rconn: Redis, args: Namespace, logger: Logger) -> int: - """Run the QC programs.""" - fqjobid = jobs.job_key(args.redisprefix, args.jobid) - thejob = parse_job(rconn, args.redisprefix, args.jobid) - meta = thejob["job-metadata"] - with ZipFile(meta["rqtl2-bundle-file"], "r") as zfile: +def qc_missing_files(rconn: Redis, fqjobid: str, + bundlefilepath: Union[str, Path]) -> tuple[ + tuple[str, str], ...]: + """Run QC for files listed in control file that don't exist in bundle.""" + with ZipFile(str(bundlefilepath), "r") as zfile: missing = rqc.missing_files(zfile) add_to_errors(rconn, fqjobid, "errors-generic", tuple( rqfe.MissingFile( @@ -41,7 +41,15 @@ def run_qc(rconn: Redis, args: Namespace, logger: Logger) -> int: "the bundle.")) for mfile in missing)) - if len(missing) > 0: + return missing + +def run_qc(rconn: Redis, args: Namespace, logger: Logger) -> int: + """Run the QC programs.""" + fqjobid = jobs.job_key(args.redisprefix, args.jobid) + thejob = parse_job(rconn, args.redisprefix, args.jobid) + jobmeta = thejob["job-metadata"] + + if len(qc_missing_files(rconn, fqjobid, jobmeta["rqtl2-bundle-file"])) > 0: logger.error("Missing files in the bundle!") return 1 |