def test_get_padded_haplotypes(self): chrom = 'my_chrom' ref_seq = 'ATGCTACTGC' # (pos, ref, alt), pad, padded ref, padded alt, start, end cases = [ ((4, 'T', 'G'), 2, 'GCTAC', 'GCGAC', 2, 7), # sub ((4, 'T', 'TA'), 2, 'GCTAC', 'GCTAAC', 2, 7), # ins ((4, 'T', 'GA'), 2, 'GCTAC', 'GCGAAC', 2, 7), # sub ins ((4, 'TA', 'T'), 2, 'GCTACT', 'GCTCT', 2, 8), # del ((4, 'TA', 'G'), 2, 'GCTACT', 'GCGCT', 2, 8), # sub del # test what happens for variant at start and end of chrom ((0, 'A', 'G'), 2, 'ATG', 'GTG', 0, 3), # sub at start ((0, 'A', 'AG'), 2, 'ATG', 'AGTG', 0, 3), # ins at start ((0, 'AT', 'T'), 2, 'ATGC', 'TGC', 0, 4), # del at start ((9, 'C', 'G'), 2, 'TGC', 'TGG', 7, 10), # sub at end ((9, 'C', 'CG'), 2, 'TGC', 'TGCG', 7, 10), # ins at end ((8, 'GC', 'G'), 2, 'CTGC', 'CTG', 6, 10), # del at end ] for ((pos, ref, alt), pad, pad_ref, pad_alt, start, end) in cases: var = Variant(chrom, pos, ref, alt) padded, region = get_padded_haplotypes(var, ref_seq, pad) self.assertEqual(pad_ref, padded[0]) self.assertEqual(pad_alt, padded[1]) self.assertEqual(region.start, start) self.assertEqual(region.end, end)
def test_raises(self): chrom = 'my_chrom' ref_seq = 'ATGCTACTGC' var = Variant(chrom, 2, 'GT', 'G') # ref should be GC with self.assertRaises(ValueError): get_padded_haplotypes(var, ref_seq, 2)