test_variantchecker.py 35.3 KB
Newer Older
1
"""
2
Tests for the variantchecker module.
3
4
"""

5

6
#import logging; logging.basicConfig()
7
from nose.tools import *
8

9
from mutalyzer.output import Output
Vermaat's avatar
Vermaat committed
10
11
from mutalyzer.Db import Cache
from mutalyzer.Retriever import GenBankRetriever
12
from mutalyzer.variantchecker import check_variant
13
14


15
class TestVariantchecker():
16
    """
17
    Test the variantchecker module.
18
19
20
    """
    def setUp(self):
        """
21
        Initialize test variantchecker module.
22
        """
23
        self.output = Output(__file__)
Vermaat's avatar
Vermaat committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
        self.cache_database = Cache()
        self.retriever = GenBankRetriever(self.output, self.cache_database)

    def _slice(self, chromosome, start, stop, orientation):
        """
        Get a UD slice.

        Orientation: 1 for forward, 2 for reverse.
        """
        return self.retriever.retrieveslice(chromosome, start, stop, orientation)

    def _slice_gene(self, gene, organism='human', upstream=5000, downstream=2000):
        """
        Get a UD slice for a gene.
        """
        return self.retriever.retrievegene(gene, organism, upstream, downstream)
40

41
42
43
44
45
46
    def _load_record(self, identifier):
        """
        Load a record in the database and cache.
        """
        return self.retriever.loadrecord(identifier)

47
48
49
50
51
    def test_deletion_in_frame(self):
        """
        Simple in-frame deletion should give a simple description on protein
        level.
        """
52
        check_variant('AL449423.14(CDKN2A_v001):c.161_163del', self.output)
53
54
55
56
57
58
59
60
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'AL449423.14:g.61937_61939del')
        assert 'AL449423.14(CDKN2A_v001):c.161_163del' \
               in self.output.getOutput('descriptions')
        assert 'AL449423.14(CDKN2A_i001):p.(Met54_Gly55delinsSer)' \
               in self.output.getOutput('protDescriptions')
        assert self.output.getOutput('newprotein')

61
62
63
64
65
    def test_insertion_in_frame(self):
        """
        Simple in-frame insertion should give a simple description on protein
        level.
        """
66
        check_variant('AL449423.14(CDKN2A_v001):c.161_162insATC', self.output)
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'AL449423.14:g.61938_61939insGAT')
        assert 'AL449423.14(CDKN2A_v001):c.161_162insATC' \
               in self.output.getOutput('descriptions')
        assert 'AL449423.14(CDKN2A_i001):p.(Met54delinsIleSer)' \
               in self.output.getOutput('protDescriptions')
        assert self.output.getOutput('newprotein')

    def test_deletion_insertion_in_frame(self):
        """
        Simple in-frame deletion/insertion should give a simple description on
        protein level.
        """
        check_variant('AL449423.14(CDKN2A_v001):c.161_162delinsATCCC',
81
                      self.output)
82
83
84
85
86
87
88
89
90
91
92
93
94
95
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'AL449423.14:g.61938_61939delinsGGGAT')
        assert 'AL449423.14(CDKN2A_v001):c.161_162delinsATCCC' \
               in self.output.getOutput('descriptions')
        assert 'AL449423.14(CDKN2A_i001):p.(Met54delinsAsnPro)' \
               in self.output.getOutput('protDescriptions')
        assert self.output.getOutput('newprotein')

    def test_deletion_insertion_in_frame_complete(self):
        """
        Simple in-frame deletion/insertion should give a simple description on
        protein level, also with the optional deleted sequence argument.
        """
        check_variant('AL449423.14(CDKN2A_v001):c.161_162delTGinsATCCC',
96
                      self.output)
97
98
99
100
101
102
103
104
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'AL449423.14:g.61938_61939delinsGGGAT')
        assert 'AL449423.14(CDKN2A_v001):c.161_162delinsATCCC' \
               in self.output.getOutput('descriptions')
        assert 'AL449423.14(CDKN2A_i001):p.(Met54delinsAsnPro)' \
               in self.output.getOutput('protDescriptions')
        assert self.output.getOutput('newprotein')

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    def test_est_warning_nm_est(self):
        """
        Warning for EST positioning on NM reference.
        """
        check_variant('NM_003002.2:274del', self.output)
        west = self.output.getMessagesWithErrorCode('WEST')
        assert len(west) == 1

    def test_no_est_warning_nm_c(self):
        """
        No EST warning for c. positioning on NM reference.
        """
        check_variant('NM_003002.2:c.274del', self.output)
        west = self.output.getMessagesWithErrorCode('WEST')
        assert len(west) == 0

    def test_no_est_warning_nm_n(self):
        """
        No EST warning for n. positioning on NM reference.
        """
        check_variant('NM_003002.2:n.274del', self.output)
        west = self.output.getMessagesWithErrorCode('WEST')
        assert len(west) == 0

    def test_est_warning_ng_est(self):
        """
        Warning for EST positioning on NG reference.
        """
        check_variant('NG_012772.1:128del', self.output)
        west = self.output.getMessagesWithErrorCode('WEST')
        assert len(west) == 1

    def test_no_est_warning_ng_g(self):
        """
        No EST warning for g. positioning on NG reference.
        """
        check_variant('NG_012772.1:g.128del', self.output)
        west = self.output.getMessagesWithErrorCode('WEST')
        assert len(west) == 0

    def test_no_est_warning_est_est(self):
        """
        No warning for EST positioning on EST reference.
        """
        check_variant('AA010203.1:54_55insG', self.output)
        west = self.output.getMessagesWithErrorCode('WEST')
        assert len(west) == 0

