about summary refs log tree commit diff
diff options
context:
space:
mode:
authorpi coding agent <pi@localhost>2026-11-05 20:09:55 +0000
committerFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-11-05 14:16:31 -0600
commite4ffb00d2f505ba11ec175ada2c85288d80a6050 (patch)
treea3af3dd9bd82e7ac26db04ba09390d1b6eb9d799
parentbe5137651f46fe2d0fd649993efa0fe69b386ec3 (diff)
downloadgn-uploader-e4ffb00d2f505ba11ec175ada2c85288d80a6050.tar.gz
Unify missing-value symbol parsing in r_qtl.utils
Move `parse_missing_values_symbols` from the genotypes views into
`r_qtl.utils` and use it in the genotypes Stage 01 collector config and the
phenotypes individual-file uploads, replacing their divergent inline splits
with the more robust whitespace/comma parsing. Move the tests to
`tests/r_qtl/test_utils.py`.
-rw-r--r--r_qtl/utils.py6
-rw-r--r--tests/r_qtl/test_utils.py (renamed from tests/uploader/genotypes/test_genotype_views.py)2
-rw-r--r--uploader/genotypes/collector_config.py5
-rw-r--r--uploader/genotypes/views.py7
-rw-r--r--uploader/phenotypes/views.py3
5 files changed, 15 insertions, 8 deletions
diff --git a/r_qtl/utils.py b/r_qtl/utils.py
new file mode 100644
index 0000000..bd0c07b
--- /dev/null
+++ b/r_qtl/utils.py
@@ -0,0 +1,6 @@
+"""General utilities for processing R/qtl(2)-related data."""
+
+
+def parse_missing_values_symbols(value: str) -> list[str]:
+    """Parse a whitespace- and/or comma-separated list of unique symbols."""
+    return list(dict.fromkeys(value.replace(",", " ").split()))
diff --git a/tests/uploader/genotypes/test_genotype_views.py b/tests/r_qtl/test_utils.py
index f5c234b..7736b70 100644
--- a/tests/uploader/genotypes/test_genotype_views.py
+++ b/tests/r_qtl/test_utils.py
@@ -1,7 +1,7 @@
 """Tests for the genotype views helpers."""
 import pytest
 
-from uploader.genotypes.views import parse_missing_values_symbols
+from r_qtl.utils import parse_missing_values_symbols
 
 
 @pytest.mark.unit_test
diff --git a/uploader/genotypes/collector_config.py b/uploader/genotypes/collector_config.py
index d7c8fa6..776dcc8 100644
--- a/uploader/genotypes/collector_config.py
+++ b/uploader/genotypes/collector_config.py
@@ -3,6 +3,8 @@ import sys
 from pathlib import Path
 from typing import Any, Mapping
 
+from r_qtl.utils import parse_missing_values_symbols
+
 
 def from_form(form: Mapping[str, str]) -> dict:
     """Build the statistics collector's config from the upload form.
@@ -18,7 +20,8 @@ def from_form(form: Mapping[str, str]) -> dict:
         "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(),
+        "na_strings": parse_missing_values_symbols(
+            form.get("file-na", "- NA N/A")),
         "transposed": (form.get("transposed") or "off") == "on",
     }
 
diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py
index fcae9b0..2154330 100644
--- a/uploader/genotypes/views.py
+++ b/uploader/genotypes/views.py
@@ -33,6 +33,8 @@ from uploader.monadic_requests import make_either_error_handler
 from uploader.population.models import population_by_species_and_id
 from uploader.request_checks import with_dataset, with_population
 
+from r_qtl.utils import parse_missing_values_symbols
+
 
 from . import collector_config
 from . import collector_job
@@ -48,11 +50,6 @@ genotypesbp = Blueprint("genotypes", __name__)
 render_template = make_template_renderer("genotypes")
 
 
-def parse_missing_values_symbols(value: str) -> list[str]:
-    """Parse a whitespace- and/or comma-separated list of unique symbols."""
-    return list(dict.fromkeys(value.replace(",", " ").split()))
-
-
 def collect_genotype_stats_success_handler(job):
     """Proceed to the study design/encoding stage."""
     return redirect(url_for(
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index ff28a6f..a85a442 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -34,6 +34,7 @@ from flask import (flash,
 
 from r_qtl import r_qtl2_qc as rqc
 from r_qtl import exceptions as rqe
+from r_qtl.utils import parse_missing_values_symbols
 
 from uploader import jobs
 from uploader import session
@@ -323,7 +324,7 @@ def process_phenotypes_individual_files(error_uri):
     cdata = {
         "sep": form["file-separator"],
         "comment.char": form["file-comment-character"],
-        "na.strings": form["file-na"].split(" "),
+        "na.strings": parse_missing_values_symbols(form["file-na"]),
     }
     bundlepath = Path(uploads_dir(app),
                       f"{str(uuid.uuid4()).replace('-', '')}.zip")