-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_coordinate_change.py
102 lines (91 loc) · 3.42 KB
/
test_coordinate_change.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
import unittest
from genome_functions import get_other_index_from_alignment
from allele_fixes import multi_shift_fix, old_coords_fix
class SequenceIndexingTest(unittest.TestCase):
def test_coordinate_changes(self):
examples = (
(
"VAQCAAIKVT----AQCVKVTVIFLAAAA",
"VAQC--IKVTVIFLAQCVKVTVIFL"
),
(
"VAQC--IKVTVIFLAQCVKVTVIFL",
"VAQCAAIKVT----AQCVKVTVIFLAAAA"
),
(
"-VAT---",
"AVATCGF"
),
(
"AVATCGF",
"-VAT---"
)
)
for new_alignment, old_alignment in examples:
new_seq = new_alignment.replace('-', '')
old_seq = old_alignment.replace('-', '')
for i in range(len(new_seq)):
old_i = get_other_index_from_alignment(new_alignment, old_alignment, i)
if old_i is None:
continue
self.assertEqual(new_seq[i], old_seq[old_i])
def test_shift_coordinates(self):
seq = 'AVPPAVPPP'
self.assertEqual(multi_shift_fix(seq, ['A3', 'V4']), ['A1,V2', 'A5,V6'])
self.assertEqual(multi_shift_fix(seq, ['A3', 'V4', '8-10']), ['A1,V2,6-8'])
# Test that it finds both extremes
self.assertEqual(multi_shift_fix('AVVVVVVVVA', ['A3']), ['A1', 'A10'])
# Test that it works with one-length string
self.assertEqual(multi_shift_fix('V', ['A3']), [])
self.assertEqual(multi_shift_fix('A', ['A3']), ['A1'])
def test_old_coords_fix(self):
coordinate_changes = [
# Correct
{
'revision': 'dummy_revision',
'new_alignment': 'ACLPTV',
'old_alignment': 'A--PTV',
'old_coord': 'dummy_coord'
},
# Old does not match
{
'revision': 'dummy_revision2',
'new_alignment': 'ACLPTV',
'old_alignment': 'V--PTV',
'old_coord': 'dummy_coord1'
},
# Another correct one (to see that it returns both)
{
'revision': 'dummy_revision3',
'new_alignment': 'ACPTV',
'old_alignment': 'A-PTV',
'old_coord': 'dummy_coord3'
},
# New does not match
{
'revision': 'dummy_revision4',
'new_alignment': 'VCLPTV',
'old_alignment': 'A--PTV',
'old_coord': 'dummy_coord4'
},
# Position does not exist in old
{
'revision': 'dummy_revision5',
'new_alignment': 'VCLPTV',
'old_alignment': 'A-----',
'old_coord': 'dummy_coord5'
},
# Position does not exist in new
{
'revision': 'dummy_revision6',
'new_alignment': '-CLPTV',
'old_alignment': 'A--PTV',
'old_coord': 'dummy_coord6'
},
]
solutions = old_coords_fix(coordinate_changes, ['A1', 'P2'])
self.assertEqual(len(solutions), 4)
self.assertEqual(solutions[0]['values'], 'A1,P4')
self.assertEqual(solutions[1]['values'], 'A1,P3')
self.assertEqual(solutions[2]['values'], '?,P4')
self.assertEqual(solutions[3]['values'], '?,P3')