153
154
155
156
    def test_roll(self):
        """
        Just a variant where we should roll.
        """
157
        check_variant('NM_003002.2:c.273del', self.output)
Vermaat's avatar
Vermaat committed
158
        wroll = self.output.getMessagesWithErrorCode('WROLLFORWARD')
159
        assert len(wroll) > 0
160
161
162

    def test_no_roll(self):
        """
163
        Just a variant where we cannot roll.
164
        """
165
        check_variant('NM_003002.2:c.274del', self.output)
Vermaat's avatar
Vermaat committed
166
        wroll = self.output.getMessagesWithErrorCode('WROLLFORWARD')
167
        assert_equal(len(wroll), 0)
168

169
170
171
172
    def test_no_roll_splice(self):
        """
        Here we can roll but should not, because it is over a splice site.
        """
173
        check_variant('NM_000088.3:g.459del', self.output)
174
        wrollback = self.output.getMessagesWithErrorCode('IROLLBACK')
175
        assert len(wrollback) > 0
Vermaat's avatar
Vermaat committed
176
        wroll = self.output.getMessagesWithErrorCode('WROLLFORWARD')
177
        assert_equal(len(wroll), 0)
178

179
180
181
182
183
    def test_partial_roll_splice(self):
        """
        Here we can roll two positions, but should roll only one because
        otherwise it is over a splice site.
        """
184
        check_variant('NM_000088.3:g.494del', self.output)
185
        wrollback = self.output.getMessagesWithErrorCode('IROLLBACK')
186
        assert len(wrollback) > 0
Vermaat's avatar
Vermaat committed
187
        wroll = self.output.getMessagesWithErrorCode('WROLLFORWARD')
188
        assert len(wroll) > 0
189

190
191
192
193
    def test_roll_after_splice(self):
        """
        Here we can roll and should, we stay in the same exon.
        """
194
        check_variant('NM_000088.3:g.460del', self.output)
Vermaat's avatar
Vermaat committed
195
        wroll = self.output.getMessagesWithErrorCode('WROLLFORWARD')
196
        assert len(wroll) > 0
197

Vermaat's avatar
Vermaat committed
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
    def test_roll_both_ins(self):
        """
        Insertion that rolls should not use the same inserted sequence in
        descriptions on forward and reverse strands.

        Here we have the following situation on the forward strand:

                                65470 (genomic)
                                  |
          CGGTGCGTTGGGCAGCGCCCCCGCCTCCAGCAGCGCCCGCACCTCCTCTA

        Now, an insertion of TAC after 65470 should be rolled to an insertion
        of ACT after 65471:

          CGGTGCGTTGGGCAGCGCCCCCGCC --- TCCAGCAGCGCCCGCACCTCCTCTA
          CGGTGCGTTGGGCAGCGCCCCCGCC TAC TCCAGCAGCGCCCGCACCTCCTCTA  =>

          CGGTGCGTTGGGCAGCGCCCCCGCCT --- CCAGCAGCGCCCGCACCTCCTCTA
          CGGTGCGTTGGGCAGCGCCCCCGCCT ACT CCAGCAGCGCCCGCACCTCCTCTA

        However, in CDKN2A_v001 (on the reverse strand), this insertion should
        roll the other direction and the inserted sequence should be the reverse
        complement of CTA, which is TAG, and not that of ACT, which is AGT.

        The next test (test_roll_reverse_ins) tests the situation for an input
        of AL449423.14:g.65471_65472insACT, where only the reverse roll should
        be done.
        """
226
        check_variant('AL449423.14:g.65470_65471insTAC', self.output)
Vermaat's avatar
Vermaat committed
227
228
        assert 'AL449423.14(CDKN2A_v001):c.99_100insTAG' in self.output.getOutput('descriptions')
        assert_equal ('AL449423.14:g.65471_65472insACT', self.output.getIndexedOutput('genomicDescription', 0, ''))
