← Lucas B. C. Rocha

Artificial Intelligence course · Python + numpy · interactive demo

Grouping DNA sequences by similarity, without choosing how many groups

Each sequence becomes a vector with the frequency of every k-mer. Instead of a number of clusters you choose how similar the members must be, and a greedy mean shift in the style of MeShClust forms and then merges the clusters. This page runs the same algorithm as meshclust.py, step by step, on the 16 hepatitis B virus sequences of the repository.

1 Input

  1. k-mer vectors
  2. Phase 1: mean shift
  3. Phase 2: merging
  4. Result

2 Sequences in k-mer space

2-D projection (PCA) of the vectors

3 Terminal


        

4 k-mer frequency vectors

one row per sequence, one column per k-mer; darker = more frequent

How the mean shift works here

Each sequence is cut into overlapping k-mers and the counts are divided by the total. The similarity of two sequences is the overlap of their vectors, sum(min(a, b)): 1 for the same composition, 0 for nothing in common.

  • Phase 1: a cluster starts at a sequence (the centre). Every free sequence with similarity ≥ s to the centre joins. Then the centre shifts to the member most similar to the mean of the members, and the search repeats from there until nobody new joins. The next cluster starts at the free sequence most similar to the last centre.
  • Phase 2: clusters whose centres have similarity ≥ s are merged, from the largest to the smallest, and the centres are recomputed, until nothing changes.

Unlike the MeShClust paper, which predicts alignment identity with a trained model, the threshold here is applied directly to the k-mer similarity, so s = 0.95 is not 95% identity.

5 Similarity to the current centre

6 Clusters