% SEND:
% - M: the Mutation distance matrix for the PP.
% - dis: the mutation distance vector for which u want to get the new species count vector

% DO:
% - get the pairs for which there's 'dis' mutation relationship (M = dis).
% - eliminate the minimal set of PPs, such that all the remaining PPs have M > dis

% GET:
% - the new species count


function Nspc = get_count_by_mutation_dis(M, dis)

dim = size(M); dim = dim(1); % the number of PPs
V = 1:dim;        % vector of PP index
N = length(dis);  % number of distances to analyze

% go over "dis"
for i = 1:N
    
    % the current distance
    d = dis(i);
    % get the index of the pairs that differ in up to "d" AA from one another
    [x y] = find(M <= d & M > 0);
    % arrange the pairs such that the index on the right is always smaller than the index on the left
    P = [x y];
    P = sortrows(P);
    
    % identify the minimal set to exclude
    p1 = unique(P(:,1));
    p2 = unique(P(:,2));
    if length(p1) <= length(p2)
        tmp = setdiff(V,p1);
    else
        tmp = setdiff(V,p2);
    end

    % get the new species count
    Nspc(i) = length(tmp);
    
    clear tmp P
    
end