229
        assert_equal(len(self.output.getMessagesWithErrorCode('WROLLFORWARD')), 1)
Vermaat's avatar
Vermaat committed
230
231
232
233
234
235

    def test_roll_reverse_ins(self):
        """
        Insertion that rolls on the reverse strand should not use the same
        inserted sequence in descriptions on forward and reverse strands.
        """
236
        check_variant('AL449423.14:g.65471_65472insACT', self.output)
Vermaat's avatar
Vermaat committed
237
238
        assert 'AL449423.14(CDKN2A_v001):c.99_100insTAG' in self.output.getOutput('descriptions')
        assert_equal ('AL449423.14:g.65471_65472insACT', self.output.getIndexedOutput('genomicDescription', 0, ''))
239
        assert_equal(len(self.output.getMessagesWithErrorCode('WROLLFORWARD')), 0)
Vermaat's avatar
Vermaat committed
240
241
242
243
244
245

    def test_roll_message_forward(self):
        """
        Roll warning message should only be shown for currently selected
        strand (forward).
        """
246
        check_variant('AL449423.14:g.65470_65471insTAC', self.output)
247
248
        assert_equal(len(self.output.getMessagesWithErrorCode('WROLLFORWARD')), 1)
        assert_equal(len(self.output.getMessagesWithErrorCode('WROLLREVERSE')), 0)
Vermaat's avatar
Vermaat committed
249
250
251
252
253
254

    def test_roll_message_reverse(self):
        """
        Roll warning message should only be shown for currently selected
        strand (reverse).
        """
255
        check_variant('AL449423.14(CDKN2A_v001):c.98_99insGTA', self.output)
256
257
        assert_equal(len(self.output.getMessagesWithErrorCode('WROLLFORWARD')), 0)
        assert_equal(len(self.output.getMessagesWithErrorCode('WROLLREVERSE')), 1)
Vermaat's avatar
Vermaat committed
258

259
260
261
262
    def test_ins_cds_start(self):
        """
        Insertion on CDS start boundary should not be included in CDS.
        """
263
        check_variant('NM_000143.3:c.-1_1insCAT', self.output)
264
        assert_equal(self.output.getIndexedOutput("newprotein", 0), None)
265
        # Todo: Is this a good test?
266
267
268
269
270

    def test_ins_cds_start_after(self):
        """
        Insertion after CDS start boundary should be included in CDS.
        """
271
        check_variant('NM_000143.3:c.1_2insCAT', self.output)
272
        assert_equal(self.output.getIndexedOutput("newprotein", 0), '?')
273
274
275
276
277
278
        # Todo: Is this a good test?

    def test_del_splice_site(self):
        """
        Deletion hitting one splice site should not do a protein prediction.
        """
279
        check_variant('NG_012772.1(BRCA2_v001):c.632-5_670del', self.output)
280
        assert len(self.output.getMessagesWithErrorCode('WOVERSPLICE')) > 0
281
        assert_equal(self.output.getOutput('removedSpliceSites'), [])
282
283
284
285
286
287
288
289
        # Todo: For now, the following is how to check if no protein
        # prediction is done.
        assert not self.output.getOutput('newprotein')

    def test_del_exon(self):
        """
        Deletion of an entire exon should be possible.
        """
290
        check_variant('NG_012772.1(BRCA2_v001):c.632-5_681+7del', self.output)
291
        assert len(self.output.getMessagesWithErrorCode('WOVERSPLICE')) > 0
292
293
294
295
296
297
298
299
300
        assert_equal(self.output.getOutput('removedSpliceSites'), [2])
        # Todo: For now, the following is how to check if protein
        # prediction is done.
        assert self.output.getOutput('newprotein')

    def test_del_exon_exact(self):
        """
        Deletion of exactly an exon should be possible.
        """
301
        check_variant('NG_012772.1(BRCA2_v001):c.632_681del', self.output)
302
303
        assert_equal(len(self.output.getMessagesWithErrorCode('WOVERSPLICE')), 0)
        assert_equal(self.output.getOutput('removedSpliceSites'), [2])
304
305
306
307
308
309
310
311
312
313
314
315
316
        # Todo: For now, the following is how to check if protein
        # prediction is done.
        assert self.output.getOutput('newprotein')

    def test_del_exon_in_frame(self):
        """
        Deletion of an entire exon with length a triplicate should give a
        proteine product with just this deletion (and possibly substitutions
        directly before and after).

        NG_012772.1(BRCA2_v001):c.68-7_316+7del is such a variant, since
        positions 68 through 316 are exactly one exon and (316-68+1)/3 = 83.
        """
