def test_siblings_same_yob(self): """ Check max no. of siblings with same year of birth is not exceeded. """ pedigree_file = deepcopy(self.pedigree_file) pedigree = pedigree_file.pedigrees[0] f1 = pedigree.get_person_by_name('F1') self.assertEqual(len(pedigree.get_siblings(f1)[1]), 0) pedigree.people.append( Male(f1.famid, "M1A", "111", f1.fathid, f1.mothid, yob=f1.yob)) pedigree.people.append( Male(f1.famid, "M1B", "112", f1.fathid, f1.mothid, yob=f1.yob)) self.assertEqual(len(pedigree.get_siblings(f1)[1]), 2) with self.assertRaisesRegex( PersonError, r"siblings with the same year of birth exceeded"): PedigreeFile.validate(pedigree_file.pedigrees)
def test_siblings(self): """ Check max no. of siblings not exceeded. """ pedigree_file = deepcopy(self.pedigree_file) pedigree = pedigree_file.pedigrees[0] f1 = pedigree.get_person_by_name('F1') self.assertEqual(len(pedigree.get_siblings(f1)[0]), 0) pedigree.people.append( Male(f1.famid, "M1A", "111", f1.fathid, f1.mothid)) pedigree.people.append( Male(f1.famid, "M1B", "112", f1.fathid, f1.mothid)) self.assertEqual(len(pedigree.get_siblings(f1)[0]), 2) with self.assertRaisesRegex(PersonError, r"exeeded the maximum number of siblings"): 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 _add_twin(self, pedigree, twin=None, twin_key="1"): """ Utility for creating a twin given a person in a pedigree. """ if twin is None: twin = pedigree.get_person_by_name('M2') twin.mztwin = twin_key twin.fathid = "311" twin.mothid = "312" pedigree.people.append(Male(twin.famid, "M3", "311", "0", "0")) pedigree.people.append(Female(twin.famid, "F3", "312", "0", "0")) pedigree.people.append( Male(twin.famid, "M2A", "111", "311", "312", mztwin=twin_key, age=twin.age, yob=twin.yob, gtests=deepcopy(twin.gtests), cancers=deepcopy(twin.cancers)))
def test_mother_sex(self): ''' Test an error is raised if the sex of the mother is not 'F'. ''' # change sex of mother to 'M' pedigree_file = deepcopy(self.pedigree_file) f2 = pedigree_file.pedigrees[0].get_person_by_name('F2') pedigree_file.pedigrees[0].people.remove(f2) pedigree_file.pedigrees[0].people.append( Male(f2.famid, f2.name, f2.pid, f2.fathid, f2.mothid)) with self.assertRaisesRegex( PersonError, r"All mothers in the pedigree must have sex specified as 'F'"): PedigreeFile.validate(pedigree_file.pedigrees)
def _get_pedi(self): t = self.predictions.pedi.get_target() if t.cancers.is_cancer_diagnosed(): cancers = Cancers(bc1=Cancer(t.cancers.diagnoses.bc1.age), bc2=Cancer(), oc=Cancer(), prc=Cancer(), pac=Cancer()) else: cancers = Cancers() if self.predictions.model_settings['NAME'] == 'BC': gtests = BWSGeneticTests.default_factory() else: gtests = CanRiskGeneticTests.default_factory() if t.sex() is "M": new_t = Male(t.famid, t.name, t.pid, "", "", target=t.target, dead="0", age=t.age, yob=t.yob, cancers=cancers, gtests=gtests) else: new_t = Female(t.famid, t.name, t.pid, "", "", target=t.target, dead="0", age=t.age, yob=t.yob, cancers=cancers, gtests=gtests) if self.predictions.model_settings['NAME'] == 'BC': return BwaPedigree(people=[new_t]) else: return CanRiskPedigree(people=[new_t])
def _get_pedi(self): t = super()._get_pedi().get_target() cancers = Cancers() if self.predictions.model_settings['NAME'] == 'BC': gtests = BWSGeneticTests.default_factory() else: gtests = CanRiskGeneticTests.default_factory() if t.sex() is "M": new_t = Male(t.famid, t.name, t.pid, "", "", target=t.target, dead="0", age=t.age, yob=t.yob, cancers=cancers, gtests=gtests) else: new_t = Female(t.famid, t.name, t.pid, "", "", target=t.target, dead="0", age=t.age, yob=t.yob, cancers=cancers, gtests=gtests) if self.predictions.model_settings['NAME'] == 'BC': return BwaPedigree(people=[new_t]) else: return CanRiskPedigree(people=[new_t])