aboutsummaryrefslogtreecommitdiff
path: root/scripts/qc_on_rqtl2_bundle.py
blob: 5802f3a7b594d6646feed7a4ccd047723eab91d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Run Quality Control checks on R/qtl2 bundle."""
import sys
from logging import getLogger, StreamHandler

from redis import Redis

from qc_app import jobs
from qc_app.db_utils import database_connection
from qc_app.check_connections import check_db, check_redis

from scripts.cli_parser import init_cli_parser
from scripts.redis_logger import setup_redis_logger

def run_qc(_args):
    """Run the QC programs."""
    return 1

if __name__ == "__main__":
    def main():
        """Enter R/qtl2 bundle QC runner."""
        args = init_cli_parser(
            "qc-on-rqtl2-bundle", "Run QC on R/qtl2 bundle.").parse_args()
        check_redis(args.redisuri)
        check_db(args.databaseuri)

        logger = getLogger("qc-on-rqtl2-bundle")
        logger.addHandler(StreamHandler(stream=sys.stderr))
        logger.setLevel("DEBUG")

        fqjobid = jobs.job_key(args.redisprefix, args.jobid)
        with (database_connection(args.databaseuri) as _dbconn,
              Redis.from_url(args.redisuri, decode_responses=True) as rconn):
            logger.addHandler(setup_redis_logger(
                rconn, fqjobid, f"{fqjobid}:log-messages",
                args.redisexpiry))

            exitcode = run_qc(args)
            rconn.hset(
                jobs.job_key(args.redisprefix, args.jobid), "exitcode", exitcode)
            return exitcode

    sys.exit(main())