From 0165fa73fb092960c472c4baab16c164f9f55ccf Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 3 Dec 2024 16:05:05 -0600 Subject: Update file metadata using a mapping Update the metadata using a mapping rather than updating a field at a time to make it easier to ensure everything is updated in one go. --- scripts/rqtl2/phenotypes_qc.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/scripts/rqtl2/phenotypes_qc.py b/scripts/rqtl2/phenotypes_qc.py index 7a52d09..f539cad 100644 --- a/scripts/rqtl2/phenotypes_qc.py +++ b/scripts/rqtl2/phenotypes_qc.py @@ -213,12 +213,21 @@ def qc_phenocovar_file( _line["description"], "The description is not provided!")),) + rconn.hset(file_fqkey(fqkey, "metadata", filepath), + mapping={ + "status": "checking", + "linecount": _lc+1, + "total-errors": len(_errs) + }) return _errs, _lc+1 _errors, _linecount = reduce(collect_errors, _csvfile, (_errors, 1)) - rconn.hset( - f"{fqkey}:metadata", - mapping={"linecount": _linecount, "total-errors": len(_errors)}) + rconn.hset(file_fqkey(fqkey, "metadata", filepath), + mapping={ + "status": "completed", + "linecount": _linecount, + "total-errors": len(_errors) + }) return {filepath.name: {"errors": _errors, "linecount": _linecount}} @@ -316,14 +325,22 @@ def qc_pheno_file(# pylint: disable=[too-many-arguments] value) _errs = _errs + ((save_error(_err),) if bool(_err) else tuple()) - rconn.hset(f"{fqkey}:metadata", "linecount", _lc+1) - rconn.hset(f"{fqkey}:metadata", "total-errors", len(_errs)) + rconn.hset(file_fqkey(fqkey, "metadata", filepath), + mapping={ + "status": "checking", + "linecount": _lc+1, + "total-errors": len(_errs) + }) return _errs, _lc+1 - logger.debug(f"[{filepath.name}] Collecting errors") _errors, _linecount = reduce(collect_errors, _csvfile, (_errors, 1)) - logger.debug(f"[{filepath.name}] Finished collecting errors. Returning results …") - return {filepath.name: {"errors": _errors, "linecount": linecount}} + rconn.hset(file_fqkey(fqkey, "metadata", filepath), + mapping={ + "status": "completed", + "linecount": _linecount, + "total-errors": len(_errors) + }) + return {filepath.name: {"errors": _errors, "linecount": _linecount}} def phenotype_names(filepath: Path, -- cgit v1.2.3