diff options
-rw-r--r-- | r_qtl/r_qtl2.py | 5 | ||||
-rw-r--r-- | tests/r_qtl/test_files/empty_control_file_json.zip | bin | 0 -> 251 bytes | |||
-rw-r--r-- | tests/r_qtl/test_files/empty_control_file_yaml.zip | bin | 0 -> 245 bytes | |||
-rw-r--r-- | tests/r_qtl/test_r_qtl2_control_file.py | 38 |
4 files changed, 43 insertions, 0 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py index 1755a05..9127dce 100644 --- a/r_qtl/r_qtl2.py +++ b/r_qtl/r_qtl2.py @@ -28,6 +28,11 @@ def control_data(zfile: ZipFile) -> dict: "na.strings": ["NA"], "comment.char": "#", "sep": ",", + **{ + f"{key}_transposed": False for key in ( + "geno", "founder_geno", "pheno", "covar", "phenocovar", "gmap", + "pmap", "phenose") + }, **(json.loads(zfile.read(files[0])) if files[0].endswith(".json") else yaml.safe_load(zfile.read(files[0]))) diff --git a/tests/r_qtl/test_files/empty_control_file_json.zip b/tests/r_qtl/test_files/empty_control_file_json.zip Binary files differnew file mode 100644 index 0000000..94cab39 --- /dev/null +++ b/tests/r_qtl/test_files/empty_control_file_json.zip diff --git a/tests/r_qtl/test_files/empty_control_file_yaml.zip b/tests/r_qtl/test_files/empty_control_file_yaml.zip Binary files differnew file mode 100644 index 0000000..daf607f --- /dev/null +++ b/tests/r_qtl/test_files/empty_control_file_yaml.zip diff --git a/tests/r_qtl/test_r_qtl2_control_file.py b/tests/r_qtl/test_r_qtl2_control_file.py new file mode 100644 index 0000000..316307d --- /dev/null +++ b/tests/r_qtl/test_r_qtl2_control_file.py @@ -0,0 +1,38 @@ +"""Test the parsing of control file""" +from pathlib import Path + +import pytest +from zipfile import ZipFile + +from r_qtl import r_qtl2 as rqtl2 + +__DEFAULTS__ = { + "description": "Empty control file to test defaults", + "sep": ",", + "na.strings": ["NA"], + "comment.char": "#", + "geno_transposed": False, + "founder_geno_transposed": False, + "pheno_transposed": False, + "covar_transposed": False, + "phenocovar_transposed": False, + "gmap_transposed": False, + "pmap_transposed": False, + "phenose_transposed": False +} + +@pytest.mark.unit_test +@pytest.mark.parametrize( + "filepath,expected", + (("tests/r_qtl/test_files/empty_control_file_yaml.zip", + __DEFAULTS__), + ("tests/r_qtl/test_files/empty_control_file_json.zip", + __DEFAULTS__))) +def test_defaults_are_set(filepath, expected): + """ + GIVEN: path to a R/qtl2 bundle with an empty control file + WHEN: the control data is parsed + THEN: ensure all the defaults are set up correctly + """ + with ZipFile(Path(filepath).absolute(), "r") as zfile: + assert rqtl2.control_data(zfile) == expected |