def test_affected_unknown(self): """ Test including affected unknown for mother of target to show it increases breast cancer risk. """ pedigree = deepcopy(self.pedigree) target = pedigree.get_target() mother = pedigree.get_person(target.mothid) mother.yob = str(self.year - 55) mother.age = "55" calcs1 = Predictions(pedigree, cwd=self.cwd) def get_c80(calcs): for c in calcs.cancer_risks: if c.get('age') == 80: return c['breast cancer risk']['decimal'] return None # add affected unknown to mother mother.cancers = Cancers(bc1=Cancer("AU"), bc2=Cancer(), oc=Cancer(), prc=Cancer(), pac=Cancer()) calcs2 = Predictions(pedigree, cwd=self.cwd) self.assertGreater( get_c80(calcs2), get_c80(calcs1), 'Mother affected unknown increases BC risk in target')
def test_calculations2(self): """ Test prediction of cancer risk and mutation probability. """ pedigree = deepcopy(self.pedigree) target = pedigree.get_target() target.age = str(int(target.age) + 43) # sister # diagnoses = CancerDiagnoses(bc1=Cancer("20"), bc2=Cancer(), oc=Cancer(), # prc=Cancer(), pac=Cancer()) # sister = Female("FAM1", "F01", "0011", target.fathid, target.mothid, age="22", yob=str(self.year-23), # cancers=Cancers(diagnoses=diagnoses)) # pedigree.people.append(sister) # parents mother = pedigree.get_person(target.mothid) mother.yob = str(self.year - 84) mother.age = "85" mother.cancers = Cancers(bc1=Cancer("52"), bc2=Cancer(), oc=Cancer(), prc=Cancer(), pac=Cancer()) # maternal grandparents (_maternal_grandfather, maternal_grandmother) = pedigree.add_parents(mother) maternal_grandmother.age = "81" maternal_grandmother.yob = "1912" maternal_grandmother.dead = "1" maternal_grandmother.cancers = Cancers(bc1=Cancer("42"), bc2=Cancer(), oc=Cancer(), prc=Cancer(), pac=Cancer()) PedigreeFile.validate(pedigree) calcs = Predictions(pedigree, cwd=self.cwd) # each gene should have a mutation probability plus a result for no mutations for mp in calcs.mutation_probabilties: key = list(mp.keys())[0] self.assertTrue(key in settings.BC_MODEL['GENES'] or key == "no mutation") self.assertEqual(len(calcs.mutation_probabilties), len(settings.BC_MODEL['GENES']) + 1) # risks calculated at different ages: self.assertEqual(len(calcs.cancer_risks), 9) self.assertTrue([c.get('age') for c in calcs.cancer_risks] == [64, 65, 66, 67, 68, 70, 73, 75, 80])
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 test_niceness(self): """ Test niceness level for pedigree with sibling and large pedigree. """ pedigree = deepcopy(self.pedigree) self.assertEqual(Predictions._get_niceness(pedigree, factor=1), len(pedigree.people)) self.assertEqual(Predictions._get_niceness(pedigree, factor=0.01), 19) # sister target = pedigree.get_target() sister = Female("FAM1", "F01", "0011", target.fathid, target.mothid, age="22", yob=str(self.year-23), cancers=Cancers(bc1=Cancer("20"))) pedigree.people.append(sister) self.assertEqual(Predictions._get_niceness(pedigree), 1)
def setUp(self): ''' Build pedigree data. ''' self.year = date.today().year target = Female("FAM1", "F0", "001", "002", "003", target="1", age="20", yob=str(self.year - 20), cancers=Cancers()) self.pedigree = BwaPedigree(people=[target]) # parents (_father, _mother) = self.pedigree.add_parents(target) # canrisk pedigree target = Female("FAM1", "F0", "001", "002", "003", target="1", age="20", yob=str(self.year - 20), cancers=Cancers(), gtests=CanRiskGeneticTests.default_factory()) self.canrisk_pedigree = CanRiskPedigree(people=[target]) (_father, _mother) = self.canrisk_pedigree.add_parents( target, gtests=CanRiskGeneticTests.default_factory()) _mother.yob = str(self.year - 55) _mother.age = "55" _mother.cancers = Cancers(bc1=Cancer("54"), bc2=Cancer("55"), oc=Cancer(), prc=Cancer(), pac=Cancer()) self.cwd = tempfile.mkdtemp(prefix="TEST_", dir="/tmp")
def factory(ped_file_line, file_type=None): ''' Factory method for creating types of people given a record from a BOADICEA import pedigree file . @type ped_file_line: str @param ped_file_line: Pedigree file line. ''' cols = ped_file_line.split() famid = cols[0] name = cols[1] pid = cols[3] cancers = Cancers(bc1=Cancer(cols[11] if cols[11] != "0" else "-1"), bc2=Cancer(cols[12] if cols[12] != "0" else "-1"), oc=Cancer(cols[13] if cols[13] != "0" else "-1"), prc=Cancer(cols[14] if cols[14] != "0" else "-1"), pac=Cancer(cols[15] if cols[15] != "0" else "-1")) # use column headers to get gene test type and result if file_type == 'bwa': gtests = BWSGeneticTests.factory([ GeneticTest(cols[BwaPedigree.get_column_idx(gene + 't')], cols[BwaPedigree.get_column_idx(gene + 'r')]) for gene in settings.BC_MODEL['GENES'] ]) pathology = PathologyTests( er=PathologyTest(PathologyTest.ESTROGEN_RECEPTOR_TEST, cols[27]), pr=PathologyTest(PathologyTest.PROGESTROGEN_RECEPTOR_TEST, cols[28]), her2=PathologyTest(PathologyTest.HER2_TEST, cols[29]), ck14=PathologyTest(PathologyTest.CK14_TEST, cols[30]), ck56=PathologyTest(PathologyTest.CK56_TEST, cols[31])) else: genes = settings.BC_MODEL['GENES'] + settings.OC_MODEL['GENES'][2:] def get_genetic_test(cols, gene): idx = CanRiskPedigree.get_column_idx(gene) if idx < 0: raise PedigreeError("Genetic test column for '" + gene + "not found.") gt = cols[idx].split(':') return GeneticTest(gt[0], gt[1]) gtests = CanRiskGeneticTests.factory( [get_genetic_test(cols, gene) for gene in genes]) path = cols[len(CanRiskPedigree.COLUMNS) - 1].split(':') pathology = PathologyTests( er=PathologyTest(PathologyTest.ESTROGEN_RECEPTOR_TEST, path[0]), pr=PathologyTest(PathologyTest.PROGESTROGEN_RECEPTOR_TEST, path[1]), her2=PathologyTest(PathologyTest.HER2_TEST, path[2]), ck14=PathologyTest(PathologyTest.CK14_TEST, path[3]), ck56=PathologyTest(PathologyTest.CK56_TEST, path[4])) if cols[6] == 'M': return Male(famid, name, pid, fathid=cols[4], mothid=cols[5], target=cols[2], dead=cols[8], age=cols[9], yob=cols[10], ashkn=cols[16], cancers=cancers, mztwin=cols[7], gtests=gtests, pathology=pathology) elif cols[6] == 'F': return Female(famid, name, pid, fathid=cols[4], mothid=cols[5], target=cols[2], dead=cols[8], age=cols[9], yob=cols[10], ashkn=cols[16], cancers=cancers, mztwin=cols[7], gtests=gtests, pathology=pathology) else: raise PedigreeError( "The sex of family member '" + name + "' is invalid. An " + "individuals sex must be specified as 'M' or 'F' only.")