# Null model for gap finding algorithm

Today’s post will be about a simple null model for the distribution of “gaps” in coverage when metagenomic reads are mapped against a reference genome. We can use this null model to try to detect places in the genome where a lack of coverage is real and due to that genetic element not being present (at least not at high abundance) in the gene pool.

## Model definition

Suppose we have a genome of length . Suppose we have a sample of reads, each of length , which map
onto the genome. Further suppose that these reads are distributed evenly across the genomes. We then define a *gap* as a
continuous region on the genome that has no coverage - that is, a consecutive string of nucleotides which have no
reads mapping to them. Under this model, what is the empirical distribution , where is the size of a
gap?

## Computing expectations

As posed, we want to find a distribution of distributions - the probability distribution over empirical distributions. In general, this is a complicated problem. However, we can show that computing , the expected number of gaps of size , is a far more tractable task.

There are potential gaps of size exactly . Suppose that , so this number is well approximated by . (We will later see that this is a reasonable assumption for large .) If we can compute the probability that any of these individual blocks is a gap, we can compute the expectation exactly.

For a region of length to be a gap, and not be contained in any other gap, there must be no reads in the block, and at least one read flanking each side of the gap. We can compute the probability of such an event directly. We label the gap by the integers to , inclusive. We adopt the convention that a read starts at the lowest included number and ends at the highest. Our condition then amounts to:

- No reads which start from to inclusive.
- At least one read which starts at and at least one which starts at .

We start with the computation of the probability of the first event. There are positions which can’t have a read start; this gives us

If $g-\ell-1\ll L$, we have

We now need to calculate the probability that there is at least one read flanking either side of the gap, given that there are no reads in the gap. Let $F_{1}$ and $F_{2}$ be the events that there are reads flanking the left and right sides of the gap respectively. We have

which we can write in terms of the individual flanking probabilities as

These probabilities can be computed as:

We can rewrite and use the large $L$ approximation again:

We can factor out the genome length by defining the per nucleotide coverage . The expected number of gaps is given by

If as well, we have

We have a roughly exponential distribution, with scale $\ell/C$ and total number of gaps given by . The “typical” largest gap approximately occurs when , which occurs at

For low coverage (), the total number of gaps is roughly and , or . This makes sense; as goes to zero there are total gaps, which corresponds to the space between adjacent reads, which are all non-intersecting.

The cumulative distribution functions are often useful, as they transform nicely under rescalings. Additionally, if we are using the null distribution to filter out spurious gaps, we can use the CDF to define a cutoff. Let be the number of gaps with length greater than . We have

or, in the low coverage case,

## Model validity and relaxations

The expectation function will be a good approximation of the empirical distribution when the genome is long compared to the read lengths and the typical (or perhaps somewhat) block lengths. In this case, we can think of dividing the genome into sublocks which are each statistically independent in terms of gap distributions. This is true up to the block-spanning gaps, which may contribute to the tail of the distribution. One can compare the tails of the blocked and full expectation distributions to try to understand when there are many such roughly independent blocks, and therefore when the empirical distribution is close to the expectation. Furthermore, the fact that the distribution does not have heavy tails suggests that the expectation function will well characterize the

This model makes some strong assumptions. First, it assumes uniform read length and coverage across the genome. Both of these are expected to fail; reads will have some distribution (though this distribution will be quite narrow for Illumina reads), and more importantly there will be areas of the genome which naturally have higher or lower coverage. One easy way to extend the model would be to try to see the effects of different distributions of coverage and read sizes. A simple approach would be to take these distributions from a dataset of interest to see if the data can inform the model.

## Using the model to fit data

Naively fitting the model to data leads to issues; in particular, there are global coverage biases due to GC content etc., and often one can find parts of the genome with extremely high coverage (eg in locations which are more conserved across different types). Coverage issues are further complicated by the possible presence of multiple closely related types in the population. Therefore, figuring out the appropriate model parameters can be non-trivial, especially in the sparse coverage regime. For example, the coverage can be biased by high coverage areas and lead to too many gaps being called. It is useful then to think about the parameters and figure out which ones may be more or less sensitive to these issues.

There are three free parameters in the model:

- , the genome length.
- , the typical read length
- , the number of reads Note that the coverage, which shows up in many of the expressions as a useful quantity, is a composite involving all three.

In most cases, is known and fixed. The question then comes to and . Given some estimate of the coverage (an easily computable average), how should we estimate and ?

With Illumina short reads, the distribution of (or really, the mapped ) tends to be relatively narrow. Therefore if we have some estimate of via either filtering, or some other method, we should treat it as changing the estimate of as opposed to . Otherwise we can also run into issues where lowering coverage can raise the total number of gaps, even in the low coverage situation.