## Abstract

K-mer-based methods are widely used in bioinformatics, but there are many gaps in our understanding of their statistical properties. Here, we consider the simple model where a sequence S (e.g. a genome or a read) undergoes a simple mutation process whereby each nucleotide is mutated independently with some probability r, under the assumption that there are no spurious k-mer matches. How does this process affect the k-mers of S? We derive the expectation and variance of the number of mutated k-mers and of the number of islands (a maximal interval of mutated k-mers) and oceans (a maximal interval of non-mutated k-mers). We then derive hypothesis tests and confidence intervals for r given an observed number of mutated k-mers, or, alternatively, given the Jaccard similarity (with or without minhash). We demonstrate the usefulness of our results using a few select applications: obtaining a confidence interval to supplement the Mash distance point estimate, filtering out reads during alignment by Minimap2, and rating long read alignments to a de Bruijn graph by Jabba.

## 1 Introduction

*K*-mer-based methods have become widely used, e.g. for genome assembly [1], error correction [26], read mapping [16, 14], variant calling [31], genotyping [32, 7], database search [29, 11], metagenomic sequence comparison [37], and alignment-free sequence comparison [30, 22, 27]. A simple but influential recent example has been the Mash distance [22], which uses the minhash Jaccard similarity between the sets of *k*-mers in two sequences to estimate their average nucleotide divergence. Mash has been applied to determine the appropriate reference genome for in silico analyses [28], for genome compression [33], for clustering genomes [22, 3], and for estimating evolutionary distance from low-coverage sequencing datasets [27]. *K*-mer-based methods such as Mash are often faster and more practical then alignment-based methods. However, while the statistics behind sequence alignment are well understood [10], there are many gaps in our understanding of the statistics behind *k*-mer-based methods.

Consider the following simple mutation model and the questions it raises. There is a sequence of nucleotides *S* that undergoes a mutation process, whereby every position is mutated with some constant probability *r*_{1}, independently of other nucleotides. In this model, we assume that *S* does not have any repetitive *k*-mers and that a mutation always results in a unique *k*-mer (we say that there are no *spurious matches*). This mutation model captures both a simple model of sequence evolution (e.g. Jukes-Cantor) and a simple model of errors generated during sequencing, under the assumptions that *k* is large enough and the repeat content low enough to make the effect of spurious matches negligible. It is applied to analyze algorithms and the predictions of the model often reflect performance on real biological sequences (e.g. [27, 22]).

How does this simple mutation model affect the *k*-mers of *S*? This question bears resemblance but is distinct from questions studied by Lander and Waterman [15] and in alignment-free sequence comparison [30] (we elaborate on the connection in Section 1.1). Some aspects of this question have been previously explored (e.g. [19, 26, 34]), but some very basic ones have not. For example, what is the distribution of the number of mutated *k*-mers? The expectation of this distribution is known and trivial to derive, but we do not know its variance. For another example, consider that the *k*-mers of *S* fall into mutated stretches (which, inspired by Lander-Waterman statistics, we call islands) and non-mutated stretches (which we call oceans). What is the distribution on the number of these stretches? We do not even know the expected value. We answer these and other questions in this paper, with most of the results captured in Table 1.

We immediately apply our findings to derive hypothesis tests and confidence intervals for *r*_{1} from the number of observed mutated *k*-mers, the Jaccard similarity, and the Jaccard similarity under minhash. Previously, none were known, even though point estimates from these had been frequently used (e.g. Mash). In order to do this, we observe that our random variables are *m*-dependent [13], which, roughly speaking, means that the only dependencies involve *k*-mers nearby in the sequence. We apply a technique called Stein’s method [25] to approximate these as Normal variables and thereby obtain hypothesis tests and confidence intervals.

We demonstrate the usefulness of our results using a few select applications: obtaining a confidence interval to supplement the Mash distance point estimate [22], filtering out reads during alignment by Minimap2 [16], and rating long read alignments to a de Bruijn graph by Jabba [19]. These examples illustrate how the use of the simple mutation model and the techniques from our paper could have potentially improved several widely used tools. Our technique can also be applied to new questions as they arise. Our code for computing all the intervals in this paper is freely available at https://github.com/medvedevgroup/mutation-rate-intervals.

### 1.1 Related work

Here we give more background on how our paper relates to other previous work.

#### Lander-Waterman statistics

