From 7b94f989bcfbf6543bfa628422331adfa3d5daac Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Wed, 24 Mar 2021 16:18:00 +0300 Subject: Add extra procedure for parsing a genotype file * gn3/computations/parsers.py (parse_genofile): New procedure. * tests/unit/computations/test_parsers.py: New test files for above. --- tests/unit/computations/test_parsers.py | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/unit/computations/test_parsers.py (limited to 'tests') diff --git a/tests/unit/computations/test_parsers.py b/tests/unit/computations/test_parsers.py new file mode 100644 index 0000000..19c3067 --- /dev/null +++ b/tests/unit/computations/test_parsers.py @@ -0,0 +1,54 @@ +"""Test cases for procedures defined in computations.parsers""" +import unittest +import os + +from gn3.computations.parsers import parse_genofile + + +class TestParsers(unittest.TestCase): + """Test cases for some various parsers""" + + def test_parse_genofile_without_existing_file(self): + """Assert that an error is raised if the genotype file is absent""" + self.assertRaises(FileNotFoundError, parse_genofile, + "/non-existent-file") + + def test_parse_genofile_with_existing_file(self): + """Test that a genotype file is parsed correctly""" + strains = ["bxd1", "bxd2"] + genotypes = [ + {"chr": "1", "locus": "rs31443144", + "cm": "1.50", "mb": "3.010274", + "values": [-1, -1], + "dicvalues": {'bxd1': -1, 'bxd2': -1}}, + {"chr": "2", "locus": "rs27644551", + "cm": "93.26", "mb": "173.542999", + "values": [1, 1], + "dicvalues": {'bxd1': 1, 'bxd2': 1}}, + {"chr": "3", "locus": "rs31187985", + "cm": "17.12", "mb": "41.921845", + "values": [1, 1], + "dicvalues": {'bxd1': 1, 'bxd2': 1}}, + {"chr": "4", "locus": "rs30254612", + "cm": "2.15", "mb": "3.718812", + "values": [-1, 1], + "dicvalues": {'bxd1': -1, 'bxd2': 1}}, + {"chr": "5", "locus": "UNCHS047057", + "cm": "3.10", "mb": "4.199559", + "values": [-1, -1], + "dicvalues": {'bxd1': -1, 'bxd2': -1}}, + {"chr": "X", "locus": "ChrXp_no_data", + "cm": "1.40", "mb": "3.231738", + "values": [1, -1], + "dicvalues": {'bxd1': 1, 'bxd2': -1}}, + {"chr": "X", "locus": "Affy_17539964", + "cm": "1.40", "mb": "7.947581", + "values": [1, -1], + "dicvalues": {'bxd1': 1, 'bxd2': -1}}, + ] + test_genotype_file = os.path.abspath(os.path.join( + os.path.dirname(__file__), + "../test_data/genotype.txt" + )) + self.assertEqual(parse_genofile( + test_genotype_file), (strains, genotypes)) -- cgit v1.2.3