From 95d2b868adebbc7ebbc2435f9184c30c014ec513 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 3 Jan 2024 16:41:33 +0300 Subject: Parse founder_geno files. Generalise parsing files. * Add tests for parsing "founder_geno" files * Extract common file parsing structure out to more general function * Use generic function to parse "founder_geno" file in test --- tests/r_qtl/test_files/test_founder_geno.zip | Bin 0 -> 672 bytes .../test_files/test_founder_geno_transposed.zip | Bin 0 -> 725 bytes tests/r_qtl/test_r_qtl2_geno.py | 87 +++++++++++++++++++-- 3 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 tests/r_qtl/test_files/test_founder_geno.zip create mode 100644 tests/r_qtl/test_files/test_founder_geno_transposed.zip (limited to 'tests/r_qtl') diff --git a/tests/r_qtl/test_files/test_founder_geno.zip b/tests/r_qtl/test_files/test_founder_geno.zip new file mode 100644 index 0000000..f77626b Binary files /dev/null and b/tests/r_qtl/test_files/test_founder_geno.zip differ diff --git a/tests/r_qtl/test_files/test_founder_geno_transposed.zip b/tests/r_qtl/test_files/test_founder_geno_transposed.zip new file mode 100644 index 0000000..6cc8151 Binary files /dev/null and b/tests/r_qtl/test_files/test_founder_geno_transposed.zip differ diff --git a/tests/r_qtl/test_r_qtl2_geno.py b/tests/r_qtl/test_r_qtl2_geno.py index d323c4b..787d13a 100644 --- a/tests/r_qtl/test_r_qtl2_geno.py +++ b/tests/r_qtl/test_r_qtl2_geno.py @@ -177,11 +177,80 @@ def test_parse_geno_files(relpath, expected): @pytest.mark.unit_test @pytest.mark.parametrize( "relpath,expected", - ( - ("tests/r_qtl/test_files/test_founder_geno.zip", - ()), - ("tests/r_qtl/test_files/test_founder_geno_transposed.zip", - ()))) + (("tests/r_qtl/test_files/test_founder_geno.zip", + (({ + "id": "1", + "PVV4": 1, + "AXR-1": 1, + "HH.335C-Col/PhyA": 1, + "EC.480C": 1, + "EC.66C": 1 + }, { + "id": "2", + "PVV4": 1, + "AXR-1": 1, + "HH.335C-Col/PhyA": 1, + "EC.480C": 1, + "EC.66C": 1 + }, { + "id": "3", + "PVV4": 2, + "AXR-1": 2, + "HH.335C-Col/PhyA": None, + "EC.480C": 1, + "EC.66C": 1 + }, { + "id": "4", + "PVV4": 1, + "AXR-1": 1, + "HH.335C-Col/PhyA": 1, + "EC.480C": 1, + "EC.66C": 1 + }, { + "id": "5", + "PVV4": None, + "AXR-1": 2, + "HH.335C-Col/PhyA": 2, + "EC.480C": 2, + "EC.66C": 2 + }))), + ("tests/r_qtl/test_files/test_founder_geno_transposed.zip", + (({ + "id": "1", + "PVV4": 1, + "AXR-1": 1, + "HH.335C-Col/PhyA": 1, + "EC.480C": 1, + "EC.66C": 1 + }, { + "id": "2", + "PVV4": 1, + "AXR-1": 1, + "HH.335C-Col/PhyA": 1, + "EC.480C": 1, + "EC.66C": 1 + }, { + "id": "3", + "PVV4": 2, + "AXR-1": 2, + "HH.335C-Col/PhyA": None, + "EC.480C": 1, + "EC.66C": 1 + }, { + "id": "4", + "PVV4": 1, + "AXR-1": 1, + "HH.335C-Col/PhyA": 1, + "EC.480C": 1, + "EC.66C": 1 + }, { + "id": "5", + "PVV4": None, + "AXR-1": 2, + "HH.335C-Col/PhyA": 2, + "EC.480C": 2, + "EC.66C": 2 + }))))) def test_parse_founder_geno_files(relpath, expected): """Test parsing of founder_geno files from the R/qtl2 bundle. @@ -190,5 +259,9 @@ def test_parse_founder_geno_files(relpath, expected): THEN: ensure that the data we get is as expected """ with ZipFile(Path(relpath).absolute(), "r") as zfile: - assert tuple(rqtl2.founder_genotype_data( - zfile, rqtl2.control_data(zfile))) == expected + cdata = rqtl2.control_data(zfile) + assert tuple(rqtl2.file_data( + zfile, + "founder_geno", + cdata, + *rqtl2.make_process_data_geno(cdata))) == expected -- cgit v1.2.3