aboutsummaryrefslogtreecommitdiff
path: root/r_qtl
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-16 06:29:13 +0300
committerFrederick Muriuki Muriithi2024-01-16 06:52:28 +0300
commitfc27d0447c189bfd9222c7e8ccc14074cfd6adce (patch)
treefeb36cc9c2fec2461af8a2b621429bbac70c8e0b /r_qtl
parentb7942002b2f40af965bd0ef9c9673fbaeb28a9e1 (diff)
downloadgn-uploader-fc27d0447c189bfd9222c7e8ccc14074cfd6adce.tar.gz
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 ...
Diffstat (limited to 'r_qtl')
-rw-r--r--r_qtl/r_qtl2.py12
1 files changed, 7 insertions, 5 deletions
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,