function [] = aaDeltaFreqPlot(aaDelta);
% aaDeltafreqPlot is used to plot the frequences of amino acids
% Program by Steinar Thorvaldsen, april 2004. Last changes 22. july 2005.

% Use:      
%           aaDeltaFreqPlot(aaDelta)
% Input
% aaDelta:  matrix(Number of genes x pop x aa x level)containing the aa freq

% Reconstructing the Maximal dimension of the data:
[Mgene,Mpop,Maa,Mlayer] = size(aaDelta);

% Each layer is analysed separately:
for layer=1:Mlayer
    % To finde the mean and standard deviation of the most extreme group (Mpop):
    aa_freq_groupM=mean(aaDelta(:,Mpop,:,layer),1);
    aa_std_groupM=std(aaDelta(:,Mpop,:,layer));
    
    % To find the variation in mean aa composition in the other groups of sequences:
    %for n=1:Mpop-1
    %    aa_freq_group(n,:)=mean(aaDelta(:,n,:,layer),1);
    %end
    
    % To plot the results for all groups:
    figure
    ymax=3;
    max_percent=ceil(max(max(aa_freq_groupM))); %adjusting y-axes
    if max_percent>5 ymax=max_percent+2; end
    title(['Mean difference in composition of amino acids, layer ', num2str(layer)]);
    axis ([0 21 -ymax ymax]);
    hold on
    errorbar (1:20, aa_freq_groupM(1,1,:), aa_std_groupM(1,1,:),'-sb','LineWidth',1)
    xakse(1:22)=0;
    plot (0:21, xakse,'k','LineWidth',1) % ploting x-axis
    %plot (1:20, aa_freq_group(2:Ngroups,aaNr),'LineWidth',1)
    aa_letter=char('A','R','N','D','C','Q','E','G','H','I','L','K','M','F','P','S','T','W','Y','V');
    set(gca,'XTick',1:1:20);
    set(gca,'XTickLabel',{aa_letter(:)}); %labeling plot
    %set(gca,'XTickLabel',{aa_letter(aaNr)}); %labeling plot in sorted order of the aa
    hold off;

end %layer loop

