This post introduces some background for minimizers and some experiments for a new minimizer variant. That new variant is now called the mod-minimizer and published at WABI24 (DOI, PDF) (Groot Koerkamp and Pibiri 2024). The paper also includes a review of existing methods, including pseudocode for most of the methods covered below.
This content has also been absorbed into my thesis chapter on minimizers.
This posts discusses some variants of minimizers, inspired by the previous post on bidirectional anchors.
Minimizer schemes take an
The rest of this post:
- first lists some applications,
- then introduces some existing minimizer schemes,
- then introduces some new ideas,
- and lastly evaluates all schemes on random data.
- Finally, there are a bunch of experiments logs for small
.
Applications Link to heading
Minimizers can be used for various purposes, such as:
- Compressing sequences, such as in minimizer-space De Bruijn graphs (Ekim, Berger, and Chikhi 2021).
- Similarity estimation,
- Locality preserving hashing of kmers for different types of clustering.
- (Pibiri 2022; Pibiri, Shibuya, and Limasset 2023).
- Here a large
is used so that minimizers are unique keys. - The objective is to have as few minimizers as possible in any sequence, to reduce the number of cache-misses due to non-locality.
- Here a large
- Similarity estimation (Li 2016).
- Here the goal is to cluster similar reads. Ideally reads with a few small mutations have the same minimizer.
- (Pibiri 2022; Pibiri, Shibuya, and Limasset 2023).
Locality preserving hashing and similarity estimation both cluster kmers on similarity, but there are some differences:
- In LPH, we want consecutive kmers to share a minimizer. I.e. we want to partition the De Bruijn graph into long paths.
- In similarity estimation, we want similar kmers to share a minimizer, where similar explicitly includes small mutations. I.e. we want to partition the De Bruijn graph into ‘blobs’ covering many variants.
Background Link to heading
Related but out of scope topics are:
- universal minimizers: not really a local sampling scheme;
- spaced minimizers/strobemers: used for similarity search methods, but not used for locality sensitive hashing.
Minimizers Link to heading
Minimizers were introduced independently
by Roberts et al. (2004) and Schleimer, Wilkerson, and Aiken (2003): Given a
An example:
|
|
Density bounds Link to heading
By definition, minimizers sample at least one in every
- Random minimizers have a density of
when (Zheng, Kingsford, and Marçais 2020b; Marçais et al. 2017). - Schleimer, Wilkerson, and Aiken (2003) prove that on random strings, any minimizer scheme has a
density at least
but this lower bound is false, or at least, makes overly strong assumptions. - Marçais, DeBlasio, and Kingsford (2018) contradict that theorem by
constructing a universal minimizer with lower density, and remark that the
previous result only applies to ‘randomized local schemes’.
- Instead they prove that density is at least
- In the mod-minimizer paper, we simplify and improve this to:
and show that it holds not only for forward schemes but also for local schemes.
- Instead they prove that density is at least
Robust minimizers Link to heading
To reduce the density, Schleimer, Wilkerson, and Aiken (2003) suggest the following: when the minimizer of the preceding k-mer is still a minimizer, reuse it, even when it is not rightmost.
Continuing the example:
|
|
When the same kmer occurs twice in an
Still there is a drawback: When two distinct kmers have the same hash, only one
of them is selected. Although unlikely, this is not good for downstream
applications. To prevent this, minimizers
PASHA Link to heading
PASHA (Ekim, Berger, and Orenstein 2020) is another minimizer selection algorithm based on a universal hitting set. It works as follows:
- Start with a complete De Bruijn graph of order
, i.e., containing all kmers. - Remove from this a minimal set of
-mers that make the graph acyclic. - Then remove additional
-mers to remove all paths of length .- This is done using the DOCKS heuristic (Orenstein et al. 2017), which greedily
removes the vertex containing the most (length
) paths.
- This is done using the DOCKS heuristic (Orenstein et al. 2017), which greedily
removes the vertex containing the most (length
PASHAs main contribution is a considerable speedup over DOCKS. It still remains
slow and has to process the full
Miniception Link to heading
Miniception (Zheng, Kingsford, and Marçais 2020b) is another minimizer selection algorithm. It
works using an additional parameter
For a window
- Find all kmers whose minimal contained
-mer is at its start or end. - In case there are multiple (or none), break ties using random order on kmers.
In the limit, it achieves density down to
Sadly the preprint (Zheng, Kingsford, and Marçais 2020a) has a typo in Figure 6, making the results hard to interpret.
Closed syncmers Link to heading
Given
Note that closed syncmers are not directly a sampling scheme, since each kmer is independently determined to be a closed syncmer or not. This can be fixed by using an order on kmers to break ties, like miniception does.
Closed syncmers are very similar to miniception. In fact, miniception is more
general since it’s parameter
Quote:
Density is not the appropriate optimization metric
Several recent papers have focused on minimizing the density of minimizers for given k and w; see (Zheng, Kingsford & Marçais, 2020) and references therein. This would be an appropriate optimization strategy if submers were used to find identical longer substrings in different sequences, but this is rarely the primary goal of an application and other methods are better suited to this task (e.g., Burrows–Wheeler indexes).
Bd-anchors Link to heading
Bidirectional anchors (bd-anchors) are a variant on minimizers that take the minimal lexicographic rotation instead of the minimal k-mer substring (Loukides, Pissis, and Sweering 2023; Ayad, Loukides, and Pissis 2023). I wrote above them before in this post.
Reduced bd-anchors restrict this rotation to not start in the last
Density: Reduced bd-anchors have a density of
Bd-anchors have a slightly different purpose than minimizers, in that they are keyed by their position in the text, rather than by the corresponding string itself. Thus, a suffix array is built on suffixes and reverse-prefixes starting/ending there.
For random strings, reduced bd-anchors are a dense subset of the
Given the bd-anchors, two suffix arrays are built. One of suffixes starting at anchors, and one on reverse prefixes ending at anchors.
Note: bd-anchors are not a so-called forward scheme. That is, it is possible for the window to shift right, but the selected position to jump backwards. Example here.
Optimization:
When querying an
- The forward SA over suffixes only needs to contains bd-anchors occurring in
the left half of some
-mer. - The reverse SA over suffixes only needs to contains bd-anchors occurring in
the right half of some
-mer.
This makes things slightly sparser.
New: Mod-minimizers Link to heading
Bidirectional anchors have a benefit over minimizers since they always use
Why do we use large
It seems that two conceptually distinct parameters are merged:
- The length
of the minimizer, which we would like to be small. - The length
of the key we want to extract, which we would like to be larger.
Inspired by previous methods, here is a new sampling scheme, mod-sampling.
- First, choose a small parameter
, but large enough to prevent duplicate -mers. - Find the position
of the smallest -mer in the -mer window. - Sample the kmer at position
.
We define two specific cases:
- The lr-minimizer uses
for . - The mod-minimizer uses
for , where ensures that is not too small.
Here is an example for
|
|
NOTE: As it turns out, lr-minimizers are very similar to closed syncmers. In
particular compare the figure above with figure 1b in (Edgar 2021). The main
difference is that lr-minimizers are context aware and break ties by the value
of the chosen
Here is an example with a
|
|
Mod-minimizers have low density when
Experiments Link to heading
Here are some quick results.
- Code is at https://github.com/RagnarGrootKoerkamp/minimizers.
- PASHA is excluded – even though it’s very good, it’s too much effort to download
mers to quickly benchmark it. - For methods taking a parameter
or , I did a brute-force search from to (as long as they are valid), or around in case that is larger than .
Figure 1: Density for various minimizer types, for alphabet size (4) and string length (n=10^5). All of (k), (w), and density are in log scale. Black lines indicate (2/(w+1)) and (1/w).
Note:
- bd-anchors (not shown) depend only on
, and hence density decreases in . - Miniception is always better than vanilla minimizers.
- Mod-minimizers don’t do anything for
, but are best for .- Can we optimize them more? By using more ideas from miniception?
- Can we optimize miniception by introducing a third layer of minimizers??
- Or what if we sort filtered kmers by their contained k0-mer before comparing their own hash?
- For larger alphabet
(not shown), results are mostly the same but bd-anchors have slightly lower density.
Conclusion Link to heading
For
- Mod-minimizers are also an instance of a minimizer scheme w.r.t. a
specific order, namely: the hash of a kmer is the minimal hash over the tmers
occurring in a position
. - In the large-
limit, the minimizer schem - forward scheme - local scheme hierarchy collapses: minimizers already achieve the lower bound that holds for local schemes.
Small k experiments Link to heading
From here onward, this is a ’lab-log’, primarily intended for preserving some of my notes/thoughts, not for easy reading.
This leaves the case of small
- For
, it is clear that density is the best we can do. - TODO For
, minimizer schemes are boring, but forward/local schemes TODO - For alphabet size
, everything is trivial.
Thus, we start our search at parameters
- the best minimizer scheme,
- the best forward scheme,
- the best local scheme.
The question is:
- Are forward schemes better than minimizer schemes?
Answer: YES. But so far, only in the following way: where minimizer schemes always select the leftmost occurrence in case of ties, optimal forward schemes switch between leftmost and rightmost occurrences.
It’s open whether there are more interesting differences.
- Are local schemes better than forward schemes?
- Marçais, DeBlasio, and Kingsford (2018) mentions that using ILP they found
an example for
, where a non-forward scheme is better than a forward scheme, but they do not give the example nor explain details on how it’s found. For I can not reproduce this, so probably was used.
- Marçais, DeBlasio, and Kingsford (2018) mentions that using ILP they found
an example for
Search methods Link to heading
- Minimizer scheme bruteforce
- Iterate over all
orders, evaluate density on a De Bruijn word of
order
- ILP
- We set up an Integer Linear Program.
- For each of
l-mers, we create binary variables indicating which kmer in is chosen. - We construct a DeBruijn word of order
, and create a variable for each contained -mer. - For each
-mer in the text, we add an inequality that if a position in the l-mer is selected, the corresponding position in the text must also be selected. - For forward schemes, we add additional inequalities ensuring forwardness.
- For each of
Note: for
Directed minimizer Link to heading
It appears all optimal local schemes found above have slightly lower density than corresponding minimizer schemes. But in fact the local schemes are very similar to minimizer schemes. They are all instances of ‘directional minimizers’, a small generalization of minimizers that explicitly handles ties:
Directed Minimizer. Given is an order
,
Link to heading
Proven lower bound on local:
Random mini for
Best possible density. Forward and local schemes are the same for
alg \ s | ||||
---|---|---|---|---|
mini | ||||
directed mini | same | same | same | same |
forward=local | same | same | same | same |
bound | same | less | less | less |
(I suspect I made some inefficiency in the bound proof and it should be identical everywhere.)
,
Link to heading
alg \ s | |
---|---|
mini | |
directed mini | |
forward | |
local | same |
bound |
,
Link to heading
alg \ s | |
---|---|
mini | |
directed mini | |
forward | |
local | |
bound |
,
Link to heading
Best lower bound so far:
Hypothesis: best is
Random mini for
Again, forward and local are the same.
alg \ s | |||
---|---|---|---|
mini | - | ||
directed mini | - | - | |
forward=local | same |
,
Link to heading
- Local scheme beats forward here!
- But differences are only in tie-breaking between equal kmers.
alg \ s | ||
---|---|---|
mini | ||
directed mini | - | |
forward | same | - |
local | - |
Notes Link to heading
- Hypothesis: For
large enough so that all kmers are distinct, minimizers, forward, and local schemes are equally good. - Local can be strict better than forward.
- Forward can be strict better than directed mini (
, ). - Directed mini can be strict better than mini.
Reading list Link to heading
- minimizer-review
- masked-minimizers
- small-window-decycling
- Marcais 2021
- In the O(sqrt(w)/w) and O(ln(w)/w) density methods, what fails to get O(1/w)? ie just choose d=log_sigma(w)?
- Rotates the Mykkeltveit embedding by 1 step. Rotates the other direction.
- Z_delta is so cool!