From fc27d0447c189bfd9222c7e8ccc14074cfd6adce Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 16 Jan 2024 06:29:13 +0300 Subject: Provide defaults for various control variables `na.strings` has a default value of "NA" as stated in https://kbroman.org/qtl2/assets/vignettes/input_files.html#CSV_files quote: > Missing value codes will be specified in the control file (as > na.strings, with default value "NA") and will apply across all > files, so a missing value code for one file cannot be an allowed > value in another file. for `comment.char` > The CSV files can include a header with a set of comment lines > initiated by a value specified in the control file as comment.char > (with default value "#"). for `sep`: The default separator is expected to be the comma, as stated in https://kbroman.org/qtl2/assets/vignettes/input_files.html#field-separator quote: > If the data files use a separator other than a comma ... --- r_qtl/r_qtl2.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'r_qtl') diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py index 13ac355..1755a05 100644 --- a/r_qtl/r_qtl2.py +++ b/r_qtl/r_qtl2.py @@ -24,16 +24,18 @@ def control_data(zfile: ZipFile) -> dict: if num_files > 1: raise InvalidFormat("Found more than one possible control file.") - return (json.loads(zfile.read(files[0])) + return { + "na.strings": ["NA"], + "comment.char": "#", + "sep": ",", + **(json.loads(zfile.read(files[0])) if files[0].endswith(".json") else yaml.safe_load(zfile.read(files[0]))) + } def replace_na_strings(cdata, val): """Replace values indicated in `na.strings` with `None`.""" - nastrings = cdata.get("na.strings") - if bool(nastrings): - return (None if val in nastrings else val) - return val + return (None if val in cdata.get("na.strings", ["NA"]) else val) def with_non_transposed(zfile: ZipFile, member_key: str, -- cgit v1.2.3