-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalAlignment.m
77 lines (68 loc) · 1.59 KB
/
LocalAlignment.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
% Global Alignmnet
% Fixed scores
clc;
close all;
clear;
T="CTGATGAT";
S="AGCTGC";
gap=-2;
mismatch=-1;
match=1;
T = convertStringsToChars(T);
S = convertStringsToChars(S);
m = length(T);
n = length(S);
M = zeros(n+1,m+1);
M(1,:)=0*(0:m);
M(:,1)=0*(0:n);
p=max(m,n)-1;
B=zeros(p,2);
B(1,:)=[1,1];
fprintf('(%d) ',M(1,:));
fprintf('\n')
for i=2:n+1
s='';
fprintf('(%d)',M(i,1));
for j=2:m+1
up=M(i-1,j)+gap;
left=M(i,j-1)+gap;
if T(j-1)==S(i-1)
diags=M(i-1,j-1)+match;
else
diags=M(i-1,j-1)+mismatch;
end
comp=[up,left,diags,0];
M(i,j)=max(comp);
max_m=M(i,j);
if max_m==up && max_m==left
fprintf(' <|(%d) ',M(i,j));
elseif max_m==up && max_m==diags
fprintf(' \\|(%d) ',M(i,j));
elseif max_m==diags && max_m==left
fprintf(' <\\(%d) ',M(i,j));
elseif max_m==up
i_max=i-1;
j_max=j;
fprintf(' | (%d) ',M(i,j));
s(j-1)='|';
elseif max_m==left
i_max=i;
j_max=j-1;
fprintf(' < (%d) ',M(i,j));
s(j-1)=' ';
elseif max_m==diags
i_max=i-1;
j_max=j-1;
fprintf(' \\ (%d) ',M(i,j));
s(j-1)='.';
else
fprintf(' (%d) ',M(i,j));
end
end
fprintf('\n');
end
disp("M=")
disp(M);
[~, ALIGNMENT, ~] = nwalign(T,S);
disp("Alignment:")
disp(ALIGNMENT);