def test_check_variant_without_parents_female(self): """ test that check_variant_without_parents() works correctly for female """ var = TrioGenotypes('X', 100, create_snv('F', "1/0"), None, None) self.inh.set_trio_genotypes(var) # check for X-linked dominant inheritance self.assertEqual( self.inh.check_variant_without_parents("X-linked dominant"), "single_variant") self.assertEqual(self.inh.log_string, "allosomal without parents") var = TrioGenotypes('X', 100, create_snv('F', "1/1"), create_snv('F', "0/0"), create_snv('M', "0/0")) self.inh.set_trio_genotypes(var) self.assertEqual( self.inh.check_variant_without_parents("X-linked dominant"), "single_variant") # and check for hemizygous inheritance var = TrioGenotypes('X', 100, create_snv('F', "1/0"), create_snv('F', "0/0"), create_snv('M', "0/0")) self.inh.set_trio_genotypes(var) self.assertEqual(self.inh.check_variant_without_parents("Hemizygous"), "hemizygous") var = TrioGenotypes('X', 100, create_snv('F', "1/1"), create_snv('F', "0/0"), create_snv('M', "0/0")) self.inh.set_trio_genotypes(var) self.assertEqual(self.inh.check_variant_without_parents("Hemizygous"), "single_variant")
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 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 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_heterozygous_affected_mother(self): """ test that check_heterozygous() works correctly for affected mothers """ # check that trio with het affected mother is captured var = TrioGenotypes('X', 100, create_snv('F', "1/0"), create_snv('F', "1/0"), create_snv('M', "0/0")) self.inh.set_trio_genotypes(var) self.inh.mother_affected = True self.assertEqual(self.inh.check_heterozygous("X-linked dominant"), "single_variant") self.assertEqual( self.inh.log_string, "x chrom transmitted from aff, other parent non-carrier or aff") # check that when the other parent is also non-ref, the variant is no # longer captured, unless the parent is affected var = TrioGenotypes('X', 100, create_snv('F', "1/0"), create_snv('F', "1/0"), create_snv('M', "1/1")) self.inh.set_trio_genotypes(var) self.assertEqual(self.inh.check_heterozygous("X-linked dominant"), "nothing") self.assertEqual(self.inh.log_string, "variant not compatible with being causal") self.inh.father_affected = True self.inh.check_heterozygous("X-linked dominant") self.assertEqual( self.inh.log_string, "x chrom transmitted from aff, other parent non-carrier or aff") # and check that hemizgygous vars return as "compound_het" self.assertEqual(self.inh.check_heterozygous("Hemizygous"), "compound_het")
def test_check_homozygous_male(self): """ test that check_homozygous() works correctly for males """ # check for trio with de novo on male X chrom var = TrioGenotypes('X', 100, create_snv('M', "1/1"), create_snv('F', "0/0"), create_snv('M', "0/0")) trio = self.create_family('male', '1', '1') self.inh = Allosomal([var], trio, self.known_gene, "TEST") self.inh.set_trio_genotypes(var) self.assertEqual(self.inh.check_homozygous("X-linked dominant"), "single_variant") self.assertEqual(self.inh.log_string, "male X chrom de novo") # check for trio = 210, with unaffected mother var = TrioGenotypes('X', 100, create_snv('M', "1/1"), create_snv('F', "1/0"), create_snv('M', "0/0")) self.inh.set_trio_genotypes(var) self.assertEqual(self.inh.check_homozygous("X-linked dominant"), "single_variant") self.assertEqual( self.inh.log_string, "male X chrom inherited from het mother or hom affected mother") # check for trio = 210, with affected mother, which should also pass self.inh.mother_affected = True self.assertEqual(self.inh.check_homozygous("X-linked dominant"), "single_variant") self.assertEqual( self.inh.log_string, "male X chrom inherited from het mother or hom affected mother") # check for trio = 220, with affected mother var = TrioGenotypes('X', 100, create_snv('M', "1/1"), create_snv('F', "1/1"), create_snv('M', "0/0")) self.inh.set_trio_genotypes(var) self.assertEqual(self.inh.check_homozygous("X-linked dominant"), "single_variant") self.assertEqual( self.inh.log_string, "male X chrom inherited from het mother or hom affected mother") # check for trio = 220, with unaffected mother, which should not pass self.inh.mother_affected = False self.assertEqual(self.inh.check_homozygous("X-linked dominant"), "nothing") self.assertEqual(self.inh.log_string, "variant not compatible with being causal") # check that homozygous X-linked over-dominance doesn't pass self.assertEqual(self.inh.check_homozygous("X-linked over-dominance"), 'nothing') # check we raise errors with unknown inheritance modes with self.assertRaises(ValueError): self.inh.check_homozygous("Digenic")
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 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 = create_snv(child_gender, "0/1", chrom='X', pos=150, extra_info='HGNC=TEST;MAX_AF=0.0005') mom = create_snv("F", "0/0", chrom='X', pos=150) dad = create_snv("M", "0/0", chrom='X', pos=150) self.variants = [TrioGenotypes('X', '150', child, mom, dad)] self.report = Report(None, None, None) Info.set_populations([ "AFR_AF", "AMR_AF", "ASN_AF", "DDD_AF", "EAS_AF", "ESP_AF", "EUR_AF", "MAX_AF", "SAS_AF", "UK10K_cohort_AF" ])
def test_is_compound_pair_cnv_maternal(self): """ check that is_compound_pair() includes pairs with CNVs """ # generate a test variant chrom = "1" position = "60000" extra = [('CIFER_INHERITANCE', 'maternal')] child = create_cnv("F", "maternal", chrom=chrom, pos=position, format=extra) mom = create_cnv("F", "unknown", chrom=chrom, pos=position) dad = create_cnv("M", "unknown", chrom=chrom, pos=position) cnv = TrioGenotypes(chrom, position, child, mom, dad) # set some variants, so we can alter them later snv = self.create_variant(chrom="1", position="150", sex="F", cq="stop_gained") snv = self.set_compound_het_var(snv, "101") # check that these variants are compound hets, no matter which order # they are given as. self.assertTrue(self.inh.is_compound_pair(cnv, snv)) # check that if the SNV is inherited from the same parent as the CNV, # then the pair isn't a compound het. snv = self.set_compound_het_var(snv, "110") self.assertFalse(self.inh.is_compound_pair(cnv, snv))
def create_var(self, chrom, snv=True, geno=["0/1", "0/1", "0/1"], info=None, pos='150', **kwargs): """ 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 = self.create_snv(chrom, geno[0], info, **kwargs) mom = self.create_snv(chrom, geno[1], info, **kwargs) dad = self.create_snv(chrom, geno[2], info, **kwargs) else: child = self.create_cnv(chrom, info, **kwargs) mom = self.create_cnv(chrom, info, **kwargs) dad = self.create_cnv(chrom, info, **kwargs) return TrioGenotypes(chrom, pos, child, mom, dad)
def combine_trio_variants(family, 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 """ variants = [] for child in child_vars: mom, dad = None, None if family.has_parents(): mom = get_parental_var(child, mother_vars, family.mother) dad = get_parental_var(child, father_vars, family.father) trio = TrioGenotypes(child.get_chrom(), child.get_position(), child, mom, dad, SNV.debug_chrom, SNV.debug_pos) variants.append(trio) return variants
def setUp(self): """ define a family and variant, and start the Autosomal class """ # generate a test family sex = "F" mom_aff = "1" dad_aff = "1" self.trio = self.create_family(sex, mom_aff, dad_aff) # generate a test variant child = create_snv(sex, "0/1") mom = create_snv("F", "0/0") dad = create_snv("M", "0/0") var = TrioGenotypes(child.get_chrom(), child.get_position(), child, mom, dad) self.variants = [var] # make sure we've got known genes data self.known_gene = { "inh": ["Monoallelic"], "confirmed_status": ["confirmed dd gene"] } self.inh = Autosomal(self.variants, self.trio, self.known_gene, "1001") 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 = "1" position = "60000" child = create_cnv("F", "unknown", chrom=chrom, pos=position) mom = create_cnv("F", "unknown", chrom=chrom, pos=position) dad = create_cnv("M", "unknown", chrom=chrom, pos=position) cnv = TrioGenotypes(chrom, position, child, mom, dad) 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) self.assertEqual(self.inh.check_homozygous("Biallelic"), "compound_het") self.assertEqual(self.inh.log_string, "non-mendelian, but CNV might affect call")
def test_is_compound_pair_cnv_de_novo(self): """ check that is_compound_pair() includes pairs with CNVs """ chrom = "1" position = "60000" extra = [('CIFER_INHERITANCE', 'not_inherited')] child = create_cnv("F", "maternal", chrom=chrom, pos=position, format=extra) mom = create_cnv("F", "unknown", chrom=chrom, pos=position) dad = create_cnv("M", "unknown", chrom=chrom, pos=position) cnv = TrioGenotypes(chrom, position, child, mom, dad) # set some variants, so we can alter them later snv = self.create_variant(chrom="1", position="150", sex="F", cq="stop_gained") snv = self.set_compound_het_var(snv, "101") snv.child.format.pop("PP_DNM") # check that these variants are compound hets, no matter which order # they are given as. self.assertTrue(self.inh.is_compound_pair(cnv, snv)) self.assertTrue(self.inh.is_compound_pair(snv, cnv)) #check the snv can also be maternal snv = self.set_compound_het_var(snv, "110") snv.child.format.pop("PP_DNM") self.assertTrue(self.inh.is_compound_pair(snv, cnv))
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": { "inheritance": ["Monoallelic"], "confirmed_status": ["Confirmed DD Gene"] } } gene_inh = self.known_genes[var.get_gene()]["inheritance"] self.inh = Autosomal(self.variants, self.trio, gene_inh) self.inh.is_lof = var.child.is_lof()
def create_var(self, chrom='1', position='150', sex='F', child_geno='0/1'): ''' generate a test variant ''' child = create_snv(sex, child_geno, chrom=chrom, pos=position) mom = create_snv("F", "0/0", chrom=chrom, pos=position) dad = create_snv("M", "0/0", chrom=chrom, pos=position) return TrioGenotypes(child.get_chrom(), child.get_position(), child, mom, dad)
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_variant(child_sex, cq, hgnc, chrom='1', pos='150'): ''' create a default TrioGenotypes variant ''' # generate a test variant child = create_snv(child_sex, '0/1', cq, hgnc, chrom) mom = create_snv('F', '0/0', cq, hgnc, chrom) dad = create_snv('M', '0/0', cq, hgnc, chrom) return TrioGenotypes(chrom, pos, child, mom, dad)
def test_load_trio(self): ''' test that load_trio() works correctly ''' def make_vcf(person): # make a VCF, where one line would pass the default filtering vcf = make_vcf_header() vcf.append(make_vcf_line(pos=1, extra='HGNC=TEST;MAX_AF=0.0001')) vcf.append(make_vcf_line(pos=2, extra='HGNC=ATRX;MAX_AF=0.0001')) path = os.path.join(self.temp_dir, "{}.vcf.gz".format(person)) write_gzipped_vcf(path, vcf) return path child_path = make_vcf('child') mother_path = make_vcf('mother') father_path = make_vcf('father') family = Family('fam_id') family.add_child('sample', 'mother_id', 'father_id', 'female', '2', child_path) family.add_mother('mother_id', '0', '0', 'female', '1', mother_path) family.add_father('father_id', '0', '0', 'male', '1', father_path) family.set_child() sum_x_lr2_proband = 0 # define the parameters and values for the SNV class args = { 'chrom': "1", 'position': 2, 'id': ".", 'ref': "G", 'alts': "T", 'filter': "PASS", 'info': "CQ=missense_variant;HGNC=ATRX;MAX_AF=0.0001", 'format': "DP:GT:AD", 'sample': "50:0/1:10,10", 'gender': "female", 'mnv_code': None, 'qual': '1000' } dad_args = copy.deepcopy(args) dad_args['gender'] = 'male' self.assertEqual(load_trio(family, sum_x_lr2_proband), [ TrioGenotypes(chrom="1", pos=2, child=SNV(**args), mother=SNV(**args), father=SNV(**dad_args)) ])
def test_check_heterozygous_de_novo(self): """ test that check_heterozygous() works correctly for de novos """ # all of these tests are run for female X chrom de novos, since male # X chrom hets don't exist var = TrioGenotypes('X', 100, create_snv('F', "1/0"), create_snv('F', "0/0"), create_snv('M', "0/0")) self.inh.set_trio_genotypes(var) # check for X-linked dominant inheritance self.assertEqual(self.inh.check_heterozygous("X-linked dominant"), "single_variant") self.assertEqual(self.inh.log_string, "female x chrom de novo") # check for biallelic inheritance self.assertEqual(self.inh.check_heterozygous("Hemizygous"), "single_variant") # check for X-linked over dominance self.assertEqual( self.inh.check_heterozygous("X-linked over-dominance"), 'single_variant') # check we raise errors with unknown inheritance modes with self.assertRaises(ValueError): self.inh.check_heterozygous("Digenic") genos = {'0': '0/0', '1': '1/0', '2': '1/1'} for (child, mom, dad) in ["102", "110", "112", "122"]: var = TrioGenotypes('X', 100, create_snv('F', genos[child]), create_snv('F', genos[mom]), create_snv('M', genos[dad])) self.inh.set_trio_genotypes(var) self.inh.check_heterozygous("X-linked dominant") self.assertNotEqual(self.inh.log_string, "female x chrom de novo")
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, sex): """ creates a TrioGenotypes variant """ chrom = '1' position = '150' info = 'CNS=3;CALLSOURCE=aCGH' format = [('CIFER_INHERITANCE', 'uncertain')] # generate a test variant child = create_cnv(sex, "unknown", extra_info=info, format=format) mom = create_cnv("F", "unknown", extra_info=info, format=format) dad = create_cnv("M", "unknown", extra_info=info, format=format) return TrioGenotypes(chrom, position, child, mom, dad)
def create_variant(self, chrom="1", position="150", sex='F', cq=None, geno=['0/1', '0/0', '0/0']): """ creates a TrioGenotypes variant """ # generate a test variant child = create_snv(sex, geno[0], cq, chrom=chrom, pos=position) mom = create_snv("F", geno[1], cq, chrom=chrom, pos=position) dad = create_snv("M", geno[2], cq, chrom=chrom, pos=position) return TrioGenotypes(chrom, position, child, mom, dad)
def test_check_variant_without_parents_male(self): """ test that check_variant_without_parents() works correctly for males """ var = TrioGenotypes('X', 100, create_snv('M', "1/1"), None, None) trio = self.create_family('male', '1', '1') self.inh = Allosomal([var], trio, self.known_gene, "TEST") self.inh.set_trio_genotypes(var) # check for X-linked dominant inheritance self.assertEqual( self.inh.check_variant_without_parents("X-linked dominant"), "single_variant") # and check for hemizygous inheritance self.assertEqual(self.inh.check_variant_without_parents("Hemizygous"), "single_variant")
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 = create_cnv("F", "unknown", chrom=chrom, pos=position) mom = create_cnv("F", "unknown", chrom=chrom, pos=position) dad = create_cnv("M", "unknown", chrom=chrom, pos=position) cnv_var = TrioGenotypes(chrom, position, child, mom, dad) # 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_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 test_getters(self): ''' test that the class getter methods work correctly ''' # create a variant where the child, mother and father variables are filled in var = self.create_var(chrom='1', position='150', sex='F', child_geno='0/1') self.assertEqual(var.get_chrom(), '1') self.assertEqual(var.get_position(), 150) self.assertEqual(var.get_genes(), [['1001']]) self.assertEqual(var.get_range(), (150, 150)) self.assertEqual(var.is_cnv(), False) self.assertEqual(var.get_inheritance_type(), 'autosomal') # construct a variant without values for the getter methods var = TrioGenotypes() self.assertEqual(var.get_chrom(), None) self.assertEqual(var.get_position(), None) self.assertEqual(var.get_genes(), None) self.assertEqual(var.get_range(), None) self.assertEqual(var.is_cnv(), None) self.assertEqual(var.get_inheritance_type(), None)
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 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)
def test_analyse_trio(self): ''' test that analyse_trio() works correctly ''' # construct the VCFs for the trio members paths = {} for member in ['child', 'mom', 'dad']: vcf = make_vcf_header() geno, pp_dnm = '0/0', '' if member == 'child': geno, pp_dnm = '0/1', ';DENOVO-SNP;PP_DNM=1' vcf.append( make_vcf_line(genotype=geno, extra='HGNC=ARID1B' + pp_dnm)) # write the VCF data to a file handle = tempfile.NamedTemporaryFile(dir=self.temp_dir, delete=False, suffix='.vcf') for x in vcf: handle.write(x.encode('utf8')) handle.flush() paths[member] = handle.name # create a Family object, so we can load the data from the trio's VCFs fam_id = 'fam01' child = Person(fam_id, 'child', 'dad', 'mom', 'female', '2', paths['child']) mom = Person(fam_id, 'mom', '0', '0', 'female', '1', paths['mom']) dad = Person(fam_id, 'dad', '0', '0', 'male', '1', paths['dad']) family = Family(fam_id, [child], mom, dad) self.assertEqual(self.finder.analyse_trio(family), [(TrioGenotypes( chrom="1", pos=1, child=SNV( chrom="1", position=1, id=".", ref="G", alts="T", qual='1000', filter="PASS", info="CQ=missense_variant;DENOVO-SNP;HGNC=ARID1B;PP_DNM=1", format="DP:GT", sample="50:0/1", gender="female", mnv_code=None), mother=SNV(chrom="1", position=1, id=".", ref="G", alts="T", qual='1000', filter="PASS", info="CQ=missense_variant;HGNC=ARID1B", format="DP:GT", sample="50:0/0", gender="female", mnv_code=None), father=SNV(chrom="1", position=1, id=".", ref="G", alts="T", qual='1000', filter="PASS", info="CQ=missense_variant;HGNC=ARID1B", format="DP:GT", sample="50:0/0", gender="male", mnv_code=None)), ['single_variant'], [ 'Monoallelic', 'Mosaic' ], ['ARID1B'])])