-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathtest_hgvs_variantmapper.py
156 lines (126 loc) · 5.55 KB
/
test_hgvs_variantmapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
153
154
155
156
# -*- coding: utf-8 -*-
import os
import unittest
import pytest
from support import CACHE
import hgvs.dataproviders.uta
import hgvs.parser
import hgvs.variantmapper
from hgvs.exceptions import HGVSError, HGVSInvalidVariantError
@pytest.mark.vcr
def test_add_gene_symbol(am38, parser):
ags = am38.add_gene_symbol
var_g = parser.parse("NC_000007.13:g.21940852_21940908del")
am38.add_gene_symbol = True
var_t = am38.g_to_t(var_g, "NM_003777.3")
assert "NM_003777.3(DNAH11):c.13552_*36del" == str(var_t)
am38.add_gene_symbol = False
var_t = am38.g_to_t(var_g, "NM_003777.3")
assert "NM_003777.3:c.13552_*36del" == str(var_t)
am38.add_gene_symbol = ags
@pytest.mark.quick
class Test_VariantMapper_Exceptions(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.hdp = hgvs.dataproviders.uta.connect(
mode=os.environ.get("HGVS_CACHE_MODE", "run"), cache=CACHE
)
cls.vm = hgvs.variantmapper.VariantMapper(cls.hdp)
cls.hp = hgvs.parser.Parser()
def test_map_stop_retained(self):
hgvs_c = "NM_001253909.2:c.416_417insGTG"
var_c = self.hp.parse_hgvs_variant(hgvs_c)
var_p = self.vm.c_to_p(var_c)
assert str(var_p) == "NP_001240838.1:p.(Ter140Ter)"
def test_gcrp_invalid_input_type(self):
hgvs_g = "NC_000007.13:g.36561662C>T"
hgvs_c = "NM_001637.3:c.1582G>A"
var_g = self.hp.parse_hgvs_variant(hgvs_g)
var_c = self.hp.parse_hgvs_variant(hgvs_c)
cases = {
"gc": (self.vm.g_to_c, (var_c, "NM_001637.3")),
"gr": (self.vm.g_to_n, (var_c, "NM_001637.3")),
"gt": (self.vm.g_to_t, (var_c, "NM_001637.3")),
"rg": (self.vm.n_to_g, (var_c, "NM_001637.3")),
"cg": (self.vm.c_to_g, (var_g, "NM_001637.3")),
"tg": (self.vm.t_to_g, (var_g, "NM_001637.3")),
"cr": (self.vm.c_to_n, (var_g,)),
"rc": (self.vm.n_to_c, (var_g,)),
"cp": (self.vm.c_to_p, (var_g, None)),
}
failures = []
for key in cases:
try:
func, args = cases[key]
func(*args)
failures.append(key)
except hgvs.exceptions.HGVSInvalidVariantError:
pass
self.assertFalse(failures, "conversions not failing: {}".format(failures))
def test_gc_invalid_input_nm_accession(self):
hgvs_g = "NC_000007.13:g.36561662C>T"
var_g = self.hp.parse_hgvs_variant(hgvs_g)
with self.assertRaises(hgvs.exceptions.HGVSError):
self.vm.c_to_p(var_g, "NM_999999.1")
def test_undefined_cds(self):
"""Raise exception when requesting mapping to/from c. with non-coding transcript"""
hgvs_n = "NR_111984.1:n.44G>A" # legit
hgvs_c = "NR_111984.1:c.44G>A" # bogus: c. with non-coding tx accession
var_n = self.hp.parse_hgvs_variant(hgvs_n)
var_c = self.hp.parse_hgvs_variant(hgvs_c)
with self.assertRaises(hgvs.exceptions.HGVSUsageError):
var_c = self.vm.n_to_c(var_n) # n_to_c: transcript is non-coding
with self.assertRaises(hgvs.exceptions.HGVSUsageError):
var_c = self.vm.c_to_n(var_c) # c_to_n: var_c is bogus
def test_map_var_of_unsupported_validation(self):
hgvs_c = "NM_003777.3:c.13552_*36del57"
var_c = self.hp.parse_hgvs_variant(hgvs_c)
var_g = self.vm.c_to_g(var_c, "NC_000007.13")
self.assertEqual(str(var_g), "NC_000007.13:g.21940852_21940908del")
def test_map_to_unknown_p_effect(self):
hgvs_c = "NM_020975.4:c.625+9C>T"
var_c = self.hp.parse_hgvs_variant(hgvs_c)
var_p = self.vm.c_to_p(var_c)
self.assertEqual(str(var_p), "NP_066124.1:p.?")
def test_map_of_c_out_of_cds_bound(self):
hgvs_c = "NM_145901.2:c.343T>C"
var_c = self.hp.parse_hgvs_variant(hgvs_c)
with self.assertRaises(HGVSInvalidVariantError):
self.vm.c_to_p(var_c)
def test_map_of_dup_at_cds_end(self):
hgvs_c = "NM_001051.2:c.1257dupG"
var_c = self.hp.parse_hgvs_variant(hgvs_c)
var_p = self.vm.c_to_p(var_c)
self.assertEqual(str(var_p), "NP_001042.1:p.(=)")
def test_map_of_c_out_of_reference_bound(self):
hgvs_c = "NM_000249.3:c.-73960_*46597del"
var_c = self.hp.parse_hgvs_variant(hgvs_c)
with pytest.raises(HGVSError, match="coordinate is out of bounds"):
self.vm.c_to_p(var_c)
def test_map_of_ins_three_prime_utr(self):
hgvs_c = "NM_004985.4:c.567_*1insCCC"
var_c = self.hp.parse_hgvs_variant(hgvs_c)
var_p = self.vm.c_to_p(var_c)
self.assertEqual(str(var_p), "NP_004976.2:p.?")
def test_map_of_dup_three_prime_utr(self):
hgvs_c = "NM_153223.3:c.2959_*1dup"
var_c = self.hp.parse_hgvs_variant(hgvs_c)
var_p = self.vm.c_to_p(var_c)
self.assertEqual(str(var_p), "NP_694955.2:p.?")
if __name__ == "__main__":
unittest.main()
# <LICENSE>
# Copyright 2018 HGVS Contributors (https://github.com/biocommons/hgvs)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# </LICENSE>