% get a list of PPs and string of the SP (SP must appear only once in each PP)
% aline and compare all PP pairs.
% create a Matrix of with values of the number of differenent lettes.
function [M S] = count_mutation(PP, SP)
Npp = length(PP); % number of PPs
Nsp = length(SP); % the length of the SP
% get SP locations & their distances, see below
for i = 1:Npp
loc(i) = strfind(PP{i},SP);
% distance from begining (Left)
L(i) = loc(i) - 1;
% distance from end (Right)
R(i) = length(PP{i}) - loc(i) - Nsp + 1;
end
% go over any 2 pairs of the PPs (in which u have found that SP)
count = 0;
M = zeros(Npp,Npp); % diffrences count matrix
S = zeros(Npp,Npp); % AA length compared
for i = 1:Npp
for j = i+1:Npp
% get the locations to compare
Lind = min([ L(i) L(j) ]);
Rind = min([ R(i) R(j) ]);
% compare all letters to the left of the SP (that was found in each pair)
if Lind > 0
Xi = PP{i}(loc(i)-Lind : L(i));
Xj = PP{j}(loc(j)-Lind : L(j));
Lpp = length(Xi);
for k = 1:Lpp
if ~strcmp(Xi(k),Xj(k))
count = count + 1;
end
end
end
% compare all letters at the right of the SP
if Rind > 0
Yi = PP{i}(loc(i)+Nsp : loc(i)+Nsp+Rind-1);
Yj = PP{j}(loc(j)+Nsp : loc(j)+Nsp+Rind-1);
Rpp = length(Yi);
for k = 1:Rpp
if ~strcmp(Yi(k),Yj(k))
count = count + 1;
end
end
end
S(i,j) = Rpp + Lpp;
M(i,j) = count;
count = 0;
end
end