def test_mztwin_key(self):
     """ Check if an error is raised if MZ twin characters are not valid. """
     pedigree_file = deepcopy(self.pedigree_file)
     self._add_twin(pedigree_file.pedigrees[0], twin_key="X")
     with self.assertRaisesRegex(PedigreeError,
                                 r"MZ twins must be identified using one"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_ashkn(self):
     """ Test an error is raised if the Ashkenazi origin is incorrectly assigned (i.e. not 0 or 1). """
     pedigree_file = deepcopy(self.pedigree_file)
     f1 = pedigree_file.pedigrees[0].get_person_by_name('F1')
     f1.ashkn = "x"
     with self.assertRaisesRegex(PersonError, r"invalid Ashkenazi"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_type(self):
     """ Check that the genetic test type is valid. """
     pedigree_file = deepcopy(self.pedigree_file)
     f1 = pedigree_file.pedigrees[0].get_person_by_name('F1')
     f1.gtests.brca1.test_type = "X"
     with self.assertRaisesRegex(GeneticTestError,
                                 "invalid genetic test type"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_female_with_prostate_cancer(self):
     """ Test an error is raised if a female has been designated prostate cancer. """
     pedigree_file = deepcopy(self.pedigree_file)
     f1 = pedigree_file.pedigrees[0].get_person_by_name('F1')
     f1.cancers.diagnoses.prc.age = "21"
     with self.assertRaisesRegex(
             CancerError, r"female but has been assigned an prostate"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_male_with_ovarian_cancer(self):
     """ Test an error is raised if a male has been designated ovarian cancer. """
     pedigree_file = deepcopy(self.pedigree_file)
     m2 = pedigree_file.pedigrees[0].get_person_by_name('M2')
     m2.cancers.diagnoses.oc.age = "45"
     with self.assertRaisesRegex(CancerError,
                                 r"male but has been assigned an ovarian"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_mztwin_pair(self):
     """ Check if an error is raised if the number of people specified in a set of twins is not 2. """
     pedigree_file = deepcopy(self.pedigree_file)
     m2 = pedigree_file.pedigrees[0].get_person_by_name('M2')
     m2.mztwin = "1"
     with self.assertRaisesRegex(
             PedigreeError, r"Only MZ twins are permitted in the pedigree"):
         PedigreeFile.validate(pedigree_file.pedigrees)
Example #7
0
 def test_subproces_err(self):
     """ Test subprocess raises an error when the fortran can not be run. """
     pedigree = deepcopy(self.pedigree)
     PedigreeFile.validate(pedigree)
     with self.assertRaises(FileNotFoundError):
         model_settings = settings.BC_MODEL
         model_settings['HOME'] = 'xyz'
         Predictions(pedigree, cwd=self.cwd, model_settings=model_settings)
 def test_target_age(self):
     """ The target must be assigned a valid year of birth. """
     pedigree_file = deepcopy(self.pedigree_file)
     f1 = pedigree_file.pedigrees[0].get_person_by_name('F1')
     f1.age = "0"
     with self.assertRaisesRegex(PedigreeError,
                                 r"This person must be assigned an age"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_mztwin_number(self):
     """ Check if an error is raised if the number of people specified in a set of twins is not 2. """
     pedigree_file = deepcopy(self.pedigree_file)
     self._add_twin(pedigree_file.pedigrees[0])
     with self.assertRaisesRegex(
             PedigreeError,
             r"Maximum number of MZ twin pairs has been exceeded"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_ununconnected(self):
     pedigree_file = deepcopy(self.pedigree_file)
     m2 = pedigree_file.pedigrees[0].get_person_by_name('M2')
     pedigree_file.pedigrees[0].people.append(
         Male(m2.famid, "M1A", "111", "0", "0"))
     with self.assertRaisesRegex(
             PedigreeError,
             r"family members are not physically connected to the target"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_cancer_age2(self):
     ''' Test an error is raised if the cancer diagnosis age is greater than age at last follow up. '''
     pedigree_file = deepcopy(self.pedigree_file)
     m2 = pedigree_file.pedigrees[0].get_person_by_name('M2')
     m2.cancers.diagnoses.bc1.age = "59"
     m2.age = "53"
     with self.assertRaisesRegex(
             CancerError, r"diagnosis that exceeds age at last follow up"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_type_specified(self):
     """ Check if there is a genetic test result check the test type is specified. """
     pedigree_file = deepcopy(self.pedigree_file)
     f1 = pedigree_file.pedigrees[0].get_person_by_name('F1')
     f1.gtests.brca1.test_type = "0"
     f1.gtests.brca1.result = "P"
     with self.assertRaisesRegex(
             GeneticTestError, "genetic test type has not been specified"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_missing_mother(self):
     ''' Test an error is raised if the mother is missing. '''
     # remove mother F2 from pedigree
     pedigree_file = deepcopy(self.pedigree_file)
     f2 = pedigree_file.pedigrees[0].get_person_by_name('F2')
     pedigree_file.pedigrees[0].people.remove(f2)
     with self.assertRaisesRegex(PersonError,
                                 r"The mother (.*) is missing"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_name(self):
     """ Test an error is raised if the individuals name is not an alphanumeric string. """
     pedigree_file = deepcopy(self.pedigree_file)
     m2 = pedigree_file.pedigrees[0].get_person_by_name('M2')
     m2.name = "M<2"
     with self.assertRaisesRegex(
             PersonError,
             r"is unspecified or is not an alphanumeric string"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_cancer_yob(self):
     ''' Test an error is raised if the yob is not specified when a cancer is diagnosed. '''
     pedigree_file = deepcopy(self.pedigree_file)
     m2 = pedigree_file.pedigrees[0].get_person_by_name('M2')
     m2.yob = "0"
     with self.assertRaisesRegex(
             CancerError, m2.pid +
             "*. diagnosed with cancer but has no year of birth specified"):
         PedigreeFile.validate(pedigree_file.pedigrees)
Example #16
0
 def test_pedigree_range_baseline(self):
     """ Test pedigree for baseline time range (e.g. lifetime, 10yr range) risk calculation. """
     p1 = deepcopy(self.pedigree)
     PedigreeFile.validate(p1)
     calcs = Predictions(p1, cwd=self.cwd, run_risks=False)
     range_baseline = RangeRiskBaseline(calcs, 40, 50, "10 YR RANGE BASELINE")
     p2 = range_baseline._get_pedi()
     self.assertEqual(len(p2.people), 1)
     self.assertEqual(p2.get_target().age, 40)
     self.assertNotEqual(p1.get_target().age, p2.get_target().age)
 def test_result_specified(self):
     """ Check that the mutation status is specified if tested. """
     pfile = self.get_pedigree_file()
     f1 = pfile.pedigrees[0].get_person_by_name('F1')
     f1.gtests.brca1.test_type = "S"
     f1.gtests.brca1.result = "0"
     with self.assertRaisesRegex(
             GeneticTestError, "\"" + f1.pid +
             "\" .* corresponding test result has not been specified"):
         PedigreeFile.validate(pfile.pedigrees)
Example #18
0
 def test_bc1_and_bc2(self):
     """ Test an error is raised if the age of a first breast cancer exceeds that of the second. """
     pedigree_file = deepcopy(self.pedigree_file)
     f1 = pedigree_file.pedigrees[0].get_person_by_name('F1')
     f1.cancers.diagnoses.bc1.age = "22"
     f1.cancers.diagnoses.bc2.age = "21"
     with self.assertRaisesRegex(
             CancerError, f1.pid + "*. contralateral breast cancer, (.*) " +
             "age at diagnosis of the first breast cancer exceeds"):
         PedigreeFile.validate(pedigree_file.pedigrees)
Example #19
0
 def test_bc1_missing2(self):
     """ Test an error is raised if the age of a second breast cancer is AU but age of first is missing. """
     pedigree_file = deepcopy(self.pedigree_file)
     f1 = pedigree_file.pedigrees[0].get_person_by_name('F1')
     f1.cancers.diagnoses.bc1.age = "-1"
     f1.cancers.diagnoses.bc2.age = "AU"
     with self.assertRaisesRegex(
             CancerError, f1.pid + "*. contralateral breast cancer, (.*) " +
             "first breast cancer is missing"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_result(self):
     """ Check that the mutation status is valid. """
     pfile = self.get_pedigree_file()
     f1 = pfile.pedigrees[0].get_person_by_name('F1')
     f1.gtests.brca1.test_type = "S"
     f1.gtests.brca1.result = "X"
     with self.assertRaisesRegex(
             GeneticTestError,
             "\"" + f1.pid + "\" .* invalid genetic test result"):
         PedigreeFile.validate(pfile.pedigrees)
 def test_pathology_status(self):
     """ Check that the pathology results are correctly set (0, N, P). """
     pedigree_file = deepcopy(self.pedigree_file)
     f1 = pedigree_file.pedigrees[0].get_person_by_name('F1')
     f1.pathology.er.result = 'X'
     with self.assertRaisesRegex(
             PathologyError,
             "must be 'N' for negative, 'P' for positive, or '0' for unknown"
     ):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_dead(self):
     ''' Test an error is raised if the dead attribute is incorrectly specified (not 0 or 1). '''
     pedigree_file = deepcopy(self.pedigree_file)
     PedigreeFile.validate(pedigree_file.pedigrees)
     m2 = pedigree_file.pedigrees[0].get_person_by_name('M2')
     m2.dead = "3"
     with self.assertRaisesRegex(
             PersonError,
             r"alive must be specified as '0', and dead specified as '1'"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_mztwin_yob(self):
     """ Check if an error is raised if MZ twin have different years of birth. """
     pedigree_file = deepcopy(self.pedigree_file)
     pedigree = pedigree_file.pedigrees[0]
     m2 = pedigree.get_person_by_name('M2')
     self._add_twin(pedigree, twin=m2)
     m2.yob = str(int(m2.yob) + 2)
     with self.assertRaisesRegex(
             PedigreeError, r"MZ twins must have the same year of birth"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_bc1_missing(self):
     """ Test an error is raised if the age of a second breast cancer is present but age of first is missing. """
     pfile = self.get_pedigree_file()
     f1 = pfile.pedigrees[0].get_person_by_name('F1')
     f1.cancers.diagnoses.bc1.age = "-1"
     f1.cancers.diagnoses.bc2.age = "21"
     with self.assertRaisesRegex(
             CancerError,
             ".*\"" + f1.pid + "\".* contralateral breast cancer, (.*) " +
             "first breast cancer is missing"):
         PedigreeFile.validate(pfile.pedigrees)
Example #25
0
 def test_pedigree_remaining_lifetime(self):
     """ Test pedigree for remaining lifetime risk calculation. """
     p1 = deepcopy(self.pedigree)
     PedigreeFile.validate(p1)
     calcs = Predictions(p1, cwd=self.cwd, run_risks=False)
     self.assertTrue(calcs.pedi.is_carrier_probs_viable())
     self.assertTrue(calcs.pedi.is_risks_calc_viable())
     remaining_life = RemainingLifetimeRisk(calcs)
     p2 = remaining_life._get_pedi()
     self.assertEqual(len(p1.people), len(p2.people))
     self.assertEqual(p1.get_target().age, p2.get_target().age)
 def test_mztwin_parents(self):
     """ Check if an error is raised if MZ twin have different parents. """
     pedigree_file = deepcopy(self.pedigree_file)
     pedigree = pedigree_file.pedigrees[0]
     m2 = pedigree.get_person_by_name('M2')
     self._add_twin(pedigree, twin=m2)
     m2.mothid = "313"
     pedigree.people.append(Female(m2.famid, "F3A", "313", "0", "0"))
     with self.assertRaisesRegex(PedigreeError,
                                 r"MZ twins must have the same parents"):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_age(self):
     ''' Test an error is raised if the age attribute is incorrectly specified (not 0 or 1-MAX_AGE). '''
     pedigree_file = deepcopy(self.pedigree_file)
     PedigreeFile.validate(pedigree_file.pedigrees)
     m2 = pedigree_file.pedigrees[0].get_person_by_name('M2')
     m2.age = "222"
     with self.assertRaisesRegex(
             PersonError,
             r"Ages must be specified with as '0' for unknown, or in the range"
     ):
         PedigreeFile.validate(pedigree_file.pedigrees)
 def test_patholgy_bc1_setting(self):
     """ Check that pathology test results are only provided for family members with a first breast cancer """
     pedigree_file = deepcopy(self.pedigree_file)
     f1 = pedigree_file.pedigrees[0].get_person_by_name('F1')
     f1.cancers.diagnoses.bc1.age = "-1"
     f1.pathology.er.result = "P"
     with self.assertRaisesRegex(
             PathologyError,
             "Pathology test results can only be assigned to family " +
             "members who have developed breast cancer."):
         PedigreeFile.validate(pedigree_file.pedigrees)
    def test_cancer_age(self):
        ''' Test an error is raised if the cancer diagnosis age is incorrectly specified (not 0 or 1-MAX_AGE). '''
        pedigree_file = deepcopy(self.pedigree_file)
        f1 = pedigree_file.pedigrees[0].get_person_by_name('F1')
        f1.cancers.diagnoses.bc1.age = "xyz"
        with self.assertRaisesRegex(CancerError, r"Age at cancer diagnosis"):
            PedigreeFile.validate(pedigree_file.pedigrees)

        f1.cancers.diagnoses.bc1.age = "199"
        with self.assertRaisesRegex(CancerError, r"Age at cancer diagnosis"):
            PedigreeFile.validate(pedigree_file.pedigrees)
 def test_mztwin_age(self):
     """ Check if an error is raised if MZ twin are alive and have different ages at last followup. """
     pedigree_file = deepcopy(self.pedigree_file)
     pedigree = pedigree_file.pedigrees[0]
     m2 = pedigree.get_person_by_name('M2')
     self._add_twin(pedigree, twin=m2)
     m2.age = "44"
     with self.assertRaisesRegex(
             PedigreeError,
             r"If both MZ twins are alive, they must have the same age at last"
     ):
         PedigreeFile.validate(pedigree_file.pedigrees)