Esempio n. 1
0
    def testBasicWithCovar(self):
        PhenoCovar.sex_as_covariate = False
        pc = PhenoCovar()
        load_pedigree(pc, self.ped)
        pc.individual_mask = [0, 0, 0, 0, 0, 0, 1, 1]
        pc.load_covarfile(self.header, names=["BMI", "MSA"])
        pc.freeze_subjects()

        pheno = [0.1, 0.4, 1.0, 0.5, 0.9, 1.0]
        sex = [1, 1, 2, 1, 1, 1]

        # First, test without sex as covariate
        count = 0
        for test in pc:
            test_pheno, covars, nonmissing = test.get_variables()
            self.assertEqual(6, numpy.sum(nonmissing))
            self.assertEqual(2, len(covars))
            for phenotype in self.phenotypes[0:2]:
                self.assertEqual(self.phenotypes[0], list(covars[0]))
                self.assertEqual(self.phenotypes[2], list(covars[1]))
                self.assertEqual("BMI", test.get_covariate_name(0))
                self.assertEqual("MSA", test.get_covariate_name(1))
                self.assertEqual(6, len(pheno))
                self.assertEqual("Pheno-1", test.get_phenotype_name())

                for i in range(0, len(pheno)):
                    self.assertAlmostEqual(pheno[i], test_pheno[i])
            count += 1
        self.assertEqual(1, count)

        PhenoCovar.sex_as_covariate = True
Esempio n. 2
0
 def testPhenoWithAllMissing(self):
     pc = PhenoCovar()
     count = 0
     invalid = 0
     missingness = 0
     pc.add_subject("1:1", phenotype=1)
     pc.add_subject("2:2", phenotype=1)
     pc.add_subject("3:3", phenotype=1)
     pc.add_subject("4:4", phenotype=1)
     pc.freeze_subjects()
     try:
         for test in pc:
             (pheno, covars, nonmissing) = test.get_variables(
                 numpy.array([True, True, True, True]))
             count += 1
     except InvariantVar as e:
         invalid += 1
     except TooMuchMissingpPhenoCovar as e:
         missingness += 1
     self.assertEqual(0, invalid)
     self.assertEqual(1, missingness)
     self.assertEqual(0, count)