예제 #1
0
    def testLoadPeople(self):
        #Shouldn't work when wrong delimiter is specified
        thrown = False
        try:
            person = Person.loadPeople("tests/_td/dosage_set_1/set.sample",
                                       delim=",")
        except:
            thrown = True
        self.assertEqual(thrown, True)

        #default load
        people = Person.loadPeople("tests/_td/dosage_set_1/set.sample")
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 5)
        self.assertPerson(people[0], "ID1", "K", "HERO", "male")
        self.assertPerson(people[1], "ID2", "K", "HERO", "female")
        self.assertPerson(people[2], "DI5", "K", "HERO", "male")
        self.assertPerson(people[3], "ID3", "K", "HERO", "female")
        self.assertPerson(people[4], "B1", "L", "T", "female")

        #let's pretend the file header is a person entry
        people = Person.loadPeople("tests/_td/dosage_set_1/set.sample",
                                   skip_header=False)
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 6)
        self.assertPerson(people[0], "ID", "POP", "GROUP", "SEX")
        self.assertPerson(people[1], "ID1", "K", "HERO", "male")
        self.assertPerson(people[2], "ID2", "K", "HERO", "female")
        self.assertPerson(people[3], "DI5", "K", "HERO", "male")
        self.assertPerson(people[4], "ID3", "K", "HERO", "female")
        self.assertPerson(people[5], "B1", "L", "T", "female")
예제 #2
0
    def testLoadPeople(self):
        # Shouldn't work when wrong delimiter is specified
        thrown = False
        try:
            person = Person.loadPeople("tests/_td/dosage_set_1/set.sample", delim=",")
        except:
            thrown = True
        self.assertEqual(thrown, True)

        # default load
        people = Person.loadPeople("tests/_td/dosage_set_1/set.sample")
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 5)
        self.assertPerson(people[0], "ID1", "K", "HERO", "male")
        self.assertPerson(people[1], "ID2", "K", "HERO", "female")
        self.assertPerson(people[2], "DI5", "K", "HERO", "male")
        self.assertPerson(people[3], "ID3", "K", "HERO", "female")
        self.assertPerson(people[4], "B1", "L", "T", "female")

        # let's pretend the file header is a person entry
        people = Person.loadPeople("tests/_td/dosage_set_1/set.sample", skip_header=False)
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 6)
        self.assertPerson(people[0], "ID", "POP", "GROUP", "SEX")
        self.assertPerson(people[1], "ID1", "K", "HERO", "male")
        self.assertPerson(people[2], "ID2", "K", "HERO", "female")
        self.assertPerson(people[3], "DI5", "K", "HERO", "male")
        self.assertPerson(people[4], "ID3", "K", "HERO", "female")
        self.assertPerson(people[5], "B1", "L", "T", "female")
예제 #3
0
    def testPersonLoadFromRowIfFilter(self):
        row1 = ["a", "b", "c", "d"]
        p = Person.loadPersonFromSampleRowIfFilter(
            row1, group_filters=["None", "EUR"], individual_filters=[])
        self.assertPerson(p)

        p = Person.loadPersonFromSampleRowIfFilter(row1,
                                                   group_filters=["EUR"],
                                                   individual_filters=[])
        self.assertIsNone(p)

        p = Person.loadPersonFromSampleRowIfFilter(row1,
                                                   group_filters=["c", "EUR"],
                                                   individual_filters=[])
        self.assertPerson(p)

        p = Person.loadPersonFromSampleRowIfFilter(
            row1,
            group_filters=["c", "EUR"],
            individual_filters=[re.compile("Nope")])
        self.assertIsNone(p)

        p = Person.loadPersonFromSampleRowIfFilter(
            row1,
            group_filters=["c", "EUR"],
            individual_filters=[re.compile("Nope"),
                                re.compile("a")])
        self.assertPerson(p)
