From 4bf51a31c251f3d788325c58c8a78f534409f90f Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 3 Jan 2024 10:10:12 +0300 Subject: Parse the phenotype data from the R/qtl2 bundle. --- tests/r_qtl/test_files/test_pheno.zip | Bin 0 -> 485 bytes tests/r_qtl/test_files/test_pheno_transposed.zip | Bin 0 -> 536 bytes tests/r_qtl/test_r_qtl2_pheno.py | 33 +++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 tests/r_qtl/test_files/test_pheno.zip create mode 100644 tests/r_qtl/test_files/test_pheno_transposed.zip create mode 100644 tests/r_qtl/test_r_qtl2_pheno.py (limited to 'tests') diff --git a/tests/r_qtl/test_files/test_pheno.zip b/tests/r_qtl/test_files/test_pheno.zip new file mode 100644 index 0000000..5c709e7 Binary files /dev/null and b/tests/r_qtl/test_files/test_pheno.zip differ diff --git a/tests/r_qtl/test_files/test_pheno_transposed.zip b/tests/r_qtl/test_files/test_pheno_transposed.zip new file mode 100644 index 0000000..9bff030 Binary files /dev/null and b/tests/r_qtl/test_files/test_pheno_transposed.zip differ diff --git a/tests/r_qtl/test_r_qtl2_pheno.py b/tests/r_qtl/test_r_qtl2_pheno.py new file mode 100644 index 0000000..554d9c8 --- /dev/null +++ b/tests/r_qtl/test_r_qtl2_pheno.py @@ -0,0 +1,33 @@ +"""Test parsing of pheno files in a R/qtl2 bundle.""" +from pathlib import Path + +import pytest +from zipfile import ZipFile + +from r_qtl import r_qtl2 as rqtl2 + +@pytest.mark.unit_test +@pytest.mark.parametrize( + "filepath,expected", + (("tests/r_qtl/test_files/test_pheno.zip", + ({"id": "1", "liver": "61.92", "spleen": "153.16"}, + {"id": "2", "liver": "88.33", "spleen": "178.58"}, + {"id": "3", "liver": "58", "spleen": "131.91"}, + {"id": "4", "liver": "78.06", "spleen": "126.13"}, + {"id": "5", "liver": "65.31", "spleen": "181.05"})), + ("tests/r_qtl/test_files/test_pheno_transposed.zip", + ({"id": "1", "liver": "61.92", "spleen": "153.16"}, + {"id": "2", "liver": "88.33", "spleen": "178.58"}, + {"id": "3", "liver": "58", "spleen": "131.91"}, + {"id": "4", "liver": "78.06", "spleen": "126.13"}, + {"id": "5", "liver": "65.31", "spleen": "181.05"})))) +def test_parse_pheno_files(filepath, expected): + """Test parsing of 'pheno' files from the R/qtl2 bundle. + + GIVEN: path to a R/qtl2 bundle + WHEN: the 'pheno' file is parsed + THEN: verify the parsed data is as expected + """ + with ZipFile(Path(filepath).absolute(), "r") as zfile: + assert tuple( + rqtl2.phenotype_data(zfile, rqtl2.control_data(zfile))) == expected -- cgit v1.2.3