317
        check_variant('NG_012772.1(BRCA2_v001):c.68-7_316+7del', self.output)
318
        assert len(self.output.getMessagesWithErrorCode('WOVERSPLICE')) > 0
319
        assert_equal(self.output.getOutput('removedSpliceSites'), [2])
320
321
322
323
324
325
326
327
328
        # Todo: For now, the following is how to check if protein
        # prediction is done.
        assert self.output.getOutput('newprotein')
        # Todo: assert that protein products indeed have only this difference.

    def test_del_exons(self):
        """
        Deletion of two entire exons should be possible.
        """
329
        check_variant('NG_012772.1(BRCA2_v001):c.632-5_793+7del', self.output)
330
        assert len(self.output.getMessagesWithErrorCode('WOVERSPLICE')) > 0
331
        assert_equal(self.output.getOutput('removedSpliceSites'), [4])
332
333
334
335
336
337
338
339
340
        # Todo: For now, the following is how to check if protein
        # prediction is done.
        assert self.output.getOutput('newprotein')

    def test_del_intron(self):
        """
        Deletion of an entire intron should be possible (fusion of remaining
        exonic parts).
        """
341
        check_variant('NG_012772.1(BRCA2_v001):c.622_674del', self.output)
342
        assert len(self.output.getMessagesWithErrorCode('WOVERSPLICE')) > 0
343
        assert_equal(self.output.getOutput('removedSpliceSites'), [2])
344
345
346
347
        # Todo: For now, the following is how to check if protein
        # prediction is done.
        assert self.output.getOutput('newprotein')

348
349
350
351
352
    def test_del_intron_exact(self):
        """
        Deletion of exactly an intron should be possible (fusion of flanking
        exons).
        """
353
        check_variant('NG_012772.1(BRCA2_v001):c.681+1_682-1del', self.output)
354
355
356
357
358
359
360
361
362
        assert_equal(self.output.getMessagesWithErrorCode('WOVERSPLICE'), [])
        assert_equal(self.output.getOutput('removedSpliceSites'), [2])
        # Note: The protein prediction is done, but 'newprotein' is not set
        # because we have no change. So to check if the prediction is done, we
        # check if 'oldprotein' is set and to check if the prediction is
        # correct, we check if 'newprotein' is not set.
        assert self.output.getOutput('oldprotein')
        assert not self.output.getOutput('newprotein')

363
364
365
366
367
    def test_del_intron_in_frame(self):
        """
        Deletion of an entire intron should be possible (fusion of remaining
        exonic parts).
        """
368
        check_variant('NG_012772.1(BRCA2_v001):c.622_672del', self.output)
369
        assert len(self.output.getMessagesWithErrorCode('WOVERSPLICE')) > 0
370
        assert_equal(self.output.getOutput('removedSpliceSites'), [2])
371
372
373
374
375
376
377
378
379
        # Todo: For now, the following is how to check if protein
        # prediction is done.
        assert self.output.getOutput('newprotein')
        # Todo: assert that protein products indeed have only this difference.

    def test_del_exon_unknown_offsets(self):
        """
        Deletion of an entire exon with unknown offsets should be possible.
        """
380
        check_variant('NG_012772.1(BRCA2_v001):c.632-?_681+?del', self.output)
381
382
383
384
385
386
387
388
389
390
        assert len(self.output.getMessagesWithErrorCode('WOVERSPLICE')) > 0
        assert len(self.output.getMessagesWithErrorCode('IDELSPLICE')) > 0
        # Todo: For now, the following is how to check if protein
        # prediction is done.
        assert self.output.getOutput('newprotein')
        # Genomic positions should be centered in flanking introns and unsure.
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'NG_012772.1:g.(17550_19725)del')
        assert 'NG_012772.1(BRCA2_v001):c.632-?_681+?del' \
               in self.output.getOutput('descriptions')
391
392
        assert 'NG_012772.1(BRCA2_i001):p.(Val211Glufs*10)' \
               in self.output.getOutput('protDescriptions')
393
394
395
396
397
398
399
400
401
402
403
404
        # Todo: .c notation should still be c.632-?_681+?del, but what about
        # other transcripts?

    def test_del_exon_unknown_offsets_in_frame(self):
        """
        Deletion of an entire exon with unknown offsets and length a
        triplicate should give a proteine product with just this deletion
        (and possibly substitutions directly before and after).

        NG_012772.1(BRCA2_v001):c.68-?_316+?del is such a variant, since
        positions 68 through 316 are exactly one exon and (316-68+1)/3 = 83.
        """
