function [aa_P] = aaAnova1Pvalues(aaTotal, group, threshP);
% aaAnova1Pvalues is used to find significant differences between counts of amino acids 
% by univariate one-way unbalanced ANOVA.
% A non-parametric test, Kruskal-Wallis, may also be used as an alternative.
% Program by Steinar Thorvaldsen, steinart@math.uit.no, Nov. 2006. 
% Ref.: http://www.math.uit.no/bi/deltaprot/

% Use:     [aa_P]=aaAnova1Pvalues(aaTotal, group, 0.05);

% Input
% aaTotal:  M x 20 x levels with counts of aa, where M is the number of seq.
%           Counts of amino acids from 2 or more different groups of organisms
% group:    a vector containin factor levels (groups) of the observations in aaTotal 
% threshP:  Threshold p-value for significance. For later use/ploting.
% Last changes 7. Nov 2006.ance level.

% Output
% aa_P:     20 x levels. Array with statistical P-values for the observed differences.

% The function is made flexible conserning input parameters:
if nargin < 3
    threshP=0.05; % default
end

[M N D] = size(aaTotal);
M1 = length (group);
if M ~= M1
    error('Anova test: Matrix with observations must match the group vector');
end

% Perform statistical testing:
for d=1:D % Each layer is analysed separately
    for aaNo=1:N
        aa_P(aaNo,d)= anova1(aaTotal(:,aaNo,d),group,'off'); % perform ANOVA test
        %aa_P(aaNo,d)= kruskalwallis(aaTotal(:,aaNo,d),group,'off'); %non-parametric test
    end
end %layer loop
