diff options
| author | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-10-01 12:37:08 -0500 |
|---|---|---|
| committer | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-10-01 13:02:44 -0500 |
| commit | c04b75c5904bb30bd672e295ab66bbe670520c87 (patch) | |
| tree | 743794ea970f671ed8d440a9f6d9133c45f0b2cd /scripts/genotypes | |
| parent | 27ca6bc0677cc3ccfcfe4203e07f2dd9b5ac8889 (diff) | |
| download | gn-uploader-c04b75c5904bb30bd672e295ab66bbe670520c87.tar.gz | |
Fix type errors.
Diffstat (limited to 'scripts/genotypes')
| -rw-r--r-- | scripts/genotypes/preprocess_csv_collect_info.py | 40 | ||||
| -rw-r--r-- | scripts/genotypes/types.py | 3 |
2 files changed, 23 insertions, 20 deletions
diff --git a/scripts/genotypes/preprocess_csv_collect_info.py b/scripts/genotypes/preprocess_csv_collect_info.py index 2d76021..da5e904 100644 --- a/scripts/genotypes/preprocess_csv_collect_info.py +++ b/scripts/genotypes/preprocess_csv_collect_info.py @@ -2,8 +2,8 @@ import sys import logging from pathlib import Path -from typing import Iterator from dataclasses import asdict +from typing import Union, Iterator from argparse import Namespace, ArgumentParser from gn_libs.cli import SysExit @@ -29,7 +29,8 @@ def identify_columns( settings: dict[str, str] ) -> FieldsIdentity: """Identify columns using settings provided by user""" - _id = {} + _id: dict[str, Union[str, str]] = {} + _samples: tuple[str, ...] = tuple() for header in headers: if header.lower() == settings["markers"].lower(): _id["marker"] = header @@ -46,9 +47,9 @@ def identify_columns( _id["physical_distance"] = header continue - _id["samples"] = _id.get("samples", tuple()) + (header,) + _samples = _samples + (header,) - return FieldsIdentity(**_id) + return FieldsIdentity(**_id, samples=_samples) def process_transposed(line: tuple[str, ...], na_strings: tuple[str, ...]) -> LineDetails: @@ -76,30 +77,35 @@ def process_untransposed( def file_statistics(lines: Iterator[str], fileconfigs: dict) -> FileStats: """Compute file statistics from the lines in the file.""" - stats = {} - col_ids = tuple() + stats: dict = { + "data_lines": 0, + "total_lines": 0, + "blank_lines": 0, + "comment_lines": 0, + "dot_geno_lines": 0 + } dotgeno = {} headers: tuple[str, ...] = tuple() genosymbols: set[str] = set() # errors: tuple() for line in lines: - stats["total_lines"] = stats.get("total_lines", 0) + 1 + stats["total_lines"] = stats["total_lines"] + 1 _line = line.strip() if _line == "": - stats["blank_lines"] = stats.get("blank_lines", 0) + 1 + stats["blank_lines"] = stats["blank_lines"] + 1 continue if _line.startswith(fileconfigs["comment.char"]): - stats["comment_lines"] = stats.get("comment_lines", 0) + 1 + stats["comment_lines"] = stats["comment_lines"] + 1 continue if _line.startswith("@"): # custom GeneNetwork Settings - stats["dot_geno_lines"] = stats.get("dot_geno_lines", 0) + 1 + stats["dot_geno_lines"] = stats["dot_geno_lines"] + 1 _fld = tuple(item.strip() for item in line.strip("@").split(":")) dotgeno[_fld[0]] = _fld[1] continue - stats["data_lines"] = stats.get("data_lines", 0) + 1 + stats["data_lines"] = stats["data_lines"] + 1 fields: tuple[str, ...] = tuple( fld.strip() for fld in line.split(fileconfigs["separator"])) @@ -117,7 +123,7 @@ def file_statistics(lines: Iterator[str], fileconfigs: dict) -> FileStats: headers = fields # First line ***IS** headers' line! continue # ELSE: File **IS** transposed. - headers = headers + (fields[0]) + headers = headers + (fields[0],) continue line_dets = ( @@ -131,7 +137,7 @@ def file_statistics(lines: Iterator[str], fileconfigs: dict) -> FileStats: headers=headers)) if fileconfigs["transposed"]: - headers = headers + (line_dets.header) + headers = headers + (line_dets.line_header,) genosymbols.update(line_dets.geno_symbols) # TODO: do more processing @@ -140,11 +146,9 @@ def file_statistics(lines: Iterator[str], fileconfigs: dict) -> FileStats: col_ids = identify_columns(headers, fileconfigs) return FileStats( **stats, - **({"dot_geno_fields": DotGenoFields(**dotgeno)} - if bool(dotgeno) - else {}), - samples_list=col_ids.samples, - geno_symbols=tuple(genosymbols)) + geno_symbols=tuple(genosymbols), + dot_geno_fields=(DotGenoFields(**dotgeno) if bool(dotgeno) else None), + samples_list=col_ids.samples) if __name__ == "__main__": diff --git a/scripts/genotypes/types.py b/scripts/genotypes/types.py index bf46606..482d8d4 100644 --- a/scripts/genotypes/types.py +++ b/scripts/genotypes/types.py @@ -29,7 +29,7 @@ class LineDetails: """Data type for processed line details""" line_content: Sequence[Union[str, None]] geno_symbols: Sequence[str] - line_header: Optional[str] = None + line_header: str @dataclass(frozen=True) @@ -52,7 +52,6 @@ class FileStats:# pylint: disable=[too-many-instance-attributes] comment_lines: int = 0 dot_geno_lines: int = 0 dot_geno_fields: Optional[DotGenoFields] = None - samples: Sequence[str] = field(default_factory=tuple) samples_list: Sequence[str] = field(default_factory=tuple) markers_list: Sequence[str] = field(default_factory=tuple) errors: Sequence[LineError] = field(default_factory=tuple) |
