% SEND:
% --- rep (of some K level): the information retrieved from the analysis of Kmers in a single protein 
% --- Pl, K: the length of the protein and the Kmer degree K - for entropy claculation and checks


% GET:
% --- Gstat: get the entropy and the normalized entropy

function Gstat = get_entropy(rep, Pl, K)

% 3) ENTROPY_K =  -SIGMA_i [ ni/(L-K+1) log (ni/(L-K+1)) ]; 
%               where Pi = ni/(L-K+1) is the apperance probablity of the Kmer i (of level K) = 
%               the number of apperance of the Kmer i devided by the protein length minus K+1

tot_rep = sum(rep);
% check
if tot_rep ~= Pl - K + 1
    disp('CHECK Probability for entropy calculus');
    keyboard;
end
% entropy
prob = rep./tot_rep;
entropy = -sum(prob.*log2(prob));

% relative entropy. N = number of Kmers; L = Protein length
% It is important to note the theortical maximal entropy (equal probablity of Kmer) is
%  a) bounded by log2(N) if L >> N (because then, Pi = 1/N and the sum is over N).
%  b) bounded by log2(L) if N > L (because then, Pi ~ 1/L and the sum over N is stopped at L.
if Pl > 20^K
    max_ent = log2(20^K);
else
    max_ent = log2(Pl);
end
norm_ent = entropy/max_ent;


% STRUCTURE OUTPUT
Gstat.Entropy   = entropy;
Gstat.Norm_Ent  = norm_ent;



