-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_annotation.py
More file actions
99 lines (75 loc) · 4.14 KB
/
test_annotation.py
File metadata and controls
99 lines (75 loc) · 4.14 KB
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
import unittest
from os import getcwd
import re
from openvariant.annotation.annotation import Annotation
from openvariant.annotation.config_annotation import DEFAULT_FORMAT
class TestAnnotation(unittest.TestCase):
def test_annotation_creation(self):
annotation = Annotation(f'{getcwd()}/tests/data/annotation/annotation.yaml')
self.assertNotEqual(annotation, None)
def test_annotation_invalid_creation(self):
with self.assertRaises(FileNotFoundError):
Annotation(f'{getcwd()}/tests/data/no_exist.yaml')
def test_annotation_path(self):
res_expect = f'{getcwd()}/tests/data/annotation/annotation.yaml'
annotation = Annotation(f'{getcwd()}/tests/data/annotation/annotation.yaml')
self.assertEqual(annotation.path, res_expect)
def test_annotation_invalid_path(self):
with self.assertRaises(FileNotFoundError):
Annotation(f'{getcwd()}/tests/data/no_exist.yaml')
def test_annotation_patterns(self):
res_expect = {'*.maf', '*.vcf.gz'}
annotation = Annotation(f'{getcwd()}/tests/data/annotation/annotation.yaml')
self.assertEqual(set(annotation.patterns), res_expect)
def test_annotation_invalid_patterns(self):
with self.assertRaises(TypeError):
Annotation(f'{getcwd()}/tests/data/annotation/invalid_pattern.yaml')
def test_annotation_no_exist_patterns(self):
with self.assertRaises(KeyError):
Annotation(f'{getcwd()}/tests/data/annotation/no_exist_pattern.yaml')
def test_annotation_format(self):
annotation = Annotation(f'{getcwd()}/tests/data/annotation/annotation.yaml')
self.assertEqual(annotation.format, 'CSV')
def test_annotation_no_exist_format(self):
annotation = Annotation(f'{getcwd()}/tests/data/annotation/no_exist_format.yaml')
self.assertEqual(annotation.format, DEFAULT_FORMAT)
def test_annotation_invalid_format(self):
with self.assertRaises(KeyError):
Annotation(f'{getcwd()}/tests/data/annotation/invalid_format.yaml')
def test_annotation_delimiter(self):
annotation = Annotation(f'{getcwd()}/tests/data/annotation/annotation.yaml')
print(annotation.delimiter, '\t')
self.assertEqual(annotation.delimiter, '\t')
def test_annotation_columns(self):
res_expect = {'PLATFORM', 'DATASET'}
annotation = Annotation(f'{getcwd()}/tests/data/annotation/annotation.yaml')
self.assertEqual(set(annotation.columns), res_expect)
def test_annotation_no_exist_columns(self):
with self.assertRaises(KeyError):
Annotation(f'{getcwd()}/tests/data/annotation/no_exist_columns.yaml')
def test_annotation_invalid_columns(self):
with self.assertRaises(KeyError):
Annotation(f'{getcwd()}/tests/data/annotation/invalid_columns.yaml')
def test_annotation_annotations(self):
annotation = Annotation(f'{getcwd()}/tests/data/annotation/annotation.yaml')
self.assertNotEqual(annotation.annotations, None)
def test_annotation__no_exist_annotations(self):
with self.assertRaises(KeyError):
Annotation(f'{getcwd()}/tests/data/annotation/no_exist_annotation.yaml')
def test_annotation_excludes(self):
res_expect = {'MUTATION_REF': [1234], 'DATASET': ['ucs']}
annotation = Annotation(f'{getcwd()}/tests/data/annotation/annotation.yaml')
self.assertEqual(annotation.excludes, res_expect)
def test_annotation_no_exist_excludes(self):
with self.assertRaises(KeyError):
Annotation(f'{getcwd()}/tests/data/annotation/no_exist_excludes.yaml')
def test_annotation_invalid_excludes(self):
with self.assertRaises(KeyError):
Annotation(f'{getcwd()}/tests/data/annotation/invalid_excludes.yaml')
def test_annotation_structure(self):
res_expect = {'*.maf', '*.vcf.gz'}
annotation = Annotation(f'{getcwd()}/tests/data/annotation/annotation.yaml')
result_pattern = set(annotation.structure.keys())
result_structure = annotation.structure.values()
self.assertEqual(result_pattern, res_expect)
self.assertNotEqual(result_structure, None)