about summary refs log tree commit diff
diff options
context:
space:
mode:
authorpi coding agent <pi@localhost>2026-11-04 17:10:59 +0000
committerFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-11-04 11:31:55 -0600
commit9cdd3edc1fe41e32bbdf687d761d31a703757d2d (patch)
tree7a785577cd960a38dcf2b4c7e5e95de2108dc306
parent6112e00f3b7de903426d38ea2af36ac5270ba67f (diff)
downloadgn-uploader-9cdd3edc1fe41e32bbdf687d761d31a703757d2d.tar.gz
Build the collector config from the upload form
Add `uploader.genotypes.collector_config.from_form` to map the upload form's
metadata fields to the statistics collector's config keys (`markers`,
`chromosome`, `cm`, `mb`, `transposed`, `separator`, `comment.char`,
`na_strings`), falling back to the collector's defaults and normalising the
missing-value strings.

Use it in `add_genotype_records` instead of the previous `sep`/`na.strings`
stub metadata.
-rw-r--r--uploader/genotypes/collector_config.py21
-rw-r--r--uploader/genotypes/views.py11
2 files changed, 25 insertions, 7 deletions
diff --git a/uploader/genotypes/collector_config.py b/uploader/genotypes/collector_config.py
new file mode 100644
index 0000000..9132600
--- /dev/null
+++ b/uploader/genotypes/collector_config.py
@@ -0,0 +1,21 @@
+"""Build the genotype statistics collector configuration from the upload form."""
+from typing import Mapping
+
+
+def from_form(form: Mapping[str, str]) -> dict:
+    """Build the statistics collector's config from the upload form.
+
+    The upload form uses its own field names for the metadata; the collector
+    expects a different set of config keys. This maps between them, falling
+    back to the collector's defaults when a field is absent.
+    """
+    return {
+        "markers": form.get("markers_field", "Locus"),
+        "chromosome": form.get("chromosomes_field", "Chr"),
+        "cm": form.get("centimorgans_field", "cM"),
+        "mb": form.get("megabases_field", "Mb"),
+        "separator": form.get("file-separator", ","),
+        "comment.char": form.get("file-comment-char", "#"),
+        "na_strings": form.get("file-na", "- NA N/A").split(),
+        "transposed": (form.get("transposed") or "off") == "on",
+    }
diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py
index 94f90ab..0174a43 100644
--- a/uploader/genotypes/views.py
+++ b/uploader/genotypes/views.py
@@ -28,6 +28,7 @@ from uploader.population.models import population_by_species_and_id
 from uploader.request_checks import with_dataset, with_population
 
 
+from . import collector_config
 from .models import (genotype_markers,
                      genotype_records,
                      genotype_dataset,
@@ -220,12 +221,12 @@ def create_dataset(species: dict, population: dict, **kwargs):# pylint: disable=
 
 def _collect_geno_csv_stats_(
         uploaded_file: Path,
-        csv_meta: dict
+        config: dict
 ) -> dict:
     """Build up the job to collect the genotype CSV file statistics."""
     return {
         "file": uploaded_file,
-        "metadata": csv_meta
+        "metadata": config
     }
 
 
@@ -292,11 +293,7 @@ def add_genotype_records(# pylint: disable=[unused-argument]
     #
     _geno_csv_stats_job = _collect_geno_csv_stats_(
         _geno_file,
-        csv_meta = {
-            "sep": form.get("file-separator", ","),
-            "comment.char": form.get("file-comment-char", "#"),
-            "na.strings": form.get("file-na", "- NA N/A").split(" ")
-        })
+        collector_config.from_form(form))
     #
     # * Stage 02: Establish basic info about the study
     #   - What's the study design?