From 7a3e0fdac498a9d22c6ea8789b42c5c882120e00 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 16 Feb 2024 16:34:11 +0300 Subject: Convert missing value codes to None --- r_qtl/r_qtl2.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'r_qtl') diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py index e4c1894..4f0ab2a 100644 --- a/r_qtl/r_qtl2.py +++ b/r_qtl/r_qtl2.py @@ -306,3 +306,10 @@ def raw_file_data(zipfilepath: Union[str, Path], def strip_comments(rawdata: Iterator[str], commentchar) -> Iterator[str]: """Remove comments from raw text.""" return (line for line in rawdata if not line.startswith(commentchar)) + +def missing_value_codes_to_none(value: str, + nastrings: tuple[str, ...]) -> Optional[str]: + """ + If 'value' is a missing value code, return `None`, otherwise return 'value'. + """ + return value if value not in nastrings else None -- cgit v1.2.3