function aaN = findSeqSiteVar(S);
% findSeqSiteVar is used to count amino acid sequence variation along the sequenses S.
% Conserved sites has a variation level of N=1.
% If nessesary the amino acid will be converted from a character to an 
% integer representation.
% Gaps will be counted as aa 21. May be changed?
% Program by Steinar Thorvaldsen, april 2004. 
% Latest modified 4. april 2005.

% Input
% S: character or integer array containing aligned sequence from I genes
% Output
% aaN: vector containing the numbers of different aa in each position along the sequence.

% To determine the number and length of the sequences:
[I,J] = size (S);

aaN = zeros (1,J);

if ischar (S)
    Sint = aa2int(S); % Convert amino acid from a character to an integer representation
else
    Sint = S;
end

for j=1:J
    aaPosN=S(:,j);
    aaPosN=union(aaPosN,aaPosN); %using set union to avoid repetitions
    aaN(1,j)=length(aaPosN); %to find the number of different aa
end
