aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-02-09 16:12:45 +0300
committerFrederick Muriuki Muriithi2024-02-12 18:17:39 +0300
commitb7eb549bb02eaba22ba06b0ddf5d04c9b4fe0f66 (patch)
tree6566c114021684a18bdb8dd3e15bbbd125471d10
parent34eab8a50ce185aaf786fd7138a3bd0b7c5b0576 (diff)
downloadgn-uploader-b7eb549bb02eaba22ba06b0ddf5d04c9b4fe0f66.tar.gz
Extract missing files check to external function
-rw-r--r--scripts/qc_on_rqtl2_bundle.py24
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