예제 #4
0
    def testPersonLoadFromRowIfFilter(self):
        row1 = ["a", "b", "c", "d"]
        p = Person.loadPersonFromSampleRowIfFilter(row1, group_filters=["None", "EUR"], individual_filters=[])
        self.assertPerson(p)

        p = Person.loadPersonFromSampleRowIfFilter(row1, group_filters=["EUR"], individual_filters=[])
        self.assertIsNone(p)

        p = Person.loadPersonFromSampleRowIfFilter(row1, group_filters=["c", "EUR"], individual_filters=[])
        self.assertPerson(p)

        p = Person.loadPersonFromSampleRowIfFilter(
            row1, group_filters=["c", "EUR"], individual_filters=[re.compile("Nope")]
        )
        self.assertIsNone(p)

        p = Person.loadPersonFromSampleRowIfFilter(
            row1, group_filters=["c", "EUR"], individual_filters=[re.compile("Nope"), re.compile("a")]
        )
        self.assertPerson(p)
예제 #5
0
    def testLoadFilteredPeople(self):
        #Shouldn't work when wrong delimiter is specified
        thrown = False
        try:
            person = Person.loadFilteredPeople(
                "tests/_td/dosage_set_1/set.sample", delim=",")
        except:
            thrown = True
        self.assertEqual(thrown, True)

        #default load
        people = Person.loadFilteredPeople("tests/_td/dosage_set_1/set.sample")
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 0)

        people = Person.loadFilteredPeople("tests/_td/dosage_set_1/set.sample",
                                           group_filters=["HERO"])
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 4)
        self.assertPerson(people[0], "ID1", "K", "HERO", "male")
        self.assertPerson(people[1], "ID2", "K", "HERO", "female")
        self.assertPerson(people[2], "DI5", "K", "HERO", "male")
        self.assertPerson(people[3], "ID3", "K", "HERO", "female")

        people = Person.loadFilteredPeople("tests/_td/dosage_set_1/set.sample",
                                           group_filters=["HERO", "T"])
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 5)
        self.assertPerson(people[0], "ID1", "K", "HERO", "male")
        self.assertPerson(people[1], "ID2", "K", "HERO", "female")
        self.assertPerson(people[2], "DI5", "K", "HERO", "male")
        self.assertPerson(people[3], "ID3", "K", "HERO", "female")
        self.assertPerson(people[4], "B1", "L", "T", "female")

        people = Person.loadFilteredPeople("tests/_td/dosage_set_1/set.sample",
                                           group_filters=["T"])
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 1)
        self.assertPerson(people[0], "B1", "L", "T", "female")

        people = Person.loadFilteredPeople(
            "tests/_td/dosage_set_1/set.sample",
            group_filters=["HERO"],
            individual_filters=[re.compile("ID")])
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 3)
        self.assertPerson(people[0], "ID1", "K", "HERO", "male")
        self.assertPerson(people[1], "ID2", "K", "HERO", "female")
        self.assertPerson(people[2], "ID3", "K", "HERO", "female")

        people = Person.loadFilteredPeople(
            "tests/_td/dosage_set_1/set.sample",
            group_filters=["HERO"],
            individual_filters=[re.compile("ID"),
                                re.compile("DI")])
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 4)
        self.assertPerson(people[0], "ID1", "K", "HERO", "male")
        self.assertPerson(people[1], "ID2", "K", "HERO", "female")
        self.assertPerson(people[2], "DI5", "K", "HERO", "male")
        self.assertPerson(people[3], "ID3", "K", "HERO", "female")

        people = Person.loadFilteredPeople(
            "tests/_td/dosage_set_1/set.sample",
            group_filters=["HERO"],
            individual_filters=[re.compile("DI")])
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 1)
        self.assertPerson(people[0], "DI5", "K", "HERO", "male")
예제 #6
0
 def testPersonLoadFromRow(self):
     row = ["a", "b", "c", "d"]
     p = Person.loadPersonFromSampleRow(row)
     self.assertPerson(p)
예제 #7
0
 def testPersonToLine(self):
     p = Person("a", "b", "c", "d")
     l = p.toTextLine()
     self.assertEqual("a b c d", l)