405
        check_variant('NG_012772.1(BRCA2_v001):c.68-?_316+?del', self.output)
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
        assert len(self.output.getMessagesWithErrorCode('WOVERSPLICE')) > 0
        assert len(self.output.getMessagesWithErrorCode('IDELSPLICE')) > 0
        # Todo: For now, the following is how to check if protein
        # prediction is done.
        assert self.output.getOutput('newprotein')
        # Genomic positions should be centered in flanking introns and unsure.
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'NG_012772.1:g.(7324_11720)del')
        assert 'NG_012772.1(BRCA2_v001):c.68-?_316+?del' \
               in self.output.getOutput('descriptions')
        # Todo: .c notation should still be c.632-?_681+?del, but what about
        # other transcripts?

    def test_del_exon_unknown_offsets_composed(self):
        """
        Deletion of an entire exon with unknown offsets and another composed
        variant with exact positioning should be possible.
        """
424
        check_variant('NG_012772.1(BRCA2_v001):c.[632-?_681+?del;681+4del]',
425
                      self.output)
426
427
428
429
430
431
432
        assert len(self.output.getMessagesWithErrorCode('WOVERSPLICE')) > 0
        assert len(self.output.getMessagesWithErrorCode('IDELSPLICE')) > 0
        # Todo: For now, the following is how to check if protein
        # prediction is done.
        assert self.output.getOutput('newprotein')
        # Genomic positions should be centered in flanking introns and unsure.
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
433
434
435
436
437
438
439
440
441
442
443
444
                     'NG_012772.1:g.[(17550_19725)del;19017del]')
        assert 'NG_012772.1(BRCA2_v001):c.[632-?_681+?del;681+4del]' \
               in self.output.getOutput('descriptions')
        # Todo: .c notation should still be c.632-?_681+?del, but what about
        # other transcripts?

    def test_del_exon_unknown_offsets_reverse(self):
        """
        Deletion of an entire exon with unknown offsets should be possible,
        also on the reverse strand.
        """
        check_variant('AL449423.14(CDKN2A_v001):c.151-?_457+?del',
445
                      self.output)
446
447
448
449
450
451
452
453
454
        assert len(self.output.getMessagesWithErrorCode('WOVERSPLICE')) > 0
        assert len(self.output.getMessagesWithErrorCode('IDELSPLICE')) > 0
        # Todo: For now, the following is how to check if protein
        # prediction is done.
        assert self.output.getOutput('newprotein')
        # Genomic positions should be centered in flanking introns and unsure.
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'AL449423.14:g.(60314_63683)del')
        assert 'AL449423.14(CDKN2A_v001):c.151-?_457+?del' \
455
456
457
               in self.output.getOutput('descriptions')
        # Todo: .c notation should still be c.632-?_681+?del, but what about
        # other transcripts?
458
459
460
461
462
463
464
465

    def test_del_exon_transcript_reference(self):
        """
        Deletion of entire exon on a transcript reference should remove the
        expected splice sites (only that of the deleted exon), and not those
        of the flanking exons (as would happen using the mechanism for genomic
        references).
        """
466
        check_variant('NM_018723.3:c.758_890del', self.output)
467
468
469
470
471
        assert_equal(len(self.output.getMessagesWithErrorCode('WOVERSPLICE')), 0)
        assert_equal(self.output.getOutput('removedSpliceSites'), [2])
        # Todo: For now, the following is how to check if protein
        # prediction is done.
        assert self.output.getOutput('newprotein')
Vermaat's avatar
Vermaat committed
472
473
474
475
476

    def test_ins_range(self):
        """
        Insertion of a range is not implemented yet.
        """
477
        check_variant('AB026906.1:c.274_275ins262_268', self.output)
Vermaat's avatar
Vermaat committed
478
479
480
481
482
483
        assert_equal(len(self.output.getMessagesWithErrorCode('ENOTIMPLEMENTED')), 1)

    def test_delins_range(self):
        """
        Deletion/insertion of a range is not implemented yet.
        """
484
        check_variant('AB026906.1:c.274delins262_268', self.output)
Vermaat's avatar
Vermaat committed
485
        assert_equal(len(self.output.getMessagesWithErrorCode('ENOTIMPLEMENTED')), 1)
486

487
488
489
490
    def test_contig_reference(self):
        """
        Variant description on a CONTIG RefSeq reference.
        """
491
        check_variant('NG_005990.1:g.1del', self.output)
492
493
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'NG_005990.1:g.1del')
494
495
496
497
498
499
500

    def test_no_reference(self):
        """
        Variant description without a reference.
        """
        check_variant('g.244355733del', self.output)
        assert_equal(len(self.output.getMessagesWithErrorCode('ENOREF')), 1)
Vermaat's avatar
Vermaat committed
501

502
    def test_chromosomal_positions(self):
