about summary refs log tree commit diff
path: root/scripts/rqtl2/phenotypes_qc.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/rqtl2/phenotypes_qc.py')
-rw-r--r--scripts/rqtl2/phenotypes_qc.py33
1 files changed, 18 insertions, 15 deletions
diff --git a/scripts/rqtl2/phenotypes_qc.py b/scripts/rqtl2/phenotypes_qc.py
index 699c291..9f11f57 100644
--- a/scripts/rqtl2/phenotypes_qc.py
+++ b/scripts/rqtl2/phenotypes_qc.py
@@ -41,7 +41,10 @@ logging.basicConfig(
             "(%(pathname)s: %(lineno)d) %(message)s"))
 logger = logging.getLogger(__MODULE__)
 
-def validate(phenobundle: Path, logger: Logger) -> dict:
+def validate(
+        phenobundle: Path,
+        logger: Logger# pylint: disable=[redefined-outer-name]
+) -> dict:
     """Check that the bundle is generally valid"""
     try:
         rqc.validate_bundle(phenobundle)
@@ -63,7 +66,7 @@ def validate(phenobundle: Path, logger: Logger) -> dict:
 
 def check_for_mandatory_pheno_keys(
         phenobundle: Path,
-        logger: Logger,
+        logger: Logger,# pylint: disable=[redefined-outer-name]
         **kwargs
 ) -> dict:
     """Check that the mandatory keys exist for phenotypes."""
@@ -90,7 +93,7 @@ def check_for_mandatory_pheno_keys(
 
 def check_for_averages_files(
         phenobundle: Path,
-        logger: Logger,
+        logger: Logger,# pylint: disable=[redefined-outer-name]
         **kwargs
 ) -> dict:
     """Check that averages files appear together"""
@@ -144,15 +147,15 @@ def redis_logger(
 ) -> Iterator[logging.Logger]:
     """Build a Redis message-list logger."""
     rconn = Redis.from_url(redisuri, decode_responses=True)
-    logger = logging.getLogger(loggername)
-    logger.propagate = False
+    _logger = logging.getLogger(loggername)
+    _logger.propagate = False
     handler = RedisMessageListHandler(
         rconn,
         fullyqualifiedkey(fqkey, filename))#type: ignore[arg-type]
     handler.setFormatter(logging.getLogger().handlers[0].formatter)
-    logger.addHandler(handler)
+    _logger.addHandler(handler)
     try:
-        yield logger
+        yield _logger
     finally:
         rconn.close()
 
@@ -179,7 +182,7 @@ def qc_phenocovar_file(
             redisuri,
             f"{__MODULE__}.qc_phenocovar_file",
             filepath.name,
-            f"{fqkey}:logs") as logger,
+            f"{fqkey}:logs") as _logger,
           Redis.from_url(redisuri, decode_responses=True) as rconn):
         print("Running QC on file: ", filepath.name)
         _csvfile = rqtl2.read_csv_file(filepath, separator, comment_char)
@@ -199,7 +202,7 @@ def qc_phenocovar_file(
 
         def collect_errors(errors_and_linecount, line):
             _errs, _lc = errors_and_linecount
-            logger.info("Testing record '%s'", line[0])
+            _logger.info("Testing record '%s'", line[0])
             if len(line) != len(_headings):
                 _errs = _errs + (save_error(InvalidValue(
                     filepath.name,
@@ -209,12 +212,12 @@ def qc_phenocovar_file(
                     (f"Record {_lc} in file {filepath.name} has a different "
                      "number of columns than the number of headings"))),)
             _line = dict(zip(_headings, line))
-            if not bool(_line["description"]):
+            if not bool(_line.get("description")):
                 _errs = _errs + (
                     save_error(InvalidValue(filepath.name,
                                             _line[_headings[0]],
                                             "description",
-                                            _line["description"],
+                                            _line.get("description"),
                                             "The description is not provided!")),)
 
             rconn.hset(file_fqkey(fqkey, "metadata", filepath),
@@ -240,7 +243,7 @@ def merge_dicts(*dicts):
     return reduce(lambda merged, dct: {**merged, **dct}, dicts, {})
 
 
-def decimal_points_error(# pylint: disable=[too-many-arguments]
+def decimal_points_error(# pylint: disable=[too-many-arguments,too-many-positional-arguments]
         filename: str,
         rowtitle: str,
         coltitle: str,
@@ -271,7 +274,7 @@ def integer_error(
         return InvalidValue(filename, rowtitle, coltitle, cellvalue, message)
 
 
-def qc_pheno_file(# pylint: disable=[too-many-locals, too-many-arguments]
+def qc_pheno_file(# pylint: disable=[too-many-locals, too-many-arguments, too-many-positional-arguments]
         filepath: Path,
         redisuri: str,
         fqkey: str,
@@ -287,7 +290,7 @@ def qc_pheno_file(# pylint: disable=[too-many-locals, too-many-arguments]
             redisuri,
             f"{__MODULE__}.qc_pheno_file",
             filepath.name,
-            f"{fqkey}:logs") as logger,
+            f"{fqkey}:logs") as _logger,
           Redis.from_url(redisuri, decode_responses=True) as rconn):
         print("Running QC on file: ", filepath.name)
         save_error = partial(
@@ -314,7 +317,7 @@ def qc_pheno_file(# pylint: disable=[too-many-locals, too-many-arguments]
 
         def collect_errors(errors_and_linecount, line):
             _errs, _lc = errors_and_linecount
-            logger.debug("Checking row %s", line[0])
+            _logger.debug("Checking row %s", line[0])
             if line[0] not in samples:
                 _errs = _errs + (save_error(InvalidValue(
                 filepath.name,