about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-10-01 13:30:51 -0500
committerFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-10-01 13:45:53 -0500
commitd1e99bbec35e7ebbefa9858cc46acbdcc36fc8c7 (patch)
treead5c119744fd3d294f41ffbbe6c67349f0b7c4d5 /scripts
parent6bc474f2fda1dec8e411d5c3ce82a292a8de2a88 (diff)
downloadgn-uploader-d1e99bbec35e7ebbefa9858cc46acbdcc36fc8c7.tar.gz
Add basic header validation.
Validate whether there are columns with the names given on the CLI,
and if not, add a message note to that effect.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/genotypes/preprocess_csv_collect_info.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/scripts/genotypes/preprocess_csv_collect_info.py b/scripts/genotypes/preprocess_csv_collect_info.py
index 675a0e5..026936d 100644
--- a/scripts/genotypes/preprocess_csv_collect_info.py
+++ b/scripts/genotypes/preprocess_csv_collect_info.py
@@ -33,7 +33,12 @@ def identify_columns(
         settings: dict[str, str]
 ) -> FieldsIdentity:
     """Identify columns using settings provided by user"""
-    _id: dict[str, Union[str, str]] = {}
+    _id: dict[str, Union[str, str]] = {
+        "marker": "",
+        "chromosome": "",
+        "genetic_distance": "",
+        "physical_distance": ""
+    }
     _samples: tuple[str, ...] = tuple()
     for header in headers:
         if header.lower() == settings["markers"].lower():
@@ -97,6 +102,32 @@ def process_untransposed(
         errors=_errors)
 
 
+def validate_headers(
+        headers: tuple[str, ...],
+        settings: dict
+) -> tuple[LineError, ...]:
+    """Validate that the headers are correct."""
+    _errors: tuple[LineError, ...] = tuple()
+    _header_descriptions = {
+        "markers": "marker",
+        "chromosome": "chromosome",
+        "cm": "genetic distance (cM)",
+        "mb": "physical location (Mb)"}
+    for _header, _desc in _header_descriptions.items():
+        try:
+            headers.index(settings[_header])
+        except ValueError as _verr:
+            _errors = _errors + (LineError(
+                row_header=headers[0],
+                column_header="-",
+                message=(
+                    f"Header row does not have a '{_desc}' column named "
+                    f"'{settings[_header]}'."),
+                line=headers),)
+
+    return _errors
+
+
 def file_statistics(lines: Iterator[str], fileconfigs: dict) -> FileStats:
     """Compute file statistics from the lines in the file."""
     stats: dict = {
@@ -167,6 +198,8 @@ def file_statistics(lines: Iterator[str], fileconfigs: dict) -> FileStats:
         continue # end of line processing
 
     col_ids = identify_columns(headers, fileconfigs)
+    _errors = validate_headers(headers, fileconfigs) + _errors
+
     return FileStats(
         **stats,
         geno_symbols=tuple(genosymbols),