503
        """
504
        Variants on transcripts in c. notation should have chromosomal positions
505
506
        defined.
        """
Vermaat's avatar
Vermaat committed
507
        check_variant('NM_003002.2:c.274G>T', self.output)
508
        assert_equal(self.output.getIndexedOutput('rawVariantsChromosomal', 0),
Vermaat's avatar
Vermaat committed
509
                     ('chr11', '+', [('274G>T', (111959695, 111959695))]))
510
511
512
513
514
515
516
517

    def test_ex_notation(self):
        """
        Variant description using EX notation should not crash but deletion of
        one exon should delete two splice sites.
        """
        check_variant('NM_002001.2:c.EX1del', self.output)
        assert_equal(len(self.output.getMessagesWithErrorCode('IDELSPLICE')), 1)
Vermaat's avatar
Vermaat committed
518
519
520
521
522
523
524
525
526
527

    def test_lrg_reference(self):
        """
        We should be able to use LRG reference sequence without error.
        """
        check_variant('LRG_1t1:c.266G>T', self.output)
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'LRG_1:g.6855G>T')
528
529
530
531
532
533
534

    def test_non_numeric_locus_tag_ending(self):
        """
        Locus tag in NC_002128 does not end in an underscore and three digits
        but we should not crash on it.
        """
        check_variant('NC_002128(tagA):c.3del', self.output)
Vermaat's avatar
Vermaat committed
535
536
537
538
539

    def test_gi_reference_plain(self):
        """
        Test reference sequence notation with GI number.
        """
540
        assert self._load_record('NM_002001.2')  # Make sure it's in our database
Vermaat's avatar
Vermaat committed
541
542
543
544
545
546
547
548
549
550
551
552
        check_variant('31317229:c.6del', self.output)
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     '31317229:n.105del')
        assert '31317229(FCER1A_v001):c.6del' \
               in self.output.getOutput('descriptions')

    def test_gi_reference_prefix(self):
        """
        Test reference sequence notation with GI number and prefix.
        """
553
        assert self._load_record('NM_002001.2')  # Make sure it's in our database
Vermaat's avatar
Vermaat committed
554
555
556
557
558
559
560
561
562
563
564
565
        check_variant('GI31317229:c.6del', self.output)
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     '31317229:n.105del')
        assert '31317229(FCER1A_v001):c.6del' \
               in self.output.getOutput('descriptions')

    def test_gi_reference_prefix_colon(self):
        """
        Test reference sequence notation with GI number and prefix with colon.
        """
566
        assert self._load_record('NM_002001.2')  # Make sure it's in our database
Vermaat's avatar
Vermaat committed
567
568
569
570
571
572
573
        check_variant('GI:31317229:c.6del', self.output)
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     '31317229:n.105del')
        assert '31317229(FCER1A_v001):c.6del' \
               in self.output.getOutput('descriptions')
Vermaat's avatar
Vermaat committed
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590

    def test_nop_nm(self):
        """
        Variant on NM without effect should be described as '='.
        """
        check_variant('NM_002001.2:c.1_3delinsATG', self.output)
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'NM_002001.2:n.=')
        assert 'NM_002001.2(FCER1A_v001):c.=' \
               in self.output.getOutput('descriptions')

    def test_nop_ud(self):
        """
        Variant on UD without effect should be described as '='.
        """
Vermaat's avatar
Vermaat committed
591
592
        ud = self._slice_gene('DMD')
        check_variant(ud + ':g.5T>T', self.output)
Vermaat's avatar
Vermaat committed
593
594
595
596
597
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicChromDescription', 0),
                     'NC_000023.10:g.=')
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
Vermaat's avatar
Vermaat committed
598
599
                     ud + ':g.=')
        assert ud + '(DMD_v001):c.=' \
Vermaat's avatar
Vermaat committed
600
               in self.output.getOutput('descriptions')
601

Vermaat's avatar
Vermaat committed
602
603
604
605
606
    def test_ud_reverse_sequence(self):
        """
        Variant on UD from reverse strand should have reverse complement
        sequence.
        """
Vermaat's avatar
Vermaat committed
607
608
        ud = self._slice_gene('DPYD')
        check_variant(ud + '(DPYD_v1):c.85C>T', self.output)
Vermaat's avatar
Vermaat committed
609
610
611
612
613
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicChromDescription', 0),
                     'NC_000001.10:g.98348885G>A')
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
Vermaat's avatar
Vermaat committed
614
615
                     ud + ':g.42731C>T')
        assert ud + '(DPYD_v001):c.85C>T' \
Vermaat's avatar
Vermaat committed
616
617
618
619
620
621
               in self.output.getOutput('descriptions')

    def test_ud_forward_sequence(self):
        """
        Variant on UD from forward strand should have forward sequence.
        """
