-
Notifications
You must be signed in to change notification settings - Fork 61
/
test_Annotation.py
353 lines (282 loc) · 15.1 KB
/
test_Annotation.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/usr/bin/python
import pytest
import os
import logging
from AnnotatorCore import pull_hgvsg_info, DESCRIPTION_HEADERS, ONCOKB_ANNOTATION_HEADERS_GC
from AnnotatorCore import pull_genomic_change_info
from AnnotatorCore import pull_protein_change_info
from AnnotatorCore import pull_structural_variant_info
from AnnotatorCore import pull_cna_info
from AnnotatorCore import setoncokbapitoken
from AnnotatorCore import ProteinChangeQuery
from AnnotatorCore import GenomicChangeQuery
from AnnotatorCore import StructuralVariantQuery
from AnnotatorCore import CNAQuery
from AnnotatorCore import HGVSgQuery
from AnnotatorCore import ReferenceGenome
ONCOKB_API_TOKEN = os.environ["ONCOKB_API_TOKEN"]
setoncokbapitoken(ONCOKB_API_TOKEN)
log = logging.getLogger('test_Annotation')
log.info('test-----------', os.environ["ONCOKB_API_TOKEN"], '------')
VARIANT_EXISTS_INDEX = 2
MUTATION_EFFECT_INDEX = VARIANT_EXISTS_INDEX + 1
ONCOGENIC_INDEX = MUTATION_EFFECT_INDEX + 2
LEVEL_1_INDEX = ONCOGENIC_INDEX + 1
LEVEL_2_INDEX = LEVEL_1_INDEX + 1
LEVEL_3A_INDEX = LEVEL_1_INDEX + 2
HIGHEST_LEVEL_INDEX = LEVEL_1_INDEX + 7
HIGHEST_DX_LEVEL_INDEX = HIGHEST_LEVEL_INDEX + 7
HIGHEST_PX_LEVEL_INDEX = HIGHEST_DX_LEVEL_INDEX + 5
UNKNOWN = 'Unknown'
NUMBER_OF_ANNOTATION_COLUMNS = 27
NUMBER_OF_DESCRIPTION_COLUMNS = len(DESCRIPTION_HEADERS)
NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS = len(ONCOKB_ANNOTATION_HEADERS_GC)
NUMBER_OF_ANNOTATION_COLUMNS_WITH_DESCRIPTIONS = NUMBER_OF_ANNOTATION_COLUMNS + NUMBER_OF_DESCRIPTION_COLUMNS
NUMBER_OF_GC_ANNOTATION_COLUMNS = NUMBER_OF_ANNOTATION_COLUMNS + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS
NUMBER_OF_GC_ANNOTATION_COLUMNS_WITH_DESCRIPTIONS = NUMBER_OF_GC_ANNOTATION_COLUMNS + NUMBER_OF_DESCRIPTION_COLUMNS
def fake_gene_one_query_suite(annotations, include_descriptions):
assert len(annotations) == 1
annotation = annotations[0]
assert len(
annotation) == NUMBER_OF_ANNOTATION_COLUMNS if include_descriptions is False else NUMBER_OF_ANNOTATION_COLUMNS_WITH_DESCRIPTIONS
assert annotation[MUTATION_EFFECT_INDEX] == UNKNOWN
assert annotation[ONCOGENIC_INDEX] == UNKNOWN
assert annotation[HIGHEST_LEVEL_INDEX] == ''
@pytest.mark.skipif(ONCOKB_API_TOKEN in (None, ''), reason="oncokb api token required")
def test_check_protein_change():
queries = [
ProteinChangeQuery('BRAF', 'V600E', 'Colorectal Cancer'),
ProteinChangeQuery('ABL1', 'BCR-ABL1 Fusion', 'Acute Leukemias of Ambiguous Lineage'),
]
annotations = pull_protein_change_info(queries, False, False)
assert len(annotations) == 2
annotation = annotations[0]
assert len(annotation) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX] == 'Gain-of-function'
assert annotation[ONCOGENIC_INDEX] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX] == 'LEVEL_1'
annotation = annotations[1]
assert len(annotation) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX] == 'Gain-of-function'
assert annotation[ONCOGENIC_INDEX] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX] == ''
assert annotation[HIGHEST_DX_LEVEL_INDEX] == 'LEVEL_Dx1'
assert annotation[HIGHEST_PX_LEVEL_INDEX] == 'LEVEL_Px1'
@pytest.mark.skipif(ONCOKB_API_TOKEN in (None, ''), reason="oncokb api token required")
def test_reference_genome():
queries = [
GenomicChangeQuery('7', '140453136', '140453136', 'A', 'T', 'LUAD', ReferenceGenome.GRCH37),
GenomicChangeQuery('7', '140753336', '140753336', 'A', 'T', 'LUAD', ReferenceGenome.GRCH38)
]
annotations = pull_genomic_change_info(queries, False, False)
assert len(annotations) == 2
annotation37 = annotations[0]
annotation38 = annotations[1]
assert annotation37 == annotation38
queries = [
ProteinChangeQuery('MYD88', 'M232T', 'Ovarian Cancer', ReferenceGenome.GRCH37),
ProteinChangeQuery('MYD88', 'M219T', 'Ovarian Cancer', ReferenceGenome.GRCH38)
]
annotations = pull_protein_change_info(queries, False, False)
assert len(annotations) == 2
annotation37 = annotations[0]
annotation38 = annotations[1]
assert annotation37 == annotation38
@pytest.mark.skipif(ONCOKB_API_TOKEN in (None, ''), reason="oncokb api token required")
def test_fake_gene_protein_change():
queries = [
ProteinChangeQuery('test1', 'V600E', 'Ovarian Cancer')
]
annotations = pull_protein_change_info(queries, False, False)
fake_gene_one_query_suite(annotations, False)
annotations = pull_protein_change_info(queries, False, False)
fake_gene_one_query_suite(annotations, True)
@pytest.mark.skipif(ONCOKB_API_TOKEN in (None, ''), reason="oncokb api token required")
def test_check_atypical_alts():
queries = [
ProteinChangeQuery('Other Biomarkers', 'MSI-H', 'Colorectal Cancer'),
ProteinChangeQuery('Other Biomarkers', 'MSI-H', 'Leukemia'),
ProteinChangeQuery('TERT', 'Promoter Mutation', 'Bladder Cancer'),
ProteinChangeQuery('TERT', 'Promoter Mutation', 'Bladder Cancer', None, '5\'Flank')
]
annotations = pull_protein_change_info(queries, False, False)
assert len(annotations) == 4
annotation = annotations[0]
assert len(annotation) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX] == UNKNOWN
assert annotation[ONCOGENIC_INDEX] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX] == 'LEVEL_1'
annotation = annotations[1]
assert len(annotation) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX] == UNKNOWN
assert annotation[ONCOGENIC_INDEX] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX] == ''
annotation = annotations[2]
assert len(annotation) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX] == 'Likely Gain-of-function'
assert annotation[ONCOGENIC_INDEX] == 'Likely Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX] == ''
annotation_dup = annotations[3]
assert len(annotation_dup) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation == annotation_dup
@pytest.mark.skipif(ONCOKB_API_TOKEN in (None, ''), reason="oncokb api token required")
def test_check_hgvsg():
queries = [
# KRAF G12C
HGVSgQuery('12:g.25398285C>A', 'LUAD'),
# KRAF G12C
HGVSgQuery('12:g.25398285_25398286delinsAG', 'LUAD'),
# TERT Promoter
HGVSgQuery('5:g.1295167_1295168delinsAATG', 'LUAD'),
]
annotations = pull_hgvsg_info(queries, False, False)
assert len(annotations) == 3
annotation = annotations[0]
assert len(annotation) == NUMBER_OF_GC_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'Gain-of-function'
assert annotation[ONCOGENIC_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'LEVEL_1'
annotation = annotations[1]
assert len(annotation) == NUMBER_OF_GC_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'Gain-of-function'
assert annotation[ONCOGENIC_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'LEVEL_1'
annotation = annotations[2]
assert len(annotation) == NUMBER_OF_GC_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'Likely Gain-of-function'
assert annotation[ONCOGENIC_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'Likely Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == ''
@pytest.mark.skipif(ONCOKB_API_TOKEN in (None, ''), reason="oncokb api token required")
def test_check_genomic_change():
queries = [
# KRAF G12C
GenomicChangeQuery('12', '25398285', '25398285', 'C', 'A', 'LUAD'),
# KRAF G12C
GenomicChangeQuery('12', '25398285', '25398286', 'CA', 'AG', 'LUAD'),
# TERT Promoter
GenomicChangeQuery('5', '1295167', '1295168', 'TC', 'AATG', 'LUAD'),
]
annotations = pull_genomic_change_info(queries, False, False)
assert len(annotations) == 3
annotation = annotations[0]
assert len(annotation) == NUMBER_OF_GC_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'Gain-of-function'
assert annotation[ONCOGENIC_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'LEVEL_1'
annotation = annotations[1]
assert len(annotation) == NUMBER_OF_GC_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'Gain-of-function'
assert annotation[ONCOGENIC_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'LEVEL_1'
annotation = annotations[2]
assert len(annotation) == NUMBER_OF_GC_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'Likely Gain-of-function'
assert annotation[ONCOGENIC_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == 'Likely Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX + NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS] == ''
@pytest.mark.skipif(ONCOKB_API_TOKEN in (None, ''), reason="oncokb api token required")
def test_check_structural_variants():
queries = [
StructuralVariantQuery('ALK', 'EML4', 'FUSION', 'NSCLC'),
StructuralVariantQuery('ALK', 'EML4', 'FUSION', 'Melanoma'),
StructuralVariantQuery('BCR', 'ABL1', 'FUSION', 'Acute Leukemias of Ambiguous Lineage'),
]
annotations = pull_structural_variant_info(queries, False)
assert len(annotations) == 3
annotation = annotations[0]
assert len(annotation) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX] == 'Gain-of-function'
assert annotation[ONCOGENIC_INDEX] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX] == 'LEVEL_1'
annotation = annotations[1]
assert len(annotation) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX] == 'Gain-of-function'
assert annotation[ONCOGENIC_INDEX] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX] == 'LEVEL_3B'
annotation = annotations[2]
assert len(annotation) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX] == 'Gain-of-function'
assert annotation[ONCOGENIC_INDEX] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX] == ''
assert annotation[HIGHEST_DX_LEVEL_INDEX] == 'LEVEL_Dx1'
assert annotation[HIGHEST_PX_LEVEL_INDEX] == 'LEVEL_Px1'
@pytest.mark.skipif(ONCOKB_API_TOKEN in (None, ''), reason="oncokb api token required")
def test_fake_fusion_gene():
queries = [
StructuralVariantQuery('test1', 'test2', 'FUSION', 'NSCLC'),
]
annotations = pull_structural_variant_info(queries, False)
fake_gene_one_query_suite(annotations, False)
annotations = pull_structural_variant_info(queries, False)
fake_gene_one_query_suite(annotations, True)
@pytest.mark.skipif(ONCOKB_API_TOKEN in (None, ''), reason="oncokb api token required")
def test_cna():
queries = [
CNAQuery('BRCA2', 'DELETION', 'Ovarian Cancer'),
CNAQuery('ERBB2', 'Amplification', 'Breast Cancer'),
CNAQuery('ERBB2', 'Amplification', 'Colorectal Cancer'),
CNAQuery('CDKN2A', 'Deletion', 'AML with BCR-ABL1'),
]
annotations = pull_cna_info(queries, False)
assert len(annotations) == 4
annotation = annotations[0]
assert len(annotation) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX] == 'Loss-of-function'
assert annotation[ONCOGENIC_INDEX] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX] == 'LEVEL_1'
annotation = annotations[1]
assert len(annotation) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX] == 'Gain-of-function'
assert annotation[ONCOGENIC_INDEX] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX] == 'LEVEL_1'
annotation = annotations[2]
assert len(annotation) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX] == 'Gain-of-function'
assert annotation[ONCOGENIC_INDEX] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX] == 'LEVEL_1'
annotation = annotations[3]
assert len(annotation) == NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[MUTATION_EFFECT_INDEX] == 'Loss-of-function'
assert annotation[ONCOGENIC_INDEX] == 'Oncogenic'
assert annotation[HIGHEST_LEVEL_INDEX] == ''
assert annotation[HIGHEST_DX_LEVEL_INDEX] == 'LEVEL_Dx2'
assert annotation[HIGHEST_PX_LEVEL_INDEX] == ''
@pytest.mark.skipif(ONCOKB_API_TOKEN in (None, ''), reason="oncokb api token required")
def test_fake_cna():
queries = [
CNAQuery('test1', 'Amplification', 'Breast Cancer'),
]
annotations = pull_cna_info(queries, False)
fake_gene_one_query_suite(annotations, False)
annotations = pull_cna_info(queries, True)
fake_gene_one_query_suite(annotations, True)
def check_brca2_s1882_without_cancertype(annotation, genomic_query=False):
assert len(annotation) == NUMBER_OF_GC_ANNOTATION_COLUMNS if genomic_query else NUMBER_OF_ANNOTATION_COLUMNS
assert annotation[(
NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS + MUTATION_EFFECT_INDEX) if genomic_query else MUTATION_EFFECT_INDEX] == 'Likely Loss-of-function'
assert annotation[(
NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS + ONCOGENIC_INDEX) if genomic_query else ONCOGENIC_INDEX] == 'Likely Oncogenic'
assert annotation[(
NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS + HIGHEST_LEVEL_INDEX) if genomic_query else HIGHEST_LEVEL_INDEX] == 'LEVEL_1'
assert annotation[(
NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS + LEVEL_1_INDEX) if genomic_query else LEVEL_1_INDEX] == 'Olaparib,Olaparib+Bevacizumab,Rucaparib,Olaparib+Abiraterone+Prednisone,Niraparib,Olaparib+Abiraterone+Prednisolone,Talazoparib+Enzalutamide,Niraparib+Abiraterone Acetate+Prednisone'
assert annotation[(
NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS + LEVEL_2_INDEX) if genomic_query else LEVEL_2_INDEX] == 'Olaparib,Rucaparib,Niraparib'
assert annotation[(
NUMBER_OF_ONCOKB_ANNOTATION_GC_COLUMNS + LEVEL_3A_INDEX) if genomic_query else LEVEL_3A_INDEX] == 'Olaparib,Talazoparib'
@pytest.mark.skipif(ONCOKB_API_TOKEN in (None, ''), reason="oncokb api token required")
def test_duplicated_treatments():
# there should not be any duplicated treatment listed when cancer type is not specified
# test protein change query
queries = [
ProteinChangeQuery('BRCA2', 'S1882*', ''),
]
annotations = pull_protein_change_info(queries, False, False)
assert len(annotations) == 1
check_brca2_s1882_without_cancertype(annotations[0])
# test genomic change query
queries = [
GenomicChangeQuery('13', '32914137', '32914137', 'C', 'A', ''),
]
annotations = pull_genomic_change_info(queries, False, False)
assert len(annotations) == 1
check_brca2_s1882_without_cancertype(annotations[0], True)