def combine_trio_variants(self, child_vars, mother_vars, father_vars): """ for each variant, combine the trio's genotypes into TrioGenotypes Args: child_vars: list of Variant objects for the child mother_vars: list of Variant objects for the mother father_vars: list of Variant objects for the father Returns: list of TrioGenotypes objects for the family """ mother_cnv_matcher = MatchCNVs(mother_vars) father_cnv_matcher = MatchCNVs(father_vars) variants = [] for var in child_vars: trio = TrioGenotypes(var, SNV.debug_chrom, SNV.debug_pos) # if we only have the child, then just add the variant to the list if self.family.has_parents() == False: variants.append(trio) continue mother_var = self.get_parental_var(var, mother_vars, self.family.mother.get_gender(), mother_cnv_matcher) trio.add_mother_variant(mother_var) father_var = self.get_parental_var(var, father_vars, self.family.father.get_gender(), father_cnv_matcher) trio.add_father_variant(father_var) variants.append(trio) return variants
def test_check_homozygous_with_cnv(self): """ test that check_homozygous() works correctly for variant lists with CNVs """ # generate a test variant chrom = "1" position = "60000" child_var = self.create_cnv("F", "unknown", chrom, position) mom_var = self.create_cnv("F", "unknown", chrom, position) dad_var = self.create_cnv("M", "unknown", chrom, position) cnv_var = TrioGenotypes(child_var) cnv_var.add_mother_variant(mom_var) cnv_var.add_father_variant(dad_var) var = self.variants[0] # check for trio = 200, which is non-mendelian self.set_trio_genos(var, "200") self.assertEqual(self.inh.check_homozygous("Biallelic"), "nothing") self.assertEqual(self.inh.log_string, "non-mendelian trio") # check when a CNV is in the variants list self.inh.variants.append(cnv_var) self.assertEqual(self.inh.check_homozygous("Biallelic"), "compound_het") self.assertEqual(self.inh.log_string, "non-mendelian, but CNV might affect call")
def setUp(self): """ define a family and variant, and start the Allosomal class """ # generate a test family child_gender = "F" mom_aff = "1" dad_aff = "1" self.trio = self.create_family(child_gender, mom_aff, dad_aff) # generate a test variant child_var = self.create_snv(child_gender, "0/1") mom_var = self.create_snv("F", "0/0") dad_var = self.create_snv("M", "0/0") var = TrioGenotypes(child_var) var.add_mother_variant(mom_var) var.add_father_variant(dad_var) self.variants = [var] # make sure we've got known genes data self.known_genes = {"TEST": {"inh": ["Monoallelic"], "confirmed_status": ["Confirmed DD Gene"]}} self.inh = Allosomal(self.variants, self.trio, self.known_genes, "TEST") self.inh.is_lof = var.child.is_lof()
def setUp(self): """ define a family and variant, and start the Autosomal class """ # generate a test family child_gender = "F" mom_aff = "1" dad_aff = "1" self.trio = self.create_family(child_gender, mom_aff, dad_aff) # generate a test variant child_var = self.create_snv(child_gender, "0/1") mom_var = self.create_snv("F", "0/0") dad_var = self.create_snv("M", "0/0") var = TrioGenotypes(child_var) var.add_mother_variant(mom_var) var.add_father_variant(dad_var) self.variants = [var] # make sure we've got known genes data self.known_genes = { "TEST": { "inh": ["Monoallelic"], "confirmed_status": ["Confirmed DD Gene"] } } self.inh = Autosomal(self.variants, self.trio, self.known_genes, "TEST") self.inh.is_lof = var.child.is_lof()
def test_check_homozygous_with_cnv(self): """ test that check_homozygous() works correctly for variant lists with CNVs """ # generate a test variant chrom = "X" position = "60000" child_var = self.create_cnv("F", "unknown", chrom, position) mom_var = self.create_cnv("F", "unknown", chrom, position) dad_var = self.create_cnv("M", "unknown", chrom, position) cnv_var = TrioGenotypes(child_var) cnv_var.add_mother_variant(mom_var) cnv_var.add_father_variant(dad_var) var = self.variants[0] # check for trio = 200, which is non-mendelian self.set_trio_genos(var, "200") self.assertEqual(self.inh.check_homozygous("Hemizygous"), "nothing") self.assertEqual(self.inh.log_string, "non-mendelian trio") # check when a CNV is in the variants list self.inh.variants.append(cnv_var) self.assertEqual(self.inh.check_homozygous("Hemizygous"), "compound_het") self.assertEqual(self.inh.log_string, "non-mendelian, but CNV might affect call")
def create_variant(self, child_gender, chrom="1", position="15000000"): """ creates a TrioGenotypes variant """ # generate a test variant child_var = self.create_cnv(child_gender, "unknown", "uncertain", chrom, position) mom_var = self.create_cnv("F", "unknown", "uncertain", chrom, position) dad_var = self.create_cnv("M", "unknown", "uncertain", chrom, position) var = TrioGenotypes(child_var) var.add_mother_variant(mom_var) var.add_father_variant(dad_var) return var
def create_trio_variant(self, child_gender, cq, hgnc, chrom="1"): """ create a default TrioGenotypes variant """ # generate a test variant child_var = self.create_snv(child_gender, "0/1", cq, hgnc, chrom) mom_var = self.create_snv("F", "0/0", cq, hgnc, chrom) dad_var = self.create_snv("M", "0/0", cq, hgnc, chrom) var = TrioGenotypes(child_var) var.add_mother_variant(mom_var) var.add_father_variant(dad_var) return var
def test_check_if_any_variant_is_cnv(self): """ test if check_if_any_variant_is_cnv() works correctly """ # generate a test variant chrom = "1" position = "60000" child_var = self.create_cnv("F", "unknown", chrom, position) mom_var = self.create_cnv("F", "unknown", chrom, position) dad_var = self.create_cnv("M", "unknown", chrom, position) cnv_var = TrioGenotypes(child_var) cnv_var.add_mother_variant(mom_var) cnv_var.add_father_variant(dad_var) # check that all variants=SNV returns False self.assertFalse(self.inh.check_if_any_variant_is_cnv()) # add a CNV to the variants, then check that we find a CNV self.inh.variants.append(cnv_var) self.assertTrue(self.inh.check_if_any_variant_is_cnv())
def create_var(self, chrom, snv=True, geno=["0/1", "0/1", "0/1"]): """ define a family and variant, and start the Inheritance class Args: chrom: string for chrom, since we check the number of different chroms snv: boolean for whether to create a SNV or CNV object """ # generate a test variant if snv: child_var = self.create_snv(chrom, geno[0]) mom_var = self.create_snv(chrom, geno[1]) dad_var = self.create_snv(chrom, geno[2]) else: child_var = self.create_cnv(chrom) mom_var = self.create_cnv(chrom) dad_var = self.create_cnv(chrom) var = TrioGenotypes(child_var) var.add_mother_variant(mom_var) var.add_father_variant(dad_var) return var
def setUp(self): """ define a family and variant, and start the Allosomal class """ # generate a test family child_gender = "F" mom_aff = "1" dad_aff = "1" self.trio = self.create_family(child_gender, mom_aff, dad_aff) # generate a test variant child_var = self.create_snv(child_gender, "0/1") mom_var = self.create_snv("F", "0/0") dad_var = self.create_snv("M", "0/0") var = TrioGenotypes(child_var) var.add_mother_variant(mom_var) var.add_father_variant(dad_var) self.variants = [var] self.report = Report(None, None, None, None) self.report.family = self.trio
def create_variant(self, child_gender, chrom="1", position="15000000", cq=None): """ creates a TrioGenotypes variant """ # generate a test variant try: child_var = self.create_snv(child_gender, "0/1", chrom, position, cq) except ValueError: child_var = self.create_snv(child_gender, "1/1", chrom, position, cq) mom_var = self.create_snv("F", "0/0", chrom, position, cq) dad_var = self.create_snv("M", "0/0", chrom, position, cq) var = TrioGenotypes(child_var) var.add_mother_variant(mom_var) var.add_father_variant(dad_var) return var
def test_is_compound_pair_cnv(self): """ check that is_compound_pair() includes pairs with CNVs """ # generate a test variant chrom = "1" position = "60000" child_var = self.create_cnv("F", "unknown", chrom, position) mom_var = self.create_cnv("F", "unknown", chrom, position) dad_var = self.create_cnv("M", "unknown", chrom, position) cnv = TrioGenotypes(child_var) cnv.add_mother_variant(mom_var) cnv.add_father_variant(dad_var) # set some variants, so we can alter them later snv = self.create_variant("F", chrom="1", position="150", cq="stop_gained") snv = self.set_compound_het_var(snv, "110") # exclude pairs where both members are not loss-of-function self.assertTrue(self.inh.is_compound_pair(cnv, snv))
class TestTrioGenotypesPy(unittest.TestCase): """ test the Inheritance class """ def setUp(self): """ define a family and variant, and start the Inheritance class """ # generate a test family child_gender = "F" mom_aff = "1" dad_aff = "1" self.trio = self.create_family(child_gender, mom_aff, dad_aff) # generate a test variant child_var = self.create_snv(child_gender, "0/1") mom_var = self.create_snv("F", "0/0") dad_var = self.create_snv("M", "0/0") self.var = TrioGenotypes(child_var) self.var.add_mother_variant(mom_var) self.var.add_father_variant(dad_var) def create_snv(self, gender, genotype): """ create a default variant """ chrom = "1" pos = "15000000" snp_id = "." ref = "A" alt = "G" filt = "PASS" # set up a SNV object, since SNV inherits VcfInfo var = SNV(chrom, pos, snp_id, ref, alt, filt) info = "HGNC=TEST;CQ=missense_variant;DENOVO-SNP;PP_DNM=0.99" keys = "GT:DP:TEAM29_FILTER:PP_DNM" values = genotype + ":50:PASS:0.99" var.add_info(info) var.add_format(keys, values) var.set_gender(gender) var.set_genotype() return var def create_family(self, child_gender, mom_aff, dad_aff): """ create a default family, with optional gender and parental statuses """ fam = Family("test") fam.add_child("child", "child_vcf", "2", child_gender) fam.add_mother("mother", "mother_vcf", mom_aff, "2") fam.add_father("father", "father_vcf", dad_aff, "1") fam.set_child() return fam def test_passes_de_novo_checks(self): """ test that passes_de_novo_checks() works correctly """ # check that a default de novo variant passes self.assertTrue(self.var.passes_de_novo_checks(pp_filter=0.9)) # check that vars fail without DENOVO-SNP or DENOVO-INDEL flags del self.var.child.info["DENOVO-SNP"] self.assertFalse(self.var.passes_de_novo_checks(pp_filter=0.9)) # make sure that DENOVO-INDEL flag can pass the de novo filter self.var.child.info["DENOVO-INDEL"] = True self.assertTrue(self.var.passes_de_novo_checks(pp_filter=0.9)) # check that de novos with low PP_DNM scores fail the de novo filter self.var.child.format["PP_DNM"] = 0.0099 self.assertFalse(self.var.passes_de_novo_checks(pp_filter=0.9)) # check that de novos with low PP_DNM scores pass the de novo filter, if # we are using a low PP_DNM threshold self.var.child.format["PP_DNM"] = 0.0099 self.assertTrue(self.var.passes_de_novo_checks(pp_filter=0.0)) # check that we don't fail a de novo if it lacks the PP_DNM annotation del self.var.child.format["PP_DNM"] self.assertTrue(self.var.passes_de_novo_checks(pp_filter=0.9)) def test_passes_de_novo_checks_X_chrom(self): """ test that passes_de_novo_checks() works on the X chromosome """ # check that a male X chrom de novo passes self.trio.child.gender = "M" self.var.inheritance_type = "XChrMale" self.var.child.format["GT"] = "1/1" self.var.child.set_genotype() self.assertTrue(self.var.passes_de_novo_checks(pp_filter=0.9)) # and change a field so that it would fail del self.var.child.info["DENOVO-SNP"] self.assertFalse(self.var.passes_de_novo_checks(pp_filter=0.9)) # and change the variant fom a male X de novo genotype self.var.child.format["GT"] = "1/0" self.var.child.set_genotype() self.assertTrue(self.var.passes_de_novo_checks(pp_filter=0.9)) # now check that a female X chrom de novo passes self.trio.child.gender = "F" self.var.inheritance_type = "XChrFemale" self.var.child.set_genotype() self.var.child.info["DENOVO-SNP"] = True self.assertTrue(self.var.passes_de_novo_checks(pp_filter=0.9)) def test_get_de_novo_genotype(self): """ check that get_de_novo_genotype() works correctly """ self.var.inheritance_type = "autosomal" self.assertEqual(self.var.get_de_novo_genotype(), (1, 0, 0)) self.var.inheritance_type = "XChrFemale" self.assertEqual(self.var.get_de_novo_genotype(), (1, 0, 0)) # we double the alt count for males on the X, so a de novo genotype # differes from the other situations self.var.inheritance_type = "XChrMale" self.assertEqual(self.var.get_de_novo_genotype(), (2, 0, 0)) def test_get_trio_genotype(self): """ test that get_trio_genotype() works correctly """ # check that the defaul var gives the expected genotypes self.assertEqual(self.var.get_trio_genotype(), (1, 0, 0)) # check that different genotypes still work self.var.mother.format["GT"] = "1/1" self.var.mother.set_genotype() self.assertEqual(self.var.get_trio_genotype(), (1, 2, 0)) # check that probands only give NA genotypes for parents del self.var.mother del self.var.father self.assertEqual(self.var.get_trio_genotype(), (1, "NA", "NA")) def test_chrom_to_int(self): """ test that chrom_to_int() works correctly """ # check that an autosomal chrom works self.assertEqual(self.var.chrom_to_int("1"), 1) # check that an X chrom works self.assertEqual(self.var.chrom_to_int("X"), 23) # check that an X chrom works self.assertEqual(self.var.chrom_to_int("chrX"), 23) # check that a Y chrom works self.assertEqual(self.var.chrom_to_int("chrY"), 24)