-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestSwSequenceAlignment.m
190 lines (177 loc) · 5.45 KB
/
TestSwSequenceAlignment.m
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
%% Test cases for swSequenceAlignment
% Bernard Llanos
% Spring 2016 research assistantship supervised by Dr. Y.H. Yang
% University of Alberta, Department of Computing Science
% File created August 4, 2016
%% Local sequence alignment
% Example from https://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm
% A = 1, C = 2, G = 3, T = 4
subject = [1 3 2 1 2 1 2 1];
query = [1 2 1 2 1 2 4 1];
f_similarity = @(x, y) (x == y) * 2 + (x ~= y) * -1;
threshold = 0;
f_subject_gap = @(x) -1;
f_query_gap = @(x) -1;
[ alignment, score ] = swSequenceAlignment( subject, query, f_similarity, threshold, f_subject_gap, f_query_gap, 'Local' );
alignment_expected = [
1 1;
2 0;
3 2;
4 3;
5 4;
6 5;
7 6;
0 7;
8 8
];
score_expected = 12;
if all(all(alignment_expected == alignment))
disp('Local alignment 1 is correct.')
else
disp('Incorrect local alignment 1.')
end
if score_expected == score
disp('Local alignment 1 score is correct.')
else
disp('Incorrect local alignment 1 score.')
end
%% Global sequence alignment
% Example from http://pages.cs.wisc.edu/~bsettles/ibs08/lectures/02-alignment.pdf
% (Page 27)
% A = 1, C = 2, G = 3, T = 4
subject = [1 1 1 2];
query = [1 3 2];
f_similarity = @(x, y) (x == y) * 1 + (x ~= y) * -1;
threshold = -Inf;
f_subject_gap = @(x) -2 * x;
f_query_gap = @(x) -2 * x;
[ alignment, score ] = swSequenceAlignment( subject, query, f_similarity, threshold, f_subject_gap, f_query_gap, 'Global' );
alignment_expected = [
2 1;
3 2;
4 3
];
score_expected = -1;
if all(all(alignment_expected == alignment))
disp('Global alignment 1 is correct.')
else
disp('Incorrect global alignment 1.')
end
if score_expected == score
disp('Global alignment 1 score is correct.')
else
disp('Incorrect global alignment 1 score.')
end
%% Semi-global sequence alignment
% Example from http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-096-algorithms-for-computational-biology-spring-2005/lecture-notes/lecture5_newest.pdf
% (Page 24)
% A = 1, C = 2, G = 3, T = 4
subject = [1 1 3 2];
query = [1 3 4];
f_similarity = @(x, y) (x == y) * 1 + (x ~= y) * -1;
threshold = -Inf;
f_subject_gap = @(x) -2 * x;
f_query_gap = @(x) -2 * x;
[ alignment, score ] = swSequenceAlignment( subject, query, f_similarity, threshold, f_subject_gap, f_query_gap, 'SemiGlobal' );
alignment_expected = [
2 1;
3 2;
4 3
];
score_expected = 1;
if all(all(alignment_expected == alignment))
disp('Semi-global alignment 1 is correct.')
else
disp('Incorrect semi-global alignment 1.')
end
if score_expected == score
disp('Semi-global alignment 1 score is correct.')
else
disp('Incorrect semi-global alignment 1 score.')
end
%% Semi-global sequence alignment 2
% Example from http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-096-algorithms-for-computational-biology-spring-2005/lecture-notes/lecture5_newest.pdf
% (Page 22)
% A = 1, C = 2, G = 3, T = 4
subject = [2 1 3 2 1 2 4 4 3 3 1 4 4 2 4 2 3 3];
query = [2 1 3 2 3 4 3 3];
f_similarity = @(x, y) (x == y) * 1 + (x ~= y) * -1;
threshold = -Inf;
f_subject_gap = @(x) -2 * x;
f_query_gap = @(x) -2 * x;
[ alignment, score ] = swSequenceAlignment( subject, query, f_similarity, threshold, f_subject_gap, f_query_gap, 'SemiGlobal' );
alignment_expected = [
4 1;
5 2;
0 3;
6 4;
7 5;
8 6;
9 7;
10 8
];
score_expected = 3;
if all(all(alignment_expected == alignment))
disp('Semi-global alignment 2 is correct.')
else
disp('Incorrect semi-global alignment 2.')
end
if score_expected == score
disp('Semi-global alignment 2 score is correct.')
else
disp('Incorrect semi-global alignment 2 score.')
end
%% Local sequence alignment 2
% Example from http://pages.cs.wisc.edu/~bsettles/ibs08/lectures/02-alignment.pdf
% (Page 35)
% A = 1, C = 2, G = 3, T = 4
subject = [4 4 1 1 3];
query = [1 1 3 1];
f_similarity = @(x, y) (x == y) * 1 + (x ~= y) * -1;
threshold = 0;
f_subject_gap = @(x) -2 * x;
f_query_gap = @(x) -2 * x;
[ alignment, score ] = swSequenceAlignment( subject, query, f_similarity, threshold, f_subject_gap, f_query_gap, 'Local' );
alignment_expected = [
3 1;
4 2;
5 3
];
score_expected = 3;
if all(all(alignment_expected == alignment))
disp('Local alignment 2 is correct.')
else
disp('Incorrect local alignment 2.')
end
if score_expected == score
disp('Local alignment 2 score is correct.')
else
disp('Incorrect local alignment 2 score.')
end
%% Global sequence alignment with affine gap function
% Example from http://pages.cs.wisc.edu/~bsettles/ibs08/lectures/02-alignment.pdf
% (Page 41)
% A = 1, C = 2, G = 3, T = 4
subject = [1 1 4];
query = [1 2 1 2 4];
f_similarity = @(x, y) (x == y) * 1 + (x ~= y) * -1;
threshold = -Inf;
f_subject_gap = @(x) -3 - x;
f_query_gap = @(x) -3 - x;
[ alignment, score ] = swSequenceAlignment( subject, query, f_similarity, threshold, f_subject_gap, f_query_gap, 'Global' );
alignment_expected = [
1 3;
2 4;
3 5
];
score_expected = -4;
if all(all(alignment_expected == alignment))
disp('Global affine gap penalty alignment 1 is correct.')
else
disp('Incorrect global affine gap penalty alignment 1.')
end
if score_expected == score
disp('Global affine gap penalty alignment 1 score is correct.')
else
disp('Incorrect global affine gap penalty alignment 1 score.')
end