Finish 2000-03-27 00:00:00 UTC

GFD5.4g

by Francois Glineur

Status: Passed
Results: 99.9961
CPU Time: 20.039
Score: 51691.0
Submitted at: 2000-03-24 15:39:28 UTC
Scored at: 2000-03-24 15:42:50 UTC

Current Rank: 81st
Based on: GFD5.4f (diff)

Comments
Please login or create a profile.
Code
function Sequence = GFD5(Segments)
% Garde en place Segments et StartSegments

[nSegs, lSegs] = size(Segments);

[SortedHash Order]  = sort(Segments * rand(lSegs, 1));
startSegs = Order(diff([SortedHash ; 0]) ~= 0)';
endSegs = startSegs;

nSegs = length(startSegs);

Description = cell(nSegs, 1);
for index = startSegs
   Description{index} = index;
end

matchLength = lSegs-1;
while matchLength > 0
   RandWeight = randn(matchLength, 1);
   LeftHash = Segments(endSegs, lSegs-matchLength+1:end) * RandWeight;
   RightHash = Segments(startSegs, 1:matchLength) * RandWeight;
   Compare = LeftHash * (RightHash.^(-1))';
   [leftIndices, rightIndices] = find(abs(Compare - 1) < 1e-10);
   indexLeft = 1;
   while indexLeft <= length(endSegs) & leftIndices
      Match = rightIndices(leftIndices == indexLeft); 
      if Match
         indexRight = Match(1);
         if (indexRight == indexLeft) & (length(Match) > 1) % Rare case, happens e.g. with strvcat('AAA','AAG','AGC')
            indexRight = Match(2); 
         end
         if indexRight ~= indexLeft
            Description{startSegs(indexLeft)} = [Description{startSegs(indexLeft)} lSegs-matchLength Description{startSegs(indexRight)}];
            startSegs(indexRight) = startSegs(indexLeft); Compare(:, indexRight) = Compare(:, indexLeft); 
            startSegs(indexLeft) = []; 
            endSegs(indexLeft) = []; 
            t = find(rightIndices == indexRight); leftIndices(t) = []; rightIndices(t) = []; % Remove column iR
            rightIndices(rightIndices == indexLeft) = indexRight; % Move column iL to iR
            rightIndices(rightIndices > indexLeft) = rightIndices(rightIndices > indexLeft) - 1; % Delete column iL
            t = find(leftIndices == indexLeft); leftIndices(t) = []; rightIndices(t) = []; % Delete row  iL
            leftIndices(leftIndices > indexLeft) = leftIndices(leftIndices > indexLeft) - 1; % continued
            % ICI ON PEUT ELIMINER TOUTES LES LIGNES EN DESSOUS DE ILEFT
            if length(endSegs) == 1 
               matchLength = 1;
               break;   
            end
         else
            indexLeft = indexLeft + 1;
         end
      else
         indexLeft = indexLeft + 1;
      end
   end
   matchLength = matchLength - 1;
end
if length(startSegs) > 1 % If disjoint segments in the end, we have to merge them
   for index = 2:length(startSegs)
      Description{startSegs(1)} = [Description{startSegs(1)} lSegs Description{startSegs(index)}];
   end
   startSegs = startSegs(1);
end
Sequence(repmat(cumsum([0 Description{startSegs}(2:2:2*nSegs-2)])', 1, lSegs) + repmat(1:lSegs, nSegs, 1)) = Segments((Description{startSegs}(1:2:2*nSegs-1)), :);