예제 #8
0
    def testBuildFilteredSamples(self):
        if os.path.exists("_test"):
            shutil.rmtree("_test")
        os.makedirs("_test")

        Person.buildFilteredSamples("tests/_td/dosage_set_1/set.sample",
                                    "_test/s.sample")
        expected = ["ID POP GROUP SEX"]
        self.assertSamplesFile("_test/s.sample", expected)

        Person.buildFilteredSamples("tests/_td/dosage_set_1/set.sample",
                                    "_test/s.sample",
                                    group_filters=["HERO"])
        expected = [
            "ID POP GROUP SEX", "ID1 K HERO male", "ID2 K HERO female",
            "DI5 K HERO male", "ID3 K HERO female"
        ]
        self.assertSamplesFile("_test/s.sample", expected)

        Person.buildFilteredSamples("tests/_td/dosage_set_1/set.sample",
                                    "_test/s.sample",
                                    group_filters=["HERO", "T"])
        expected = [
            "ID POP GROUP SEX", "ID1 K HERO male", "ID2 K HERO female",
            "DI5 K HERO male", "ID3 K HERO female", "B1 L T female"
        ]
        self.assertSamplesFile("_test/s.sample", expected)

        Person.buildFilteredSamples("tests/_td/dosage_set_1/set.sample",
                                    "_test/s.sample",
                                    group_filters=["T"])
        expected = ["ID POP GROUP SEX", "B1 L T female"]
        self.assertSamplesFile("_test/s.sample", expected)

        Person.buildFilteredSamples("tests/_td/dosage_set_1/set.sample",
                                    "_test/s.sample",
                                    group_filters=["HERO"],
                                    individual_filters=[re.compile("ID")])
        expected = [
            "ID POP GROUP SEX", "ID1 K HERO male", "ID2 K HERO female",
            "ID3 K HERO female"
        ]
        self.assertSamplesFile("_test/s.sample", expected)

        Person.buildFilteredSamples("tests/_td/dosage_set_1/set.sample",
                                    "_test/s.sample",
                                    group_filters=["HERO"],
                                    individual_filters=[re.compile("DI")])
        expected = ["ID POP GROUP SEX", "DI5 K HERO male"]
        self.assertSamplesFile("_test/s.sample", expected)

        Person.buildFilteredSamples(
            "tests/_td/dosage_set_1/set.sample",
            "_test/s.sample",
            group_filters=["HERO"],
            individual_filters=[re.compile("DI"),
                                re.compile("ID")])
        expected = [
            "ID POP GROUP SEX", "ID1 K HERO male", "ID2 K HERO female",
            "DI5 K HERO male", "ID3 K HERO female"
        ]
        self.assertSamplesFile("_test/s.sample", expected)

        shutil.rmtree("_test")
예제 #9
0
 def testPersonConstructor(self):
     p = Person("a", "b", "c", "d")
     self.assertPerson(p)
예제 #10
0
    def testLoadFilteredPeople(self):
        # Shouldn't work when wrong delimiter is specified
        thrown = False
        try:
            person = Person.loadFilteredPeople("tests/_td/dosage_set_1/set.sample", delim=",")
        except:
            thrown = True
        self.assertEqual(thrown, True)

        # default load
        people = Person.loadFilteredPeople("tests/_td/dosage_set_1/set.sample")
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 0)

        people = Person.loadFilteredPeople("tests/_td/dosage_set_1/set.sample", group_filters=["HERO"])
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 4)
        self.assertPerson(people[0], "ID1", "K", "HERO", "male")
        self.assertPerson(people[1], "ID2", "K", "HERO", "female")
        self.assertPerson(people[2], "DI5", "K", "HERO", "male")
        self.assertPerson(people[3], "ID3", "K", "HERO", "female")

        people = Person.loadFilteredPeople("tests/_td/dosage_set_1/set.sample", group_filters=["HERO", "T"])
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 5)
        self.assertPerson(people[0], "ID1", "K", "HERO", "male")
        self.assertPerson(people[1], "ID2", "K", "HERO", "female")
        self.assertPerson(people[2], "DI5", "K", "HERO", "male")
        self.assertPerson(people[3], "ID3", "K", "HERO", "female")
        self.assertPerson(people[4], "B1", "L", "T", "female")

        people = Person.loadFilteredPeople("tests/_td/dosage_set_1/set.sample", group_filters=["T"])
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 1)
        self.assertPerson(people[0], "B1", "L", "T", "female")

        people = Person.loadFilteredPeople(
            "tests/_td/dosage_set_1/set.sample", group_filters=["HERO"], individual_filters=[re.compile("ID")]
        )
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 3)
        self.assertPerson(people[0], "ID1", "K", "HERO", "male")
        self.assertPerson(people[1], "ID2", "K", "HERO", "female")
        self.assertPerson(people[2], "ID3", "K", "HERO", "female")

        people = Person.loadFilteredPeople(
            "tests/_td/dosage_set_1/set.sample",
            group_filters=["HERO"],
            individual_filters=[re.compile("ID"), re.compile("DI")],
        )
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 4)
        self.assertPerson(people[0], "ID1", "K", "HERO", "male")
        self.assertPerson(people[1], "ID2", "K", "HERO", "female")
        self.assertPerson(people[2], "DI5", "K", "HERO", "male")
        self.assertPerson(people[3], "ID3", "K", "HERO", "female")

        people = Person.loadFilteredPeople(
            "tests/_td/dosage_set_1/set.sample", group_filters=["HERO"], individual_filters=[re.compile("DI")]
        )
        self.assertIsNotNone(people)
        self.assertEqual(len(people), 1)
        self.assertPerson(people[0], "DI5", "K", "HERO", "male")
