% retrieve position hits in windowstable
% 31may
% B
function [Sequencehits1,windowsnext1,windowstable1,WindowsSeqpdist1,WindowsOrSignal1]=positionhits(windowstable,beta,Lim,stag,windowsnext,Sequencehits,WindowsSeqpdist,WindowsOrSignal)
%% retrieve position hits per window
n=numel(windowstable(1,:));
m=numel(windowstable(:,1));

x=1;
for i=1:n
    c=1;
    for j=1:m
        windowstable(j,i)=windowstable(j,i);
        if windowstable(j,i)<(Lim)
            positions{x}(c)=j;
            score{x}(c)=windowstable(j,i);
            c=c+1;
        else
            positions{x}(c)=0;
        end
    end
    x=x+1;
end

%% determine if exists consecutive values
% This matrix assigns by default one point to each window, due the fact
% that it has been recognized into the other sequence, it will add points
% to the "left" window if a match has been detected in a x+full position of
% the next window (making them consecutive matching windows)
% Change: This is comented due the fact that only one value is been
% analized, and evaluated in uncommented "for".

for i=1:n-1
   
   for j=1:numel(positions{i})
        for k=1:numel(positions{i+1})
            if positions{i}(j)+beta==positions{i+1}(k)
            score{i}(j)=score{i}(j)-Lim;
            end
        end
   end

end
c=1;
for i=1:n
    score1(i)=mean(score{i});
    if score1(i)<Lim
        windowsnext1{c}=windowsnext{i};
        windowstable1(:,c)=windowstable(:,i);
        Sequencehits1(:,c)=Sequencehits(:,i);
        WindowsSeqpdist1{:,c}=WindowsSeqpdist{:,i};
        WindowsOrSignal1{:,c}=WindowsOrSignal{:,i};
         c=c+1;
    end
end



end