Vermaat's avatar
Vermaat committed
622
623
        ud = self._slice_gene('MARK1')
        check_variant(ud + '(MARK1_v001):c.400T>C', self.output)
Vermaat's avatar
Vermaat committed
624
625
626
627
628
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicChromDescription', 0),
                     'NC_000001.10:g.220773181T>C')
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
Vermaat's avatar
Vermaat committed
629
630
                     ud + ':g.76614T>C')
        assert ud + '(MARK1_v001):c.400T>C' \
Vermaat's avatar
Vermaat committed
631
632
633
634
635
636
637
               in self.output.getOutput('descriptions')

    def test_ud_reverse_range(self):
        """
        Variant on UD from reverse strand should have reversed range
        positions.
        """
Vermaat's avatar
Vermaat committed
638
639
        ud = self._slice('NC_000009.11', 32922603, 33006639, 2)
        check_variant(ud + ':g.10624_78132del', self.output)
Vermaat's avatar
Vermaat committed
640
641
642
643
644
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicChromDescription', 0),
                     'NC_000009.11:g.32928508_32996016del')
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
Vermaat's avatar
Vermaat committed
645
                     ud + ':g.10624_78132del')
Vermaat's avatar
Vermaat committed
646
647
648
649
650

    def test_ud_forward_range(self):
        """
        Variant on UD from forward strand should have forward range positions.
        """
Vermaat's avatar
Vermaat committed
651
652
        ud = self._slice_gene('MARK1')
        check_variant(ud + '(MARK1_v001):c.400_415del', self.output)
Vermaat's avatar
Vermaat committed
653
654
655
656
657
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicChromDescription', 0),
                     'NC_000001.10:g.220773181_220773196del')
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
Vermaat's avatar
Vermaat committed
658
                     ud + ':g.76614_76629del')
Vermaat's avatar
Vermaat committed
659
660
661
662
663
664
665

    def test_ud_reverse_del_length(self):
        """
        Variant on UD from reverse strand should have reversed range
        positions, but not reverse complement of first argument (it is not a
        sequence, but a length).
        """
Vermaat's avatar
Vermaat committed
666
667
        ud = self._slice('NC_000009.11', 32922603, 33006639, 2)
        check_variant(ud + ':g.10624_78132del67509', self.output)
Vermaat's avatar
Vermaat committed
668
669
670
671
672
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicChromDescription', 0),
                     'NC_000009.11:g.32928508_32996016del')
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
Vermaat's avatar
Vermaat committed
673
                     ud + ':g.10624_78132del')
Vermaat's avatar
Vermaat committed
674
675
676
677
678
679
680
681
682
683
684
685

    def test_ud_reverse_roll(self):
        """
        Variant on UD from reverse strand should roll the oposite direction.

        The situation is as follows:

                      G    A    A    A    T    T
                c.   102  103  104  105  106  107
                g.   748  749  750  751  752  753
            chr g.   868  867  866  865  864  863
        """
Vermaat's avatar
Vermaat committed
686
687
        ud = self._slice_gene('DPYD')
        check_variant(ud + '(DPYD_v001):c.104del', self.output)
Vermaat's avatar
Vermaat committed
688
689
690
691
692
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicChromDescription', 0),
                     'NC_000001.10:g.98348867del')
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
Vermaat's avatar
Vermaat committed
693
694
                     ud + ':g.42751del')
        assert ud + '(DPYD_v001):c.105del' \
Vermaat's avatar
Vermaat committed
695
696
697
698
699
700
701
702
703
704
705
706
707
               in self.output.getOutput('descriptions')

    def test_ud_forward_roll(self):
        """
        Variant on UD from forward strand should roll the same.

        The situation is as follows:

                      A    T    T    T    A
                c.   398  399  400  401  402
                g.   612  613  614  615  616
            chr g.   179  180  181  182  183
        """
Vermaat's avatar
Vermaat committed
708
709
        ud = self._slice_gene('MARK1')
        check_variant(ud + '(MARK1_v001):c.400del', self.output)
Vermaat's avatar
Vermaat committed
710
711
712
713
714
        error_count, _, _ = self.output.Summary()
        assert_equal(error_count, 0)
        assert_equal(self.output.getIndexedOutput('genomicChromDescription', 0),
                     'NC_000001.10:g.220773182del')
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
Vermaat's avatar
Vermaat committed
715
716
                     ud + ':g.76615del')
        assert ud + '(MARK1_v001):c.401del' \
Vermaat's avatar
Vermaat committed
717
718
               in self.output.getOutput('descriptions')

