diff options
| author | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-10-01 13:27:25 -0500 |
|---|---|---|
| committer | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-10-01 13:29:01 -0500 |
| commit | 6bc474f2fda1dec8e411d5c3ce82a292a8de2a88 (patch) | |
| tree | 2cde696eb09334f1ac4a8f7af585d8aca05b6b40 /scripts | |
| parent | c04b75c5904bb30bd672e295ab66bbe670520c87 (diff) | |
| download | gn-uploader-6bc474f2fda1dec8e411d5c3ce82a292a8de2a88.tar.gz | |
Handle line-level errors.
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/genotypes/preprocess_csv_collect_info.py | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/scripts/genotypes/preprocess_csv_collect_info.py b/scripts/genotypes/preprocess_csv_collect_info.py index da5e904..675a0e5 100644 --- a/scripts/genotypes/preprocess_csv_collect_info.py +++ b/scripts/genotypes/preprocess_csv_collect_info.py @@ -12,7 +12,11 @@ from scripts.cli.options import add_logging from scripts.cli.logging import setup_logging from scripts.cli.validators import file_exists -from .types import FileStats, LineDetails, DotGenoFields, FieldsIdentity +from .types import (FileStats, + LineError, + LineDetails, + DotGenoFields, + FieldsIdentity) logger = logging.getLogger(__name__) @@ -63,16 +67,34 @@ def process_untransposed( headers: tuple[str, ...] ) -> LineDetails: """Processed line in a non-transposed file.""" + _errors: tuple[LineError, ...] = tuple() _symbols = tuple(_symb for _head, _symb in zip(headers, line) if _head not in ( settings["markers"], settings["chromosome"], settings["cm"], settings["mb"])) + + try: + _idx = headers.index(settings["markers"]) + except ValueError as _verr: + _idx = 0 + + if len(headers) != len(line): + _errors = _errors + (LineError( + row_header=line[_idx], + column_header="-", + message=( + f"Columns mismatch: There are {len(headers)} headers but only " + f"{len(line)} field values in the line."), + line=line + ),) + return LineDetails( line_content=line, line_header=line[0], - geno_symbols=tuple(set(_symbols))) + geno_symbols=tuple(set(_symbols)), + errors=_errors) def file_statistics(lines: Iterator[str], fileconfigs: dict) -> FileStats: @@ -87,7 +109,7 @@ def file_statistics(lines: Iterator[str], fileconfigs: dict) -> FileStats: dotgeno = {} headers: tuple[str, ...] = tuple() genosymbols: set[str] = set() - # errors: tuple() + _errors: tuple[LineError, ...] = tuple() for line in lines: stats["total_lines"] = stats["total_lines"] + 1 _line = line.strip() @@ -135,6 +157,7 @@ def file_statistics(lines: Iterator[str], fileconfigs: dict) -> FileStats: fields, fileconfigs, headers=headers)) + _errors = _errors + tuple(line_dets.errors) if fileconfigs["transposed"]: headers = headers + (line_dets.line_header,) @@ -148,7 +171,8 @@ def file_statistics(lines: Iterator[str], fileconfigs: dict) -> FileStats: **stats, geno_symbols=tuple(genosymbols), dot_geno_fields=(DotGenoFields(**dotgeno) if bool(dotgeno) else None), - samples_list=col_ids.samples) + samples_list=col_ids.samples, + errors=_errors) if __name__ == "__main__": |