There is a natural analogy between the stretches of mutated *k*-mers and the intervals covered by random clones in the work of Lander and Waterman [15]. Each error can be viewed as a random clone with fixed length *k*, and thus the islands in our study correspond to “covered islands” in theirs. However, their focus was to determine how much redundancy was necessary to cover all (or most) of a genomic sequence, which would correspond to how many nucleotide mutations are needed so that most of the *k*-mers in the sequence are mutated. In particular, they expect average coverage of the sequence by clones to be greater than 1, while in our study we expect the corresponding value, ≈ *k*(1 − (1 − *r*)^{k}, to be much less than 1. Thus, the approximations applied in [15] do not hold in our case.

#### Alignment-free sequence comparison

In alignment-free analysis, two sequences are compared by comparing their respective vectors of *k*-mer counts [30]. Two such vectors can be compared in numerous ways, e.g. through the the *D*_{2} similarity measure, which can be viewed as a generalization of the number of mutated *k*-mers we study in this paper. However, in alignment-free analysis, both the underlying model and the questions studied are somewhat different. In particular, alignment-free analysis usually works with much smaller values of *k*, e.g. *k <* 10 [38]. This means that most *k*-mers are present in a sequence, and *k*-mers will match between and within sequences even if they are in different locations and not evolutionarily related. Our model and questions assume that these spurious matches are background noise that can be ignored (which is justifiable for larger *k*), while they form a crucial component of alignment-free analysis. As a result, much of the work in measuring expectation and variance in metrics such as *D*_{2} is done with respect to the distribution of the original sequences, rather than after a mutation process [23, 5]. Even when the mutation processes have been studied, they have typically been very different from the ones we consider here (e.g. the “common motif model” [23]). Later works [20, 24] did consider the simple mutation model that we study here, though still with a small *k*. Sequence similarity has also been estimated using the average common substring length between two sequences [12]. This is similar to the distribution of oceans that we study in our paper, but the difference is that oceans are both left- and right-maximal, while the common substrings considered by [12] and others are only right-maximal.

## 2 Preliminaries

Let *L >* 0 be a positive integer. Let [*L*] to denote the interval of integers {0, …, *L* − 1}, which intuitively captures positions along a string. Let *k >* 0 be a positive integer. The *k-span* at position 0 ≤ *i < L* is denoted as *K*_{i} and is the range of integers [*i, i* + *k* − 1] (inclusive of the endpoints). Intuitively, a *k*-span captures the interval of a *k*-mer. We think of [*L* + *k* − 1] as representing an interval of length *L* + *k* − 1 that contains *L k*-spans. To simplify the statements of the theorems, we will in some places require that *L* ≥ *k* (or similar), i.e. that the interval is of length at least 2*k* − 1. We believe this covers most practical cases of interest, but, if necessary, the results can be rederived without this assumption.

We define the *simple mutation model* as a random process that takes as input two integers *k >* 0 and *L >* 0 and a real-valued *nucleotide error rate* 0 *< r*_{1} *<* 1. For every position in [*L* + *k* − 1], the process *mutates* it with probability *r*_{1}. A mutation at position *i* is said to *mutate* the *k*-spans *K*_{max(0,i−k+1)}, …, *K*_{i}. We define *N*_{mut} as a random variable which is the number of mutated *k*-spans. As shorthand notation, we use *q* ≜:. 1 − (1 − *r*_{1})^{k} to denote the probability that a *k*-span is mutated. Figure 1 shows an example.

The simple mutation model formalizes the notion of a string *S* undergoing mutations where there are no spurious matches, i.e. there are no duplicate *k*-mers in *S* and a mutation always creates a unique *k*-mer. This is also closely related to assuming that *S* is random and *k* is large enough so that such spurious matches happen with low probability. The simple mutation model captures these scenarios by representing *S* using the interval [*L* + *k* − 1] and a *k*-mer as a *k*-span.

We can partition the sequence *K*_{0}, …, *K*_{L−1} into alternating intervals called *islands* and *oceans*. The range *i*, …, *j* is an *island* iff all *K*_{i}, …, *K*_{j} are mutated, and the range is maximal, i.e. *K*_{i−1} and *K*_{j+1} are either not mutated or out of bounds. Similarly, the range is an *ocean* iff none of *K*_{i}, …, *K*_{j} are mutated, and the interval is maximal. We define *N*_{ocean} as a random variable which is the number of oceans and *N*_{isl} as the number of islands (see Figure 1).

Consider two strings composed of a set of *k*-mers *A* and *B*, respectively, and let *s* ≤ min |*A*|, |*B*| be a non-negative integer. The *Jaccard similarity* between *A* and *B* is defined as . The *minhash sketch C*_{S} of a set *C* is the set of the *s* smallest elements in *C*, under a uniformly random permutation hash function. The *minhash Jaccard similarity* between *A* and *B* is defined as , or, equivalently, |(*A* ∪ *B*)_{S} ∩ *A*_{S} ∩ *B*_{S}|*/s* [2]. In order to transplant this to our model, we define the *sketching simple mutation model* as an extension of the simple mutation model, with an additional non-negative integer parameter *s* ≤ *L*. We follow the intuition of [*L* + *k* − 1] representing a string *S* with no spurious matches. For every position *i*, if *K*_{i} is non-mutated (respectively, mutated), we think of *K*_{i} as being shared (respectively, distinct) between the strings before and after the mutation process. Formally, let U be a universe which contains an element *shared*_{i} for every non-mutated *K*_{i} and, for every mutated *K*_{i}, contains two elements *a*-*distinct*_{i} and *b*-*distinct*_{i}. Let *A* be the set of all *shared*_{i} and *a*-*distinct*_{i}, and let *B* be the set of all *shared*_{i} and *b*-*distinct*_{i}. The output of the sketching simple mutation model is the minhash Jaccard similarity between *A* and *B*, i.e. Ĵ = |(*A* ∪ *B*)_{S} ∩ *A*_{S} ∩ *B*_{S}|*/s*. Note that the Jaccard similarity (without sketches) would, in our simple mutation model, be the ratio between the number of *shared*_{i} and the size of U, which is .

Given a distribution with a parameter of interest *p*, an *approximate* (1 − *α*)*-confidence interval* is an interval which contains *p* with limiting probability 1 − *α*. Closely related, an *approximate hypothesis test with significance level* (1 − *α*) is an interval that contains a random variable with limiting probability 1 − *α*. We will drop the word “approximate” in the rest of the paper, for brevity. We will use the notation *X* ∈ *x* ± *y* to mean *X* ∈ [*x* − *y, x* + *y*]. Given 0 *< α <* 1, we define *z*_{α} = Φ^{−1}(1 − *α/*2), where Φ^{−1} is the inverse of the cumulative distribution function of the standard Gaussian distribution. Let *H*(*x, y, z*) denote the hypergeometric distribution with population size *x, y* success states in population, and *z* trials. We define *F*_{n}(*a*) = Pr[*H*(*L* + *n, L* −*n, s*) ≥*a*]. Both Φ^{−1} and *F*_{n} can be easily evaluated in programming languages such as R or python.

## 3 Number of mutated *k*-mers: expectation and variance

In this section, we look at the distribution of *N*_{mut}, i.e. the number of mutated *k*-mers. The approach we take to this kind of analysis, which is standard, is to express *N*_{mut} as a sum of indicator random variables whose pairwise dependence can be derived. Let *X*_{i} be the 0*/*1 random variable corresponding to whether or not the *k*-span *K*_{i} is mutated; i.e., *X*_{i} = 1 iff at least one of its nucleotides is mutated. Hence, Pr[*X*_{i} = 1] = 1 − (1 − *r*_{1})^{k} ≜. *q*. We can express *N*_{mut} = Σ*X*_{i}. By linearity of expectation, we have

The key to the computation of variance is the joint probabilities of two *k*-mers being mutated.

*Let* 0 ≤ *i < j < L. Then, X*_{i} *and X*_{j} *are independent if j* − *i* ≥ *k and* Pr[*X*_{i} = 1, *X*_{j} = 1] = 2*q* − 1 + (1 − *q*)(1 − *r*_{1})^{j−i} *otherwise*.

*Proof*. Set *δ* = *j* − *i*. If *δ* ≥ *k*, then *K _{i}* and

*K*

_{i+δ}do not overlap and therefore the variables

*X*

_{i}and

*X*

_{i+δ}are independent. Otherwise, consider three events.

*E*

_{1}is the event that at least one of the positions

*i*, …,

*i*+

*δ*− 1 is mutated.

*E*

_{2}is the event that none of

*i*, …,

*i*+

*δ*− 1 is mutated and one of

*i*+

*δ*, …,

*i*+

*k*− 1 is mutated.

*E*

_{3}is the event that none of

*i*, …,

*i*+

*k*− 1 is mutated. Notice that the three events form a partition of the event space and so we can write Pr[

*X*

_{i}= 1,

*X*

_{j}= 1] = Pr[

*X*

_{i}= 1,

*X*

_{j}= 1 |

*E*

_{1}]Pr[

*E*

_{1}] + Pr[

*X*

_{i}= 1,

*X*

_{j}= 1 |

*E*

_{2}]Pr[

*E*

_{2}] + Pr[

*X*

_{i}= 1,

*X*

_{j}= 1 |

*E*

_{3}]Pr[

*E*

_{3}] = Pr[

*X*

_{j}= 1 |

*E*

_{1}]Pr[

*E*

_{1}] + 1 · Pr[

*E*

_{2}] + 0 · Pr[

*E*

_{3}] =

*q*(1 − (1 −

*r*

_{1})

^{δ}) + (1 −

*r*

_{1})

^{δ}(1 − (1 −

*r*

_{1})

^{k−δ}) =

*q*−

*q*(1 −

*r*

_{1})

^{δ}+ (1 −

*r*

_{1})

^{δ}− (1 −

*q*) = 2

*q*− 1 + (1 −

*q*)(1 −

*r*

_{1})

^{δ}.

We can now compute the variance using tedious but straightforward algebraic calculations. As we will show in the following section, knowing the variance allows us to obtain a confidence interval or do a hypothesis test based on *N*_{mut}.

*If* .

## 4 Hypothesis test for *M* -dependent variables

Our derivations of hypothesis tests and confidence intervals follows the strategy used for the Binomials, which we now describe so as to provide intuition. In the case of estimating the success probability *p* of a Binomial variable *X* when the number of trials *L* is known, a confidence interval for *p* is called a binomial proportion confidence interval [6]. There are multiple ways to calculate such an interval, as described and compared in [4], and we will follow the approach of the Wilson score interval [36]. It works by first approximating the Binomial with a Normal distribution and then applying a standard score. The result is that , where Var(*X*) = *Lp*(1 − *p*) and *ε*(*L, p*) is a function such that lim_{L→∞} *ε*(*L, p*) = 0; recall that *z*_{α} = Φ^{−1}(1−*α/*2). This can be solved for *X* to obtain a hypothesis test . This can be converted into a confidence interval by finding all values of *p* for which holds. In the particular case of the Binomial, a closed form solution is possible [36], but, more generally, one can also find the solution numerically.

Though random variables like *N*_{mut} are not Binomial, they have a specific form of dependence between the trials, which allows us to apply a similar strategy. A sequence of *L* random variables *X*_{0}, …, *X*_{L−1} is said to be *m*-dependent if there exists a bounded *m* (with respect to *L*) such that if *j* − *i > m*, then the two sets {*X*_{0}, …, *X*_{i}} and {*X*_{j}, …, *X*_{L−1}} are independent [13]. In other words, *m*-dependence says that the dependence between a sequence of random variables is limited to be within blocks of length *m* along the sequence. It is known that the sum of *m*-dependent random variables is asymptotically normal [13] and this was previously used to construct heuristic hypothesis tests and confidence intervals [18]. Even stronger, the rate of convergence of the sum of *m*-dependent variables to the Normal distribution is known due to a technique called Stein’s method (see Theorem 3.5 in [25]). (This technique applies even to the case where *m* is not bounded, but that will not be the case in our paper.) Here, we apply Stein’s method to obtain a formally correct hypothesis test together with a rate of convergence for a sum of *m*-dependent (not necessarily identically distributed) Bernoulli variables.

*Let* *be a sum of m-dependent Bernoulli random variables, where X*_{i} *has success probability p*_{i}. *Let* , *and* . *Then*, Pr[*X* ≥ *Lµ* + *z*_{α}*σ*_{L}] = Pr[*X* ≤ *Lµ* − *z*_{α}*σ*_{L}] = *α/*2 − *ε/*2 *and*
*where* .

*Proof*. Let *Y* = (*X* − *Lµ*)*/σ*_{L} and let *Z* be a standard norm al random variable. From Theorem 3.6 in [25], we have , where *d*_{W}(·, ·) denotes the Wasserstein metric. Since *Z* is a standard normal random variable, we have the following standard inequality between the Kolmogorov and Wasserstein metrics (see, e.g., Section 3 in [25]):

Recall that for a standard normal variable, Pr[*Z* ≥ *z*_{α}] = *α/*2 and so, by the above, Pr[*Y* ≥ *z*_{α}] ∈ *α/*2 ± *ε*_{max}. Similarly, since Pr[*Z* ≤ −*z*_{α}] = *α/*2 we obtain Pr[*Y* ≤ −*z*_{α}] ∈ *α/*2 ± *ε*_{max}. From the definition of *Y* it then follows that Pr[*X* ≥ *Lµ* + *z*_{α}*σ*_{L}] ∈ *α/*2 ± *ε*_{max} and Pr[*X* ≤ *Lµ* − *z*_{α}*σ*_{L}] ∈ *α/*2 ± *ε*_{max}, and therefore implies that Pr[*X* ∈ *Lµ* ± *z*_{α}*σ*_{L}] ∈ 1 − *α* ± 2*ε*_{max}.

As we will see, *m*-dependence is well-suited for dealing with variables in the simple mutation model. In most natural cases, the error |*ε*| → 0 when *L* → ∞, and Lemma 3 gives a hypothesis test with significance level 1 − *α*.

## 5 Hypothesis tests for *N*_{mut} and *Ĵ* and confidence intervals for *r*_{1}

There is a natural point estimator for *r*_{1} using *N*_{mut}, defined as . This estimator is both the method of moments and the maximum likelihood estimator, meaning it has nice convergence properties as *L* increases [35]. In this section, we extend it to a confidence interval and a hypothesis test, both from *N*_{mut} and *Ĵ* (with and without sketching). In the *N*_{mut} setting, Lemma 1 shows that *X*_{0}, …, *X*_{L−1} are *m*-dependent with *m* = *k* − 1. Hence we can apply Lemma 3 to .

*Let* , *and Let* . *Then* Pr[*N*_{mut} ≥ *n*_{high}] = Pr[*N*_{mut} ≤ *n*_{low}] = *α/*2 − *ε/*2 *and*
*where* |*ε*| ≤ *c/L*^{1/4} *and c is a constant that depends only on r*_{1} *and k. In particular, when r*_{1} *and k are independent of L, we have* lim_{L→∞}(1 − *α* + *ε*) = 1 − *α*.

Corollary 4 gives the closed-form boundaries for a hypothesis test on *N*_{mut}. To compute a confidence interval for *q* (equivalently, for *r*_{1}), we can numerically find the range of *q* for which the observed *N*_{mut} lies between *n*_{low} and *n*_{high}. In other words, the upper bound on the range would be given by the value of *q* for which the observed *N*_{mut} is *n*_{low} and the lower bound by the value of *q* for which the observed *N*_{mut} is *n*_{high}. These observations are made rigorous in Theorem 5. We will use the notation to denote *N*_{mut} with parameter *r*_{1} = 1 − (1 − *q*)^{1/k}.

*For fixed k, r*_{1}, *and α, for a given observed value of* , *there exists an L large enough such that there exists a unique q _{low} such that*

*and a unique q*,

_{high}such that*and*

*where*|

*ε*| ≤

*c/L*

^{1/4}

*and c is a constant that depends only on r*

_{1}

*and k. In particular, for fixed r*

_{1}

*and k, we have*lim

_{L→∞}(1 −

*α*+

*c*) = 1 −

*α*.

Note that this theorem states that for sufficiently large *L*, there is a unique solution for the value of *q* for which the observed *N*_{mut} is *n*_{high} (and similarly a unique solution for the value of *q* for which the observed *N*_{mut} is *n*_{low}). For small *L*, we have no such guarantee (though we believe the theorem holds true for all *L* ≥ *k*); to deal with this possibility, our software verifies if the solutions are indeed unique by computing the derivative inside the proof of Theorem 5 and checking if it is positive. If it is, then the proof guarantees the solutions to be unique; if it is not, our software reports this. However, during our validations, we did not find such a case to occur.

We want to underscore how the difference between a confidence interval and a hypothesis test is relevant in our case. A confidence interval is useful when we have two sequences, one of which having evolved from the other and we would like to estimate their mutation rate from the number of mutated *k*-spans. A hypothesis test is useful when we know the mutation rate a priori, e.g. the error rate of a sequencing machine. In this case, we may want to know whether a read could have been generated from a putative genome location, given the number of observed mutated *k*-spans. We will see both applications in Section 7.

In some cases, *N*_{mut} is not observed but instead we observe another random variable *T* = *f* (*N*_{mut}), where *f* (*x*) is a monotone function. For example, if *f* (*x*) = (*L* − *x*)*/*(*L* + *x*), then *T* is the Jaccard similarity between the original and the mutated sequence (in our model). In this case, a hypothesis test with significance level *α* is to check if *T* lies between *f* (*n*_{low}) and *f* (*n*_{high}). In addition to the Jaccard, [17] describe 14 other variables that are a function of *N*_{mut}, *L*, and *k*. These are: Anderberg, Antidice, Dice, Gower, Hamman, Hamming, Kulczynski, Matching, Ochiai, Phi, Russel, Sneath, Tanimoto and Yule. We can apply our hypothesis test to any of these variables, as long as they are monotone with respect to *N*_{mut}.

We can also use Lemma 3 as a basis for deriving a hypothesis test on *Ĵ* in the sketching model. The proof is more involved and interesting in its own right, but is left for the Appendix due to space constraints.

*Consider the sketching simple mutation model with known parameters s, k, L ≥ k, r*_{1}, *and output JĴ. Let* 0 < *α* < 1 *and let m* ≥ 2 *be an integer*. *For* 0 ≤ *i* ≤ *m, let* *and* . *Let*

*Then, assuming that r*_{1} *and k are independent of L, and m* = *o*(*L*^{1/4}),

We can compute a confidence interval for *q* from *Ĵ* in the same manner as with Corollary 4. Let *j*_{low}(*q*) and *j*_{high}(*q*) be defined as in Theorem 6, but explicitly parameterized by the value of *q*. Then we numerically find the smallest value 0 *< q*_{low} *<* 1 for which *j*_{low}(*q*_{low}) = *Ĵ* and the largest value 0 *< q*_{high} *<* 1 for which *j*_{high}(*q*_{high}) = *Ĵ*. The following theorem guarantees that [*q*_{low}, *q*_{high}] is a confidence interval for *q*.

*For fixed k, r*_{1}, *α, m, and a given observed value of Ĵ, there exists an L large enough such that there exist unique intervals* *and* *such that* *if and only if* , *and* *if and only if* . *Moreover, assuming that r*_{1}, *k and m are independent of L, we have*

## 6 Number of islands and oceans

In this section, we derive the expectation and variance of *N*_{isl} and *N*_{ocean} and the hypothesis test based on them. For *N*_{isl}, we follow the same strategy as for *N*_{mut}, namely to express *N*_{isl} as a sum of indicator random variables whose joint probabilities can be derived. Let us define a *right border* as a position *i* such that *K*_{i} is mutated and *K*_{i+1} is not. We will denote it by an indicator variable *B*_{i}, for 0 ≤ *i < L* − 1. Let us also say that there exists an *end-of-string border* iff *K*_{L−1} is mutated. We will denote this by an indicator variable *Z*. A right border is a position where an island ends and an ocean begins, and the end-of-string border exists if the last island is terminated not by an ocean but by the end of available nucleotides in the string to make a *k*-mer. The number of islands is then the number of borders, i.e. .

To compute the expectation, observe that *Z* is a Bernoulli variable with parameter *q*. For *B*_{i}, observe that the only way that *K*_{i} is mutated while *K*_{i+1} is not is if position *i* is mutated and the positions *i* + 1, …, *i* + *k* are not. Therefore, *B*_{i} ∼ *Bernoulli*(*r*_{1}(1−*q*)). By linearity of expectation,

Next, we derive dependencies between border variables and use them to compute the variance.

*Let* 0 ≤ *i < j* ≤ *L* − 2. *Then* Pr[*B*_{i} = 1, *B*_{j} = 1] = 0 *if j* ≤ *i* + *k and* *otherwise. Also*, Pr[*B*_{i} = 1, *Z* = 1] = Pr[*B*_{i} = 1]Pr[*Z* = 1] = *r*_{1}*q*(1 − *q*) *if i* ≤ *L* − 2 − *k, and* Pr[*B*_{i} = 1, *Z* = 1] = *r*_{1}(1 − *q*)(1 − (1 − *r*_{1})^{L−2−i}) *otherwise*.

*Proof*. Observe that when *j* − *i > k*, the positions that have an effect on *B*_{i} (i.e. *K*_{i}, …, *K*_{i+k}) and those that have an effect on *B*_{j} (i.e. *K*_{j}, …, *K*_{j+k}) are disjoint. Hence, *B*_{i} and *B*_{j} are independent in this case. When 1 ≤ *j* − *i* ≤ *k, B*_{i} and *B*_{j} cannot co-occur. This is because *B*_{i} = 1 implies that position *j* is not mutated, while *B*_{j} = 1 implies that it is. By the same logic, *Z* is independent of all *B*_{i} for 0 ≤ *i* ≤ *L* − 2 − *k*. For the case when *L* − 2 − *k < i* ≤ *L* − 2, *B*_{i} = 1 implies that positions *L* − 1, …, *i* + *k* are not mutated. Therefore, there is an end-of-string border when *B*_{i} = 1 iff one of the positions *i* + *k* + 1, …, *L* + *k* − 2 is mutated. Thus, Pr[*Z* = 1, *B*_{i} = 1] = Pr[*Z* = 1 | *B*_{i} = 1]Pr[*B*_{i} = 1] = (1 − (1 − *r*_{1})^{L+k−2−(i+k+1)+1})*r*_{1}(1 − *q*).

*For L* ≥ *k* +3, .

Lemma 8 also shows that *N*_{isl} is *m*-dependent, with *m* = *k* − 1, Therefore, a hypothesis test on *N*_{isl} can be obtained as a corollary of Lemma 3.

*Fix r*_{1} *and let* 0 *< α <* 1. *Then, the probability that* *is* 1 − *α* + *ε, where* |*ε*| ≤ *c/L*^{1/4} *and c is a constant that depends only on r*_{1} *and k. In particular, when r*_{1} *and k are independent of L, we have* lim_{L→∞}(1 − *α* + *ε*) = 1 − *α*.

Unlike for Corollary 4, it is not as straightforward to invert this hypothesis test into a confidence interval for *r*_{1}, since the endpoints of the interval of *N*_{isl} are not monotone in *r*_{1}. We therefore do not pursue this direction here. The derivation of the expectation and variance for *N*_{ocean} is analogous and left for the Appendix (Theorem 12). Observe that |*N*_{ocean} − *N*_{isl}| ≤ 1, so, as expected, the expectation and variance are identical to *N*_{isl} in the higher order terms. Corollary 10 also holds for the case that *n* is the observed number of oceans, if we just replace *N*_{isl} with *N*_{ocean}.

An immediate application of *N*_{ocean} is to compute a hypothesis test for the *coverage by exact regions* (*C*_{ber}), a variable earlier applied to score read mappings in [19]. *C*_{ber} is the fraction of positions in [*L* + *k* − 1] that lie in *k*-spans that are in oceans. The total number of bases in all the oceanic *k*-spans is the number of non-mutated *k*-spans plus, for each ocean, an extra *k* − 1 “starter” bases. We can then write

We can use the expectations and variances of *N*_{mut} (eq. (1) and Theorem 2) and *N*_{ocean} (Theorem 12) to derive the expectation and variance of *C*_{ber}:

*and, for L* ≥ *k* + 3,, *where*

Then, observing that *C*_{ber} is a linear combination of *m*-dependent variables and hence itself *m*-dependent, we can apply Lemma 3 and obtain that, when *r*_{1} and *k* are independent of *L*,.

## 7 Empirical results and applications

In this section, we evaluate the accuracy of our results and demonstrate several applications. A sanity check validation of the correctness of our formulas for E[*N*_{mut}] and Var[*N*_{mut}] is shown in Table S1, however, most of the expectation and variance formulas are evaluated indirectly through the accuracy of the corresponding confidence intervals. We focus the evaluation on accuracy rather than run time, since calculating the confidence interval took no more than a few seconds for most cases (the only exception was for sketch sizes of 100k or more, the evaluation took on the order of minutes). Memory use was negligible in all cases.

### 7.1 Confidence intervals based on *N*_{mut}

In this section, we evaluate the accuracy of the confidence intervals (CIs) produced by Corollary 4 (other CIs will be evaluated indirectly through applications). We first simulate the simple mutation model to measure the accuracy, shown in the left three groups (i.e. *L* = 100, 1000, 10000) of Table 2, for *α* = 0.05. We observe that the predicted CIs are very accurate at *L* = 1000, and also accurate for smaller *k* and *r*_{1} when *L* = 100. Similar results hold for *α* = 0.01 (Table S2) and *α* = 0.10 (Table S3). The remainder of the cases had a CI that was too conservative; these are also the cases with some of the smallest variances (Table S1) and we suspect that, similar to the case of the Binomial, the Normal approximation of *m*-dependent variables deteriorates with very small variances. However, further investigation is needed.

Next, we investigate how well our predictions hold up when we simulate mutations along a real genome, where we can only observe the set of *k*-mers without their positions in the genome (as in alignment-free sequence comparison). We start with the *E*.*coli* genome sequence and, with probability *r*_{1}, for every position, flip the nucleotide to one of three other nucleotides, chosen with equal probability. Let *A* and *B* be the set of distinct *k*-mers in *E*.*coli* before and after the mutation process, respectively. We let *L* = (|*A*| + |*B*|)*/*2 and *n* = *L* − |*A* ∩ *B*|. We then calculate the 95% CI for *r*_{1} under the simple mutation model (Corollary 4) by plugging in *n* for *N*_{mut}. The rightmost group in Table 2 shows the accuracy of these CIs. We see that the simple mutation model we consider in this paper is a good approximation to mutations along a real genome like *E*.*coli*.

### 7.2 Mash distance

The Mash distance [22] (and its follow-up modifications [21, 27]) first measures the minhash Jaccard similarity *j* between two sequences and then uses a formula to give a point estimate for *r*_{1} under the assumptions of the sketching simple mutation model. While a hypothesis test was described in [22], it was only for the null model where the two sequences were unrelated. Theorem 6 allows us instead to give a CI for *r*_{1}, based on the minhash Jaccard similarity, in the sketching simple mutation model. Table 3 reproduces a subset of Table 1 from [22], but using CIs given by Theorem 6. For most cases, the predicted CIs are highly accurate, with an error of at most two percentage points. The three exceptions happen when *s* is small and *q* is large; in such cases, the predicted CI is too conservative (i.e. too large). In Table S4, we also tested the accuracy with a real *E*.*coli* genome by letting *A* and *B* be the set of distinct *k*-mers in the genome before and after mutations, respectively, letting *L* = (|*A*| +|*B*|)*/*2 and *Ĵ* = ((|*A* ∪ *B*|) ∩ *A*_{s} ∩ *B*_{s})*/s*, and applying Theorem 6 with those values. The accuracy is very similar to that in the simple mutation model, demonstrating that for a genome like *E*.*Coli*, the simple mutation model is a good approximation.

### 7.3 Filtering out reads during alignment to a reference

Minimap2 is a widely used long read aligner [16]. The algorithm first picks certain *k*-mers in a read as *seeds*. Then, it identifies a region of the read and a region of the reference that potentially generated it (called a chain in [16]). Let *n* be the number of seeds in the read and let *m* ≤ *n* be the number of those that exist in the reference region. Minimap2 models the error rate of the *k*-mers as a homogenous Poisson process and estimates the sequence divergence between the read and the reference as (which is the maximum likelihood estimator in that model). If is above a threshold, the alignment is abandoned. [16] observes that due to invalid assumptions, is only approximate and can be biased, but nevertheless maintains a good correlation with the true divergence.

Using our paper, we can obtain a more accurate estimate of *r*_{1}. The situation is very similar to estimating *r*_{1} from *N*_{mut}, except that only a subset of *k*-spans are being “tracked.” Therefore, the maximum likelihood estimator for *q* is *m/n* and for *r*_{1} is . Figures 2 and S3 show the relative performance of the two estimators ( and ) for sequences of different lengths, with our much closer to the simulated rate than in both cases.

### 7.4 Evaluating an alignment of a long read to a graph

Jabba [19] is an error-correction algorithm for long read data. At one stage, the algorithm evaluates whether a read is likely to have originated from a given location in the reference. Because Jabba’s reference is a de Bruijn graph and not a string, it uses the specialized *C*_{ber} score for the evaluation. In this scenario, the mutation process corresponds to sequencing errors at a known error rate *r*_{1} and the question is whether the read is likely to have arisen through this process from the given location of the reference. The authors assume the simple mutation model and derive the expected *C*_{ber} score as . They then give a lower rating to reads with a *C*_{ber} score that has “significant deviation” from this expected value. It is not clear how much of a deviation is deemed to be significant or how it was calculated.

Theorem 11, which gives E[*C*_{ber}] and Var[*C*_{ber}], would have allowed [19] to take a more rigorous approach. It shows that the *C*_{ber} expectation computed by [19] is correct only in the limit as *L* → ∞, while our formula is exact and closed-form. More substantially, we can make the determination of “significant deviation” more rigorous. We regenerated Figure 2 from [19], using the same range of values for *k* (called *m* in [19]) and an error rate of *r*_{1} = 10% as in [19] and plotted the 95% confidence interval:. Figure 3 demonstrates that this range would have done a good job at capturing most of the generated reads. Table 4 gives the number of *C*_{ber} values that fall inside of the 95% confidence interval when using a simple mutation process with the same *r*_{1} = 10% for sequences of length 10,000 for 5,000 replicates, with *k* ranging from 5 to 50 in steps of 5, depicting good agreement between simulation and theorem 11.

## 8 Conclusion

The simple mutation model has been used broadly to model either biological mutations or sequencing errors. However, its use has usually been limited to derive the expectations of random variables, e.g. the expected number of mutated *k*-mers. In this paper, we take this a step further and show that the dependencies between indicator variables in this model (e.g. whether a *k*-mer at a given position is mutated) are often easy to derive and are limited to nearby locations. This limited dependency allows us to show that the sum of these indicators is approximately Normal. As a result, we are able to obtain hypothesis tests and confidence tests in this model.

The most immediate application of our paper is likely to compute a confidence interval for average nucleotide identity from the minhash sketching Jaccard. Previously, only a point estimate was available, using Mash. However, we hope that our technique can be applied by others to random variables that we did not consider. All that is needed is to derive the joint probability of the indicator variables and compute the variance. Computing the variance by hand is tedious and error-prone but can be done with the aid of a software like Mathematica.

We test the robustness of the simple mutation model in the presence of spurious matches by using a real *E*.*coli* sequence. However, we do not explore the robustness with respect to violations such as the presence of indels (which result in different string lengths) or the presence of more repeats than in *E*.*coli*. This type of robustness has already been explored in other papers that use the simple mutation model [8, 22, 27]. However, exploring the robustness of our confidence intervals in downstream applications is important future work.

On a more technical note, it would be interesting to derive more tight error bounds for our confidence intervals, both in terms of more tightly capturing the dependencies on *L, r*_{1}, and *k*, and accurately tracking constants. The error bound *ε* that is stated in Lemma 3 is likely not tight in either respect, due to the inherent loss when transferring between the Wasserstein and Kolmogorov metrics and due to loose inequalities within the proof of Theorem 3.5 in [25]. Ideally, tight error bounds would give the user a way to know, without simulations, when the confidence intervals are accurate, in the same way that we know that the Wilson score interval for a Binomial will be inaccurate when *np*(1 − *p*) is low. For example, it would be useful to better theoretically explain and predict which values in Table 2 deviate from 0.95.

Another practical issue is with the implementation of the algorithm to compute a confidence interval for *q* from Ĵ. Theorem 7 guarantees that the algorithm is correct as *L* goes to infinity. However, the user of the algorithm will not know if *L* is large enough for the confidence interval to be correct. There are several heuristic ways to check this, which we have implemented in the software: a short simulation to check the true coverage of the reported confidence interval, a check that the sets in the definitions of *j*_{high} and *j*_{low} are not empty, and a check that *j*_{high} and *j*_{low} are monotonic with respect to *q* in the range 0 *< q <* 1.

## Acknowledgements

PM is grateful to Kirsten E. Eilertson and Benjamin Shaby for discussion. PM was supported by NSF awards 1453527 and 1439057. AB was supported in part by NSF grant CCF-1850443. This material is based upon work supported by the National Science Foundation under Grant No. 1664803

## A Appendix

### A.1 Missing theorems and proofs

*If L* ≥ *k*, .

*Proof*. In the following we will use Lemma 1 and the equality for *x* /= 1 from [9].

*For fixed k, r*_{1}, *and α, for a given observed value of* , *there exists an L large enough such that there exists a unique q*_{low} *such that* *and a unique q*_{high} *such that* , *and*
*where* |*ε*| ≤ *c/L*^{1/4} *and c is a constant that depends only on r*_{1} *and k. In particular, for fixed r*_{1} *and k, we have* lim_{L→∞}(1 − *α* + *c*) = 1 − *α*.

*Proof*. Given the result in corollary 4, we need only show that *q*_{low} and *q*_{high} are well-defined. As such, it is sufficient to show that and are strictly monotonic in *q* for sufficiently large *L*. Equivalently, since *q* = 1 − (1 − *r*_{1})^{k}, these must be strictly monotonic in *r*_{1} which we consider here. For simplicity, we will write *r* instead of *r*_{1} and *N*_{mut} instead of . Focusing then on , consider

After a (tedious) series expansion of the rightside of the equality in eq. (3) about *L* = ∞, we find that . As such, is increasing as a function of *r* as *L* → ∞. The case of showing that is also increasing proceeds in an entirely analogous fashion.

*Consider the sketching simple mutation model with known parameters s, k, L* ≥ *k, r*_{1}, *and output* Ĵ. *Let* 0 *< α <* 1 *and let m* ≥ 2 *be an integer. For* 0 ≤ *i* ≤ *m, let* *and* . *Let*

*Then, assuming that r*_{1} *and k are independent of L, and m* = *o*(*L*^{1/4}),

*Proof*. Recall the definition of *A* and *B* from the definition of the minhash Jaccard estimator. First, we argue that an element of (*A* ∪ *B*)_{S} is in *A*_{S} ∩ *B*_{S} iff it corresponds to a non-mutated *k*-span (i.e. iff *x* = *shared*_{i} for some *i*). Consider an element *x* ∈ (*A* ∪ *B*)_{S}. If *x* corresponds to a mutated *k*-span (i.e. *x* = *a*-*distinct*_{i} or *x* = *b*-*distinct*_{i} for some *i*), then *x* ∉*A* ∩ *B* and so *x* ∉*A*_{S} ∩ *B*_{S}. If *x* does not correspond to a mutated *k*-span (i.e. *x* = *shared*_{i} for some *i*), then *x* ∈ *A* ∩ *B* and *x* ∈ *A*_{S} ∩ *B*_{S} as well.

Next, let *J*′ be the random variable corresponding to |(*A* ∪ *B*)_{S} ∩ *A*_{S} ∩ *B*_{S}|. The minhash Jaccard estimator can then be expressed as *ĵ* = *J′ /s*. Note that *J′* contains randomness due to both the mutation process and to the choice of the minhash permutation. For ease of notation we set *N* = *N*_{mut}. We claim that the distribution of *J′*, conditioned on *N* = *n*, is hypergeometric *H*(*L* + *n, L* − *n, s*). To see this, recall from the discussion in the previous paragraphs that an element of (*A* ∪ *B*)_{S} is in *A*_{S} ∩ *B*_{S} only when it corresponds to a non-mutated *k*-span, and, on the event that *N* = *n*, there are exactly *L* − *n* non-mutated *k*-spans and a total of *L* + *n k*-spans to be hashed. We assume the hash values are assigned with a random permutation. Equivalently, we can generate the hash values by repeatedly assigning the smallest available hash value to an element chosen uniformly at random among those that have not been hashed yet. Then, from the first *s* elements, the probability that exactly *a* of those are selected from the set of the *L* − *n* non-mutated *k*-spans is:
which corresponds to the hypergeometric *H*(*L* + *n*; *L*− *n, s*) probability function.

Our goal is to deduce a confidence interval for *J*Ĵ, or equivalently for *J*′. This can be easily done if we could compute:

However, since we do not have an expression for Pr[*N* = *n*], we will instead obtain an upper and lower bound on *B*(*a*) using Lemma 3. For 1 ≤ *i* ≤ *m*, let and let . Note that and if . Using the law of total probability, we can write

Observe that *F*_{n}(*a*) is a non-increasing function with respect to *n*; this is because increasing *n* in *H*(*L* + *n*; *L* − *n, s*) has the overall effect of reducing the probability of success, since the population size is increased and the number of successes is decreased. Using this, we can find upper and lower bounds for *B*(*a*) as follows.

Similarly, we obtain .

We now approximate and as follows. Observe that when , we have . By Corollary 4, and ; hence, . Here, *ε*_{1} and *ε*_{2} are constants whose absolute value is bounded by *ε*_{max} = *c/L*^{1/4}, with *c >* 0 a constant that depends only on *q* and *k*. Hence, Analogously, we have .

This allows us to further simplify the bounds for *B*(*a*):
and

Let *a*_{max} = min{*a* ≥ 0: *α/*2 *> B*_{l}(*a*)} and *a*_{min} = max{*a* ≤ *s*: *α/*2 *>* 1 − *B*_{h}(*a*)}. Then, Pr[*J′* ∈ [*a*_{min}, *a*_{max}]] = 1 − *α* and so Pr[*J*Ĵ ∈ [*a*_{min}*/s, a*_{max}*/s*]] = 1 − *α*. The theorem then follows by observing that when *r*_{1}, *k* are independent of *L* and *m* = *o*(*L*^{1/4}), we have lim_{L→∞} *ε*_{max}*m* = 0 and so *a*_{min}*/s* → *j*_{low}, and *a*_{max}*/s* → *j*_{high}.

*For fixed k, r*_{1}, *α, m, and a given observed value of J*Ĵ, *there exists an L large enough such that there exist unique intervals* *and* *such that* *if and only if* , *and* *if and only if* . *Moreover, assuming that r*_{1}, *k and m are independent of L, we have*

*Proof*. Recall from Theorem 6 that and . First, observe from Theorem 2 that Var(*N*_{mut}) = *cL* + *o*(*L*), where *c* is a constant depending only on *k* and *r*_{1}. Consequently, and so, for fixed *k, r*_{1}, *α*, and *m*, there exists an *L* sufficiently large such that, for all and . Therefore, for all values of *q*, there exists an *L* sufficiently large such that the summations in the definition of *j*_{low} and *j*_{high} are over 0 ≤ *i* ≤ *m*. Second, in the proof of Theorem 5 we established that and are increasing with *q* provided *L* is sufficiently large. Therefore, the parameters in the subscripts of the *F* terms of *j*_{low} and *j*_{high} are also increasing with *q*, when *L* is sufficiently large. Third, observe that *F*_{n}(*a*) is a non-increasing function of *n* and of *a*. The fact that it is a non-increasing function of *n* we already observed in the proof of Theorem 6. The fact that it is a non-increasing function of *a* follows trivially from its definition. Combining these three observations, we deduce that *j*_{low} are *j*_{high} non-increasing functions of *q*. Therefore, they take on a certain value (i.e. *J*Ĵ) for a unique range of the domain, implying the first assertion of the theorem. The second assertion of the theorem then follows from Theorem 6.

*For L* ≥ *k* +3,.

*Proof*. For convenience, we will define a random variable *X*_{i} for 0 ≤ *i* ≤ *L* − 1 and let *X*_{i} = *B*_{i} for *i < L* − 1 and *X*_{L−1} = *Z*. Also, for notational simplicity, write *r* for *r*_{1}. Figure S1 visualizes the joint probabilities of all *X*_{i}’s, as given in Lemma 8. Using the figure as a guide, we proceed with the derivation.

E[*N*_{ocean}] = *Lr*_{1}(1 − *q*) + (1 − *q*)(1 − *r*_{1}) *and, for L* ≥ *k* + 3,

*Proof*. Let us define *Z′* as an indicator for the event that the first *k*-span (*K*_{0}) is not mutated. Hence E[*Z′*] = (1 − *r*_{1})^{k} = (1 − *q*). Observe that every ocean begins either the start of the interval or a right border. Therefore, the the number of oceans is . Thus E[*N*_{ocean}] = (1 − *q*) +(*L* − 1)*r*_{1}(1 − *q*) = (1 − *r*_{1})(1 − *q*) + *Lr*_{1}(1 − *q*). For the variance, the derivation is equivalent to replacing *Z* with *Z* in the derivation of Theorem 9 and we therefore omit the proof here.

*and, for L* ≥ *k* + 3, , *where*

*Proof*. Throughout, we write *r* instead of *r*_{1} for simplicity. Recall that *C*_{ber} = (*L* − *N*_{mut} + (*k* − 1)*N*_{ocean})*/*(*L* + *k* − 1). Applying linearity of expectation together with eq. (1) and Theorem 12,

Applying the distributive properties of variance to the definition of *C*_{ber} we get:

We only need to compute the covariance. We will use the same definition of variables as previously in Sections 3 and 6. In particular, *X*_{i} is a random variable indicating that *K*_{i} was mutated, *Z′* indicates that *K*_{0} has not mutated, and *B*_{i} indicates that *K*_{i} was mutated and *K*_{i+1} has not. Note that *Z′* = 1 − *X*_{0}. Figure S2 visualizes the joint probabilities of all *X*_{i}’s, *B*_{j}’s, and *Z*. We then compute

Observe that when *i* = 0, E[*Z′X*_{i}] = 0. When 1 ≤ *i* ≤ *k* − 1, E[*Z*^{t}*X*_{i}] = (1 − *q*)(1 − (1 − *r*)^{i}) since the left-most *i* nucleotides are not mutated when *Z′* = 1. When *k* ≤ *i* ≤ *L* − 1, *Z′* and *X*_{i} are independent so E[*Z′X*_{i}] = *q*(1 − *q*). Thus, calculating the first sum in equation (4), we obtain

For the second sum in equation (4), observe that *B*_{j} = 1 implies that *X*_{j} = 1 and *X*_{j+1} = 0. Furthermore, for 2 ≤ *d* ≤ *k*, if *X*_{j+d} = 1, then the leftmost *k* + 1 + *d* nucleotides are unmutated, so from the law of total probability, E[*B*_{j}*X*_{j+d}] = (1 − (1 − *r*)^{d−1})*r*(1 − *q*). Lastly, if *B*_{j} = 1, then for all integers *i* such that max{0, *j* − *k* + 1} ≤ *i* ≤ *j, X*_{i} = 1 as well due to the mutation at position *j*. Hence E[*B*_{j}*X*_{i}] = E[*B*_{j}] = *r*(1 − *q*). Using these observations, we obtain

Putting all of this together and simplifying, we obtain

Factoring out the *L* terms in the numerator, we get

### A.2 Experimental results: extra tables and figures

## Footnotes

* Authors are listed in alphabetical order

† This is the full version of the paper of the same title appearing in the proceedings of RECOMB 2021.

Corrected typos in Lemma 1 and added acknowledgments.