def construct_variant(self, line, gender): """ constructs a Variant object for a VCF line, specific to the variant type Args: line: list of elements of a single sample VCF line: [chrom, position, snp_id, ref_allele, alt_allele, quality, filter_value, info, format_keys, format_values] gender: gender of the individual to whom the variant line belongs (eg "1" or "M" for male, "2", or "F" for female). Returns: returns a Variant object """ # CNVs are found by their alt_allele values, as either <DUP>, or <DEL> if line[4] == "<DUP>" or line[4] == "<DEL>": var = CNV(line[0], line[1], line[2], line[3], line[4], line[6]) var.add_info(line[7]) # CNVs require the format values for filtering var.set_gender(gender) var.add_format(line[8], line[9]) if self.known_genes is not None: var.fix_gene_IDs() else: var = SNV(line[0], line[1], line[2], line[3], line[4], line[6]) var.add_info(line[7]) return var
def setUp(self): """ define a default VcfInfo object """ chrom = "1" pos = "15000000" snp_id = "." ref = "A" alt = "<DUP>" qual = "1000" filt = "PASS" info = "HGNC=TEST;HGNC_ALL=TEST,OR5A1;CQ=missense_variant;" \ "CNSOLIDATE;WSCORE=0.5;CALLP=0.000;COMMONFORWARDS=0.000;" \ "MEANLR2=0.5;MADL2R=0.02;END=16000000;SVLEN=1000000" keys = "inheritance:DP" values = "deNovo:50" sex = "F" # set up a CNV object self.var = CNV(chrom, pos, snp_id, ref, alt, qual, filt, info=info, format=keys, sample=values, gender=sex)
def create_cnv(self, chrom, info=None, pos='15000000', snp_id='.', ref='A', alt='<DUP>', qual='1000', filt='PASS', **kwargs): if info is None: info = "HGNC=TEST;HGNC_ALL=TEST,OR5A1;CQ=missense_variant;CNSOLIDATE;' \ 'WSCORE=0.5;CALLP=0.000;COMMONFORWARDS=0.000;MEANLR2=0.5;' \ 'MADL2R=0.02;END=16000000;SVLEN=1000000" keys = "inheritance:DP" values = "deNovo:50" return CNV(chrom, pos, snp_id, ref, alt, qual, filt, info=info, format=keys, sample=values, gender='male', **kwargs)
def create_cnv(self, gender, inh, chrom, pos, cq=None): """ create a default variant """ snp_id = "." ref = "A" alt = "<DEL>" filt = "PASS" if cq is None: cq = "transcript_ablation" # set up a SNV object, since SNV inherits VcfInfo var = CNV(chrom, pos, snp_id, ref, alt, filt) info = "CQ={};HGNC=TEST;HGNC_ALL=TEST;END=16000000;SVLEN=5000".format( cq) format_keys = "INHERITANCE:DP" sample_values = inh + ":50" var.add_info(info) var.add_format(format_keys, sample_values) var.set_gender(gender) var.set_genotype() return var
def test_construct_variant(self): """ test that construct_variant() works correctly """ # check that construct variant works for SNVs line = ["1", "100", ".", "T", "G", "1000", "PASS", ".", "GT", "0/1"] gender = "M" test_var = SNV(*line[:6]) variant = self.vcf_loader.construct_variant(line, gender) self.assertEqual(variant.get_key(), test_var.get_key()) # initally constructing a SNV shouldn't affect the format variable self.assertEqual(variant.format, None) # check that construct variant works for CNVs line = [ "1", "100", ".", "T", "<DEL>", "1000", "PASS", "END=200", "GT", "0/1" ] gender = "M" test_var = CNV(*line[:6]) test_var.add_info(line[7]) variant = self.vcf_loader.construct_variant(line, gender) self.assertEqual(variant.get_key(), test_var.get_key()) self.assertNotEqual(variant.format, None)
def test_construct_variant(self): """ test that construct_variant() works correctly """ # check that construct variant works for SNVs line = ["1", "100", ".", "T", "G", "1000", "PASS", ".", "GT", "0/1"] gender = "M" test_var = SNV(*line, gender=gender) variant = construct_variant(line, gender) self.assertEqual(variant.get_key(), test_var.get_key()) self.assertEqual(variant.format, {'GT': '0/1'}) # check that construct variant works for CNVs line = [ "1", "100", ".", "T", "<DEL>", "1000", "PASS", "END=200", "GT", "0/1" ] gender = "M" test_var = CNV(*line, gender=gender) variant = construct_variant(line, gender) self.assertEqual(variant.get_key(), test_var.get_key()) self.assertEqual(variant.format, {'GT': '0/1'})
def test_get_parental_var_cnv(self): ''' check that get_parental_var() works correctly for CNVs ''' sex = 'F' var = create_cnv(sex, 'deNovo') mom = Person('fam_id', 'mom', '0', '0', 'F', '1', '/PATH') parental_vars = [] self.assertEqual( get_parental_var(var, parental_vars, mom), CNV(chrom="1", position=150, id=".", ref="A", alts="<REF>", qual='1000', filter="PASS", info=str(var.info), format='INHERITANCE', sample='uncertain', gender="female", mnv_code=None)) # check that even if a CNV exist in the parent at a matching site, we # still create a new CNV objectr for the parent mother_var = create_cnv(sex, 'uncertain') self.assertEqual( get_parental_var(var, [mother_var], mom), CNV(chrom="1", position=150, id=".", ref="A", alts="<REF>", qual='1000', filter="PASS", info=str(var.info), format='INHERITANCE', sample='uncertain', gender="female", mnv_code=None))
def test_get_parental_var_cnv_maternally_inherited(self): ''' test that we can construct a maternally inherited CNV ''' sex = 'F' mom = Person('fam_id', 'mom', '0', '0', 'F', '1', '/PATH') # check that even if a CNV exist in the parent at a matching site, we # still create a new CNV object for the parent var = create_cnv(sex, 'maternal') self.assertEqual(get_parental_var(var, [], mom), CNV(chrom="1", position=150, id=".", ref="A", alts="<DUP>", qual='1000',filter="PASS", info=str(var.info), format='INHERITANCE', sample='uncertain', gender="female", mnv_code=None))
def test_include_variant(self): """ check that include_variant() works correctly """ child_variants = False gender = "M" # make a child var which passes the filters line = ["1", "100", ".", "T", "A", "1000", "PASS", "CQ=missense_variant;HGNC=ATRX", "GT", "0/1"] self.assertTrue(self.vcf_loader.include_variant(line, child_variants, gender)) # make a child var that fails the filters, which should return False line = ["1", "100", ".", "T", "A", "1000", "FAIL", "CQ=missense_variant;HGNC=ATRX", "GT", "0/1"] self.assertFalse(self.vcf_loader.include_variant(line, child_variants, gender)) # now check for parents variants child_variants = True # check a parents var, where we have a matching child var self.vcf_loader.child_keys = set([("1", 100), ("X", 200)]) line = ["1", "100", ".", "T", "A", "1000", "FAIL", "CQ=missense_variant;HGNC=ATRX", "GT", "0/1"] self.assertTrue(self.vcf_loader.include_variant(line, child_variants, gender)) # check a parents var, where we don't have a matching child var line = ["1", "200", ".", "T", "A", "1000", "FAIL", "CQ=missense_variant;HGNC=ATRX", "GT", "0/1"] self.assertFalse(self.vcf_loader.include_variant(line, child_variants, gender)) # and check parental CNVs line = ["1", "100", ".", "T", "<DEL>", "1000", "PASS", "END=200", "GT", "0/1"] gender = "M" test_var = CNV(*line[:6]) test_var.add_info(line[7]) # in this function we look for overlap in CNVs. Set up a child CNV # that the parents CNV must match. self.vcf_loader.cnv_matcher = MatchCNVs([test_var]) self.assertTrue(self.vcf_loader.include_variant(line, child_variants, gender)) # check that a parental CNV without any overlap to any childs CNVs, # fails to pass line = ["1", "300", ".", "T", "<DEL>", "1000", "PASS", "END=400", "GT", "0/1"] gender = "M" self.assertFalse(self.vcf_loader.include_variant(line, child_variants, gender))
def setUp(self): """ define a default VcfInfo object """ chrom = "1" pos = "15000000" snp_id = "." ref = "A" alt = "<DUP>" filt = "PASS" # set up a SNV object, since SNV inherits VcfInfo self.var = CNV(chrom, pos, snp_id, ref, alt, filt) info = "HGNC=TEST;HGNC_ALL=TEST,OR5A1;CQ=missense_variant;CNSOLIDATE;WSCORE=0.5;CALLP=0.000;COMMONFORWARDS=0.000;MEANLR2=0.5;MADL2R=0.02;END=16000000;SVLEN=1000000" format_keys = "inheritance:DP" sample_values = "deNovo:50" self.var.add_info(info) self.var.add_format(format_keys, sample_values) self.var.set_gender("F")
def create_cnv(self, chrom): pos = "15000000" snp_id = "." ref = "A" alt = "<DUP>" filt = "PASS" # set up a SNV object, since SNV inherits VcfInfo var = CNV(chrom, pos, snp_id, ref, alt, filt) info = "HGNC=TEST;HGNC_ALL=TEST,OR5A1;CQ=missense_variant;CNSOLIDATE;WSCORE=0.5;CALLP=0.000;COMMONFORWARDS=0.000;MEANLR2=0.5;MADL2R=0.02;END=16000000;SVLEN=1000000" format_keys = "inheritance:DP" sample_values = "deNovo:50" var.add_info(info) var.add_format(format_keys, sample_values) var.set_gender("F") var.set_genotype() return var
def test_include_variant(self): """ check that include_variant() works correctly """ mnvs = {} child_keys = None gender = "M" sum_x_l2r = {} # make a child var which passes the filters line = ["1", "100", ".", "T", "A", "1000", "PASS", "CQ=missense_variant;HGNC=ATRX", "GT", "0/1"] self.assertTrue(include_variant(line, child_keys, gender, mnvs, sum_x_l2r)) # make a child var that fails the filters, which should return False line = ["1", "100", ".", "T", "A", "1000", "FAIL", "CQ=missense_variant;HGNC=ATRX", "GT", "0/1"] self.assertFalse(include_variant(line, child_keys, gender, mnvs, sum_x_l2r)) # now check for parents variants # check a parents var, where we have a matching child var child_keys = set([("1", 100), ("X", 200)]) line = ["1", "100", ".", "T", "A", "1000", "FAIL", "CQ=missense_variant;HGNC=ATRX", "GT", "0/1"] self.assertTrue(include_variant(line, child_keys, gender, mnvs, sum_x_l2r)) # check a parents var, where we don't have a matching child var line = ["1", "200", ".", "T", "A", "1000", "FAIL", "CQ=missense_variant;HGNC=ATRX", "GT", "0/1"] self.assertFalse(include_variant(line, child_keys, gender, mnvs, sum_x_l2r)) # and check parental CNVs line = ["1", "100", ".", "T", "<DEL>", "1000", "PASS", "END=200", "GT", "0/1"] gender = "M" test_var = CNV(*line) # in this function we look for overlap in CNVs. Set up a child CNV # that the parents CNV must match. self.assertTrue(include_variant(line, child_keys, gender, mnvs, sum_x_l2r)) # check that a parental CNV without any overlap to any childs CNVs, # fails to pass line = ["1", "300", ".", "T", "<DEL>", "1000", "PASS", "END=400", "GT", "0/1"] gender = "M" self.assertFalse(include_variant(line, child_keys, gender, mnvs, sum_x_l2r))
def create_cnv(self, gender, inh, chrom, pos): """ create a default variant """ snp_id = "." ref = "A" alt = "<DUP>" filt = "PASS" # set up a SNV object, since SNV inherits VcfInfo var = CNV(chrom, pos, snp_id, ref, alt, filt) info = "HGNC=TEST;HGNC_ALL=TEST;END=16000000;SVLEN=5000" format_keys = "INHERITANCE:DP" sample_values = inh + ":50" var.add_info(info) var.add_format(format_keys, sample_values) var.set_gender(gender) var.set_genotype() return var
def setUp(self): """ define a default VcfInfo object """ chrom = "1" pos = "15000000" snp_id = "." ref = "A" alt = "<DUP>" filt = "PASS" # set up a SNV object, since SNV inherits VcfInfo cnv = CNV(chrom, pos, snp_id, ref, alt, filt) self.var = ExomeCNV(cnv) info = "HGNC=TEST;HGNC_ALL=TEST,OR5A1;CQ=missense_variant;CONVEX;RC50INTERNALFREQ=0.005;COMMONFORWARDS=0.000;MEANLR2=0.5;MADL2R=0.02" format_keys = "inheritance:DP" sample_values = "deNovo:50" self.var.cnv.add_info(info) self.var.cnv.add_format(format_keys, sample_values) self.var.cnv.set_gender("F")
def get_parental_var(self, var, parental_vars, gender, matcher): """ get the corresponding parental variant to a childs variant, or create a default variant with reference genotype. Args: var: childs var, as Variant object parental_vars: list of parental variants gender: gender of the parent matcher: cnv matcher for parent Returns: returns a Variant object, matched to the proband's variant """ key = var.get_key() # if the variant is a CNV, the corresponding variant might not match # the start site, so we look a variant that overlaps if isinstance(var, CNV) and matcher.has_match(var): key = matcher.get_overlap_key(key) for parental in parental_vars: if key == parental.get_key(): return parental # if the childs variant does not exist in the parents VCF, then we # create a default variant for the parent if isinstance(var, CNV): parental = CNV(var.chrom, var.position, var.variant_id, var.ref_allele, var.alt_allele, var.filter) else: parental = SNV(var.chrom, var.position, var.variant_id, var.ref_allele, var.alt_allele, var.filter) parental.set_gender(gender) parental.set_default_genotype() return parental