%mMutualCounter_IF_OnebyOne_BP.m

if isfield(handles, 'SEQNAME')
    delete('handles.SEQNAME')%clear previous values
end

NSeq_all    =   zeros(1,length(ChosenDomains));                                       %Optimized for Speed%
NSeq        =   zeros(1,length(ChosenDomains));
Count(length(BPs),length(BPs),length(InputData(:,1)),length(ChosenDomains))   =   0;  %Optimized for Speed%
Percent(length(BPs),length(BPs),length(InputData(:,1)),length(ChosenDomains)) =   0;  %Optimized for Speed%
SumTotal    =   zeros(length(InputData(:,1)),length(ChosenDomains));                  %Optimized for Speed%

SEQNAME{DomainLimits(length(DomainLimits)),length(BPs),length(BPs)}=[];%initiation

%             fprintf('\n%s %s %s\n','Computing',PercentCharacter,'...');
n=1;
for P=ChosenDomains
    NSeq_all(P) = DomainLimits(P+1)-DomainLimits(P);
    y = DomainLimits(P)+1;
    z = DomainLimits(P+1);
    %if z>y
    for a=1:length(BPs)
        for b=1:length(BPs)
            %clear SeqName(a,b,n,P,:);
            %Match(a,b,n,P,:)           =   strcmp(BPs(a,b),PosArray(y:z,:,n));            %Optimized for Speed% (strcmp is much faster than strmatch)
            Count(a,b,n,P)  =   sum(strcmp(BPs(a,b),PosArray(y:z,:,n)));                   %Optimized for Speed%
            Amm             =  find(strcmp(BPs(a,b),PosArray(y:z,:,n)));
            for x=1:Count(a,b,n,P)%length(Amm)
                %SeqName(a,b,n,P,x) = FastaOrganismNames(Amm(x) + DomainLimits(P)); %%%%This format is used for printing the html
                SEQNAME(x,a,b)      = FastaOrganismNames(Amm(x)+DomainLimits(P)); %%%%Another needed format to print into One-by-one GUI
            end
        end
    end
    %end
    % &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&This is the sum of GOOD sequences
    NSeq(P)=sum(sum(Count(:,:,n,P)));%%%VERY IMPORTANT MODIFICATION, WILL CAUSE TROUBLE WHEN WE START DISPLAYING ONLY CERTAIN BASEPAIRS AND NOT ALL
    % &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    for a=1:length(BPs)
        for b=1:length(BPs)
            Percent(a,b,n,P)=100*Count(a,b,n,P)/NSeq(P);%%%%%%%NSeq(P)
            Percent(a,b,n,P)=round(Rounding*Percent(a,b,n,P))/Rounding;
        end
    end
    %     SumColumns(:,:,n,P)   =   sum(Count(:,:,n,P));
    %     SumRows(:,:,n,P)      =   sum(Count(:,:,n,P)');
    %     SumTotal(n,P)         =   sum(SumColumns(:,:,n,P));    %NOT always fixed to closest decimal, regardless of the value of the variable "Rounding"
    %
    %     if Percentages == 1
    %         SumColumns(:,:,n,P)   =   100*SumColumns(:,:,n,P)/NSeq(P);
    %         SumColumns(:,:,n,P)   =   round(Rounding*SumColumns(:,:,n,P))/Rounding;
    %         SumRows(:,:,n,P)      =   100*SumRows(:,:,n,P)/NSeq(P);
    %         SumRows(:,:,n,P)      =   round(Rounding*SumRows(:,:,n,P))/Rounding;
    %         SumTotal(n,P)         =   100*SumTotal(n,P)/NSeq(P);
    %         SumTotal(n,P)         =   round(Rounding*SumTotal(n,P))/Rounding;
    %     end
end


if PercentsCounts == 2,
    VALUE=Count;
else VALUE=Percent;
end

% if ~exist('SEQNAME','var')
%     SEQNAME=[];
% end
