"""Build the genotype statistics collector configuration from the upload form.""" 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. 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": parse_missing_values_symbols( form.get("file-na", "- NA N/A")), "transposed": (form.get("transposed") or "off") == "on", } def command( filepath: Path, config: Mapping[str, Any], loglevel: str = "info" ) -> list[str]: """Build the CLI command that collects statistics for ``filepath``.""" _command = [ sys.executable, "-m", "uploader.scripts.genotypes.preprocess_csv_collect_info", "--log-level", loglevel, "--separator", str(config["separator"]), "--comment_char", str(config["comment.char"]), "--markers_field", str(config["markers"]), "--chr_field", str(config["chromosome"]), "--cm_field", str(config["cm"]), "--mb_field", str(config["mb"]), ] if bool(config["transposed"]): _command = _command + ["--is-transposed"] for na_string in config["na_strings"]: _command = _command + ["--na_strings", str(na_string)] return _command + [str(filepath)]