aboutsummaryrefslogtreecommitdiff
path: root/tests/r_qtl/test_r_qtl2_pheno.py
blob: 554d9c855b5d669676c905dab11702f229de55dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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