about summary refs log tree commit diff
path: root/scripts/process_rqtl2_bundle.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/process_rqtl2_bundle.py')
-rw-r--r--scripts/process_rqtl2_bundle.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/scripts/process_rqtl2_bundle.py b/scripts/process_rqtl2_bundle.py
index feb5e19..7b114cf 100644
--- a/scripts/process_rqtl2_bundle.py
+++ b/scripts/process_rqtl2_bundle.py
@@ -2,10 +2,10 @@
 import sys
 import uuid
 import json
-import logging
 import traceback
 from typing import Any
 from pathlib import Path
+from logging import Logger, getLogger, StreamHandler
 
 import MySQLdb as mdb
 from redis import Redis
@@ -20,11 +20,6 @@ from scripts.redis_logger import setup_redis_logger
 from scripts.rqtl2.install_phenos import install_pheno_files
 from scripts.rqtl2.install_genotypes import install_genotypes
 
-stderr_handler = logging.StreamHandler(stream=sys.stderr)
-logger = logging.getLogger("process_rqtl2_bundle")
-logger.setLevel("DEBUG")
-logger.addHandler(stderr_handler)
-
 def safe_json_decode(value: str) -> Any:
     """Safely decode the string values into JSON."""
     try:
@@ -54,7 +49,10 @@ def percent_completion(geno: float, pheno: float) -> float:
     """Compute the total completion percent."""
     return 0.5 * (geno + pheno)
 
-def process_bundle(dbconn: mdb.Connection, rconn: Redis, jobid: uuid.UUID) -> int:
+def process_bundle(dbconn: mdb.Connection,
+                   rconn: Redis,
+                   jobid: uuid.UUID,
+                   logger: Logger) -> int:
     """Process the R/qtl2 bundle."""
     try:
         thejob = parse_job(rconn, jobid)
@@ -69,7 +67,8 @@ def process_bundle(dbconn: mdb.Connection, rconn: Redis, jobid: uuid.UUID) -> in
                 meta["speciesid"],
                 meta["populationid"],
                 meta["geno-dataset-id"],
-                Path(meta["rqtl2-bundle-file"]))
+                Path(meta["rqtl2-bundle-file"]),
+                logger)
             if genoexit != 0:
                 raise Exception("Processing 'geno' file failed.")
             logger.debug(
@@ -83,7 +82,8 @@ def process_bundle(dbconn: mdb.Connection, rconn: Redis, jobid: uuid.UUID) -> in
                 meta["speciesid"],
                 meta["platformid"],
                 meta["probe-dataset-id"],
-                Path(meta["rqtl2-bundle-file"]))
+                Path(meta["rqtl2-bundle-file"]),
+                logger)
             if phenoexit != 0:
                 raise Exception("Processing 'pheno' file failed.")
             logger.debug(
@@ -109,13 +109,17 @@ if __name__ == "__main__":
         check_db(args.databaseuri)
         check_redis(args.redisuri)
 
+        logger = getLogger("process_rqtl2_bundle")
+        logger.addHandler(StreamHandler(stream=sys.stderr))
+        logger.setLevel("DEBUG")
+
         jobid = 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, jobid, f"{str(jobid)}:log-messages", args.redisexpiry))
 
-            exitcode = process_bundle(dbconn, rconn, args.jobid)
+            exitcode = process_bundle(dbconn, rconn, args.jobid, logger)
             rconn.hset(str(args.jobid), "percent", "100")
             return exitcode