← Lucas B. C. Rocha

Master's research · UFMS · interactive demo

Finding the substrings that only one set has

Given a sequence s from set A, a set B of sequences and an integer k, find, for each position i of s, the shortest substring starting at i that differs in at least k positions (Hamming distance) from every substring of B of the same length. This page runs the exact algorithm from the thesis, ported from the C++ in Exato/, step by step.

1 Input

  1. Compare s with B
  2. Check lengths
  3. Result

2 Diagonal walk

3 Terminal


        

4 Walk lengths

one column per position i of s, one row per position j of each sequence of B

Why the largest walk is the answer

Put s[i] under t[j] and walk forward until k differences show up. If that happens after L bases, every window of s starting at i with length at least L has k or more differences from the window of t starting at j, and any shorter window has fewer.

A window starting at i is specific only if it beats every start j of every sequence of B, so its minimum length is the largest L in the column. When a walk reaches the end of s or t first, the window must be longer than what fits; at the end, lengths that do not fit in s or in t become -1.

This is the cubic version (khammingDiference1). The quadratic version (khammingDiference2, based on Maass's algorithm) gives the same vector r by reusing longest common extensions along each diagonal.

5 Vector r and specific substrings