"""Normalise a genotype file and run QC for a genotype-file-qc job.""" import sys import json import logging from pathlib import Path from argparse import ArgumentParser from gn_libs import jobs, sqlite3 from uploader.genotypes import normalise, qc logger = logging.getLogger(__name__) def parse_args(): """Parse the command-line arguments.""" parser = ArgumentParser( prog="genotype-file-qc", description="Normalise a genotype file and run QC on it.") parser.add_argument("jobs_db", help="Path to the jobs SQLite database.") parser.add_argument( "qc_job_id", help="The id of the genotype-file-qc job.") parser.add_argument( "--log-level", default="info", choices=("debug", "info", "warning", "error", "critical")) return parser.parse_args() def main(): """Normalise the genotype file, then run QC on it.""" args = parse_args() logging.basicConfig(level=getattr(logging, args.log_level.upper())) with sqlite3.connection(args.jobs_db) as conn: job = jobs.job(conn, args.qc_job_id, fulldetails=True) metadata = job["metadata"] config = json.loads(metadata["config"]) stage02 = json.loads(metadata.get("stage02") or "{}") try: work_file = normalise.normalise_file( Path(metadata["file"]), config) except normalise.NormalisationError as _exc: print(json.dumps({"errors": [{"message": str(_exc)}]})) return 1 result = qc.check_file( work_file, {**config, "transposed": False}, stage02) print(json.dumps(result)) return 0 if not result["errors"] else 1 if __name__ == "__main__": sys.exit(main())