719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
    def test_deletion_with_sequence_forward_genomic(self):
        """
        Specify the deleted sequence in a deletion.
        """
        check_variant('AL449423.14:g.65471_65472delTC', self.output)
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'AL449423.14:g.65471_65472del')
        assert 'AL449423.14(CDKN2A_v001):c.98_99del' \
               in self.output.getOutput('descriptions')

    def test_deletion_with_length_forward_genomic(self):
        """
        Specify the deleted sequence length in a deletion.
        """
        check_variant('AL449423.14:g.65471_65472del2', self.output)
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'AL449423.14:g.65471_65472del')
        assert 'AL449423.14(CDKN2A_v001):c.98_99del' \
               in self.output.getOutput('descriptions')

    def test_deletion_with_sequence_reverse_coding(self):
        """
        Specify the deleted sequence in a deletion on the reverse strand.
        """
        check_variant('AL449423.14(CDKN2A_v001):c.161_163delTGG', self.output)
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'AL449423.14:g.61937_61939del')
        assert 'AL449423.14(CDKN2A_v001):c.161_163del' \
               in self.output.getOutput('descriptions')

    def test_deletion_with_length_reverse_coding(self):
        """
        Specify the deleted sequence length in a deletion on the reverse strand.
        """
        check_variant('AL449423.14(CDKN2A_v001):c.161_163del3', self.output)
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'AL449423.14:g.61937_61939del')
        assert 'AL449423.14(CDKN2A_v001):c.161_163del' \
               in self.output.getOutput('descriptions')

    def test_deletion_with_sequence_reverse_ng_coding(self):
        """
        Specify the deleted sequence in a deletion on the reverse strand
        using a genomic reference.
        """
        check_variant('NG_008939.1:c.155_157delAAC', self.output)
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'NG_008939.1:g.5206_5208del')
        assert 'NG_008939.1(PCCB_v001):c.155_157del' \
               in self.output.getOutput('descriptions')

    def test_deletion_with_length_reverse_ng_coding(self):
        """
        Specify the deleted sequence length in a deletion on the reverse strand
        using a genomic reference.
        """
        check_variant('NG_008939.1:c.155_157del3', self.output)
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'NG_008939.1:g.5206_5208del')
        assert 'NG_008939.1(PCCB_v001):c.155_157del' \
               in self.output.getOutput('descriptions')
780
781
782
783
784
785
786
787
788
789

    def test_inversion(self):
        """
        Inversion variant.
        """
        check_variant('AB026906.1:c.274_275inv', self.output)
        assert_equal(self.output.getIndexedOutput('genomicDescription', 0),
                     'AB026906.1:g.7872_7873inv')
        assert 'AB026906.1(SDHD_v001):c.274_275inv' \
            in self.output.getOutput('descriptions')
Vermaat's avatar
Vermaat committed
790
791
792
793
794
795
796

    def test_delins_with_length(self):
        """
        Delins with explicit length of deleted sequence (bug #108).
        """
        check_variant('NM_000193.2:c.108_109del2insG', self.output)
        assert 'NM_000193.2(SHH_i001):p.(Lys38Serfs*2)' in self.output.getOutput('protDescriptions')
797
798
799
800
801
802
803
804
805
806
807
808
809
810

    def test_protein_level_description(self):
        """
        Currently protein level descriptions are not implemented.
        """
        check_variant('NG_009105.1(OPN1LW):p.=', self.output)
        assert_equal(len(self.output.getMessagesWithErrorCode('ENOTIMPLEMENTED')), 1)

    def test_protein_reference(self):
        """
        Currently protein references are not implemented.
        """
        check_variant('NP_064445.1:p.=', self.output)
        assert_equal(len(self.output.getMessagesWithErrorCode('ENOTIMPLEMENTED')), 1)
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831

    def test_wnomrna_other(self):
        """
        Warning for no mRNA field on other than currently selected transcript
        should give WNOMRNA_OTHER warning.
        """
        ud = self._slice_gene('A1BG') # Contains ZNF497 (v1 and v2) with no mRNA
        check_variant(ud + '(A1BG_v001):c.13del', self.output)
        wnomrna_other = self.output.getMessagesWithErrorCode('WNOMRNA_OTHER')
        assert len(wnomrna_other) == 2

    def test_wnomrna(self):
        """
        Warning for no mRNA field on currently selected transcript should give
        WNOMRNA warning.
        """
        ud = self._slice_gene('A1BG') # Contains ZNF497 (v1 and v2) with no mRNA
        check_variant(ud + '(ZNF497_v001):c.13del', self.output)
        wnomrna = self.output.getMessagesWithErrorCode('WNOMRNA')
        wnomrna_other = self.output.getMessagesWithErrorCode('WNOMRNA_OTHER')
        assert len(wnomrna) == len(wnomrna_other) == 1