-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_protein_modification_fix.py
97 lines (76 loc) · 4.26 KB
/
test_protein_modification_fix.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
from common_autofix_functions import format_auto_fix
import unittest
from protein_modification_qc import check_func
class ProteinModificationFormattingTest(unittest.TestCase):
def test_correct_syntax_error(self):
genome = {
'dummy': {'CDS': 'dummy', 'peptide': 'MSAS'}
}
example_dict = {
'systematic_id': 'dummy',
'sequence_position': 'S4',
'modification': 'blah'
}
allowed_mod_dict = {'blah': '', 'serines_only': 'S', 'serines_or_alanines': 'SA'}
self.assertEqual(check_func(example_dict, genome, allowed_mod_dict), ('', ''))
example_dict['sequence_position'] = 'S3'
self.assertEqual(check_func(example_dict, genome, allowed_mod_dict), ('S3', ''))
example_dict['sequence_position'] = 'blah3'
self.assertEqual(check_func(example_dict, genome, allowed_mod_dict), ('pattern_error', ''))
example_dict['sequence_position'] = 'A3S4'
self.assertEqual(check_func(example_dict, genome, allowed_mod_dict), ('pattern_error', ''))
example_dict['sequence_position'] = 'A3,S4'
self.assertEqual(check_func(example_dict, genome, allowed_mod_dict), ('', ''))
# Repetitions are kept (expected behaviour)
example_dict['sequence_position'] = 'A3,S4,S4'
self.assertEqual(check_func(example_dict, genome, allowed_mod_dict), ('', ''))
# Only wrong syntax errors are reported, '|' separated
example_dict['sequence_position'] = 'A3,S4,T4,T1000'
self.assertEqual(check_func(example_dict, genome, allowed_mod_dict), ('||T4|T1000', ''))
example_dict['sequence_position'] = 'A3;S4'
self.assertEqual(check_func(example_dict, genome, allowed_mod_dict), ('', 'A3,S4'))
# No sorting, but repetitions are kept even when correcting syntax error
example_dict['sequence_position'] = 'S4 A3 S4;S4;T100'
self.assertEqual(check_func(example_dict, genome, allowed_mod_dict), ('||||T100', 'S4,A3,S4,S4,T100'))
# Test allowed modifications
example_dict['sequence_position'] = 'A3;S4'
example_dict['modification'] = 'serines_only'
self.assertEqual(check_func(example_dict, genome, allowed_mod_dict), ('residue_not_allowed', 'A3,S4'))
example_dict['modification'] = 'serines_or_alanines'
self.assertEqual(check_func(example_dict, genome, allowed_mod_dict), ('', 'A3,S4'))
def test_format_auto_fix(self):
# Simplest case
example_dict = {
'sequence_position': 'S409',
'sequence_error': 'S409',
'change_sequence_position_to': '',
'auto_fix_from': 'S409',
'auto_fix_to': 'S400',
'auto_fix_comment': 'blah'
}
fixes, comment = format_auto_fix(example_dict, 'sequence_position', 'change_sequence_position_to')
self.assertEqual(fixes, 'S400')
self.assertEqual(comment, 'blah')
# There was an error sometime in which I was using string.replace
# This gave an error as it would pick S4 from S409 and give S109
# (replacing the substring S4 by S1)
example_dict['auto_fix_from'] = 'S4,S409'
example_dict['auto_fix_to'] = 'S1,S400'
fixes, comment = format_auto_fix(example_dict, 'sequence_position', 'change_sequence_position_to')
self.assertEqual(fixes, 'S400')
self.assertEqual(comment, 'blah')
# Case where both old solutions make no difference
example_dict['auto_fix_to'] = 'S1,S400|S3,S400'
example_dict['auto_fix_comment'] = 'blah|bluh'
fixes, comment = format_auto_fix(example_dict, 'sequence_position', 'change_sequence_position_to')
self.assertEqual(fixes, 'S400')
self.assertEqual(comment, 'blah/bluh')
# Case where both solutions make a difference
example_dict['auto_fix_to'] = 'S1,S401|S3,S400'
fixes, comment = format_auto_fix(example_dict, 'sequence_position', 'change_sequence_position_to')
self.assertEqual(fixes, 'S401|S400')
self.assertEqual(comment, 'blah|bluh')
# Autofix works with random strings as well
example_dict['auto_fix_to'] = 'S1,??'
fixes, comment = format_auto_fix(example_dict, 'sequence_position', 'change_sequence_position_to')
self.assertEqual(fixes, '??')