예제 #11
0
 def testPersonLoadFromRow(self):
     row = ["a", "b", "c", "d"]
     p = Person.loadPersonFromSampleRow(row)
     self.assertPerson(p)
예제 #12
0
 def testPersonToLine(self):
     p = Person("a", "b", "c", "d")
     l = p.toTextLine()
     self.assertEqual("a b c d", l)
예제 #13
0
    def testBuildFilteredSamples(self):
        if os.path.exists("_test"):
            shutil.rmtree("_test")
        os.makedirs("_test")

        Person.buildFilteredSamples("tests/_td/dosage_set_1/set.sample", "_test/s.sample")
        expected = ["ID POP GROUP SEX"]
        self.assertSamplesFile("_test/s.sample", expected)

        Person.buildFilteredSamples("tests/_td/dosage_set_1/set.sample", "_test/s.sample", group_filters=["HERO"])
        expected = ["ID POP GROUP SEX", "ID1 K HERO male", "ID2 K HERO female", "DI5 K HERO male", "ID3 K HERO female"]
        self.assertSamplesFile("_test/s.sample", expected)

        Person.buildFilteredSamples("tests/_td/dosage_set_1/set.sample", "_test/s.sample", group_filters=["HERO", "T"])
        expected = [
            "ID POP GROUP SEX",
            "ID1 K HERO male",
            "ID2 K HERO female",
            "DI5 K HERO male",
            "ID3 K HERO female",
            "B1 L T female",
        ]
        self.assertSamplesFile("_test/s.sample", expected)

        Person.buildFilteredSamples("tests/_td/dosage_set_1/set.sample", "_test/s.sample", group_filters=["T"])
        expected = ["ID POP GROUP SEX", "B1 L T female"]
        self.assertSamplesFile("_test/s.sample", expected)

        Person.buildFilteredSamples(
            "tests/_td/dosage_set_1/set.sample",
            "_test/s.sample",
            group_filters=["HERO"],
            individual_filters=[re.compile("ID")],
        )
        expected = ["ID POP GROUP SEX", "ID1 K HERO male", "ID2 K HERO female", "ID3 K HERO female"]
        self.assertSamplesFile("_test/s.sample", expected)

        Person.buildFilteredSamples(
            "tests/_td/dosage_set_1/set.sample",
            "_test/s.sample",
            group_filters=["HERO"],
            individual_filters=[re.compile("DI")],
        )
        expected = ["ID POP GROUP SEX", "DI5 K HERO male"]
        self.assertSamplesFile("_test/s.sample", expected)

        Person.buildFilteredSamples(
            "tests/_td/dosage_set_1/set.sample",
            "_test/s.sample",
            group_filters=["HERO"],
            individual_filters=[re.compile("DI"), re.compile("ID")],
        )
        expected = ["ID POP GROUP SEX", "ID1 K HERO male", "ID2 K HERO female", "DI5 K HERO male", "ID3 K HERO female"]
        self.assertSamplesFile("_test/s.sample", expected)

        shutil.rmtree("_test")