Preprint/K-mer

Abstract
In biological sequence analysis, k-mers are unique subsequences of a sequence of length k. Primarily used within the context of computational genomics, in which k-mers are comprised of nucleotides (i.e. ATGC), k-mers are capitalized upon to assemble sequences, improve heterologous gene expression, identify species in metagenomic samples, and create attenuated vaccines. Usually, the term k-mer refers to all of a sequence's length k subsequences, such that the sequence AGAT would have four monomers (A, G, A, and T), three 2-mers (AG, GA, AT), two 3-mers (AGA and GAT) and one 4-mer (AGAT). More generally, a sequence of length L will have L − k + 1 k-mers and nk total possible k-mers, where n is number of possible monomers (four in the case of DNA).

Introduction
k-mers are simply subsequences of a sequence of length k. For example, all the possible k-mers of a sequence are shown in Table 1: A method of visualizing k-mers, the k-mer spectrum, shows the multiplicity of each k-mer in a sequence versus the number of k-mers with that multiplicity (see figure 2 for an example). Interestingly, the number of modes in a k-mer spectrum for a species's genome varies, with most species having a unimodal distribution but all tetrapods having a multimodal distribution.

Forces Affecting k-mer Frequency
The frequency of k-mer usage is affected by numerous forces, working at multiple levels. This section will describe some of these forces, but it is important to note that k-mers for higher values of k are affected by the forces affecting lower values of k as well. For example, if the 1-mer A does not occur in a sequence, none of the 2-mers containing A (AA, AT, AG, and AC) will occur either.

k = 1
When k = 1, there are four DNA k-mers, i.e., A, T, G, and C. At the molecular level, there are three hydrogen bonds between G and C, whereas there are only two between A and T. GC bonds, as a result of the extra hydrogen bond (and stronger stacking interactions), are more thermally stable than AT bonds. Mammals and birds have a higher ratio of Gs and Cs to As and Ts (GC-content), which led to the hypothesis that thermal stability was a driving factor of GC-content variation. However, while promising, this hypothesis did not hold up under scrutiny: analysis among a variety of prokaryotes showed no evidence of GC-content correlating with temperature as the thermal adaptation hypothesis would predict. Indeed, if natural selection were to be the driving force behind GC-content variation, that would require that single nucleotide changes, which are often silent, would have to alter the fitness of an organism.

Rather, current evidence suggests that GC‐biased gene conversion (gBGC) is a driving factor behind variation in GC content. gBGC is a process that occurs during recombination which replaces Gs and Cs with As and Ts. This process, though distinct from natural selection, can nevertheless exert selective pressure on DNA biased towards GC replacements being fixed in the genome. gBGC can therefore be seen as an "impostor" of natural selection. As would be expected, GC content is greater at sites experiencing greater recombination. Furthermore, organisms with higher rates of recombination exhibit higher GC content, in keeping with the gBGC hypothesis's predicted effects. Interestingly, gBGC does not appear to be limited to eukaryotes. Asexual organisms such as bacteria and archaea also experience recombination by means of gene conversion, a process of homologous sequence replacement resulting in multiple identical sequences throughout the genome. That recombination is able to drive up GC content in all domains of life suggests that gBGC is universally conserved. Whether gBGC is a (mostly) neutral byproduct of the molecular machinery of life or is itself under selection remains to be determined. The exact mechanism and evolutionary advantage or disadvantage of gBGC is currently unknown.

k = 2
Despite the comparatively large body of literature discussing GC-content biases, relatively little has been written about dinucleotide biases. What is known is that these dinucleotide biases are relatively constant throughout the genome, unlike GC-content, which, as seen above, can vary considerably. This is an important insight that must not be overlooked. If dinucleotide bias were subject to pressures resulting from translation, then we would expect to see differing patterns of dinucleotide bias in coding and noncoding regions driven by some dinucelotides' reduced translational efficiency. Because we do not, we can therefore infer that the forces modulating dinucleotide bias are independent of translation. Further evidence against translational pressures affecting dinucleotide bias is the fact that the dinucleotide biases of viruses, which rely heavily on translational efficiency, are shaped by their viral family more than by their hosts, whose translational machinery the viruses hijack.

Counter to gBGC's increasing GC-content is CG suppression, which reduces the frequency of CG 2-mers due to deamination of methylated CG dinucleotides, resulting in substitutions of CGs with TGs, thereby reducing the GC-content. This interaction highlights the interrelationship between the forces affecting k-mers for varying values of k.

One interesting fact about dinucleotide bias is that it can serve as a "distance" measurement between phylogenetically similar genomes. The genomes of pairs of organisms that are closely related share more similar dinucleotide biases than between pairs of more distantly related organisms.

k = 3
There are twenty natural amino acids that are used to build the proteins that DNA encodes. However, there are only four nucleotides. Therefore, there cannot be a one-to-one correspondence between nucleotides and amino acids. Similarly, there are 42 or 16 2-mers, which is also not enough to unambiguously represent every amino acid. However, there are 43 or 64 distinct 3-mers in DNA, which is enough to uniquely represent each amino acid. These non-overlapping 3-mers are called codons. While each codon only maps to one amino acid, each amino acid can be represented by multiple codons. Thus, the same amino acid sequence can have multiple DNA representations. Interestingly, each codon for an amino acid is not used in equal proportions. This is called codon-usage bias (CUB). As a parenthetical, when k = 3 we must distinguish between true 3-mer frequency and CUB. For example, the sequence ATGGCA has four k-mer words within it (ATG, TGG, GGC, and GCA) while only containing two codons (ATG and GCA). However, CUB is a major driving factor of 3-mer usage bias (accounting for up to ⅓ of it, since ⅓ of the k-mers in a coding region are codons) and will be the main focus of this section.

The exact cause of variation between the frequencies of various codons is not fully understood. It is known that codon preference is correlated with tRNA abundances, with codons matching more abundant tRNAs being correspondingly more frequent and that more highly expressed proteins exhibit greater CUB. This suggests that selection for translational efficiency or accuracy is the driving force behind CUB variation.

k = 4
Similar to the effect seen in dinucleotide bias, the tetranucleotide biases of phylogenetically similar organisms are more similar than between less closely related organisms. The exact cause of variation in tetranucleotide bias is not well understood, but it has been hypothesized to be the result of the maintenance of genetic stability at the molecular level.

Sequence Assembly and Alignment
In DNA sequence assembly from short read sequencers, k-mers are used to construct De Bruijn graphs that can be used to reconstruct the original sequence. Specifically, each read (which can be of varying length in next-generation sequencers), is broken into its constituent k-mers (for some value of k). These k-mers are then able to be used to create a De Bruijn graph modeling the original, complete sequence (see figure for details). Notably, this approach is very susceptible to read errors, highlighting the importance of error correction. Introduced by the Euler assembler, De Bruijn graph-based methods have become popular with Velvet, SOAPdenovo, and ALLPATHS also using variations of this procedure.

Additionally, k-mers are able to detect genome mis-assembly and bacterial contamination of eukaryotic genome assemblies. Similarly, k-mer spectra have been applied to correcting next-generation sequence data.

Genetics and Genomics
With respect to disease, dinucleotide bias has been applied to the detection of genetic islands associated with pathogenicity. Prior work has also shown that tetranucleotide biases are able to effectively detect horizontal gene transfer in both prokaryotes and eukaryotes.

Another application of k-mers is in genomics-based taxonomy. For example, GC-content has been used to distinguish between species of Erwinia with moderate success. Similar to the direct use of GC-content for taxonomic purposes is the use of T m, the melting temperature of DNA. Because GC bonds are more thermally stable, sequences with higher GC content exhibit a higher T m. In 1987, the Ad Hoc Committee on Reconciliation of Approaches to Bacterial Systematics proposed the use of ΔT m as factor in determining species boundaries as part of the phylogenetic species concept, though this proposal does not appear to have gained traction within the scientific community.

Other applications within genetics and genomics include the detection of recombination sites in genomes, estimation of genome size, identification of CpG islands,  and the DNA barcoding of species.

Metagenomics
k-mer frequency variation is heavily used in metagenomic binning algorithms. In binning, the challenge is to separate sequencing reads into "bins" of reads for each organism, which will then be assembled. TETRA is a notable tool that takes metagenomic samples and bins them into organisms based on their tetranucleotide (k = 4) frequencies. Other tools that similarly rely on k-mer frequency for metagenomic binning are CompostBin (k = 6), PCAHIER, PhyloPythia (5 ≤ k ≤ 6), CLARK (k ≥ 20), and TACOA (2 ≤ k ≤ 6). Recent developments have even applied deep learning to metagenomic binning using k-mers.

k-mers can also be used to estimate species abundance in metagenomic samples, determine which species are present in samples, and identify biomarkers for diseases from samples.

Biotechnology
Modifying k-mer frequencies in DNA sequences has been used extensively in biotechnological applications to control translational efficiency. Specifically, it has been used to both up- and down-regulate protein production rates.

With respect to increasing protein production, reducing unfavorable dinucleotide frequency has been used yield higher rates of protein synthesis. In addition, codon usage bias has been modified to create synonymous sequences with greater protein expression rates. Similarly, codon pair optimization, a combination of dinucelotide and codon optimization, has also been successfully used to increase expression.

The most studied application of k-mers for decreasing translational efficiency is codon-pair manipulation for attenuating viruses in order to create vaccines. Researchers were able to recode dengue virus, the virus that causes dengue fever, such that its codon-pair bias was more different to mammalian codon-usage preference than the wild type. Though containing an identical amino-acid sequence, the recoded virus demonstrated significantly weakened pathogenicity while eliciting a strong immune response. This approach has also been used effectively to create an influenza vaccine as well a vaccine for Marek's disease herpesvirus (MDV). Notably, the codon-pair bias manipulation employed to attenuate MDV did not effectively reduce the oncogenicity of the virus, highlighting a potential weakness in the biotechnology applications of this approach. To date, no codon-pair deoptimized vaccine has been approved for use.

Two later articles help explain the actual mechanism underlying codon-pair deoptimization: codon-pair bias is the result of dinucleotide bias. By studying viruses and their hosts, both sets of authors were able to conclude that the molecular mechanism that results in the attentuation of viruses is an increase in dinucleotides poorly suited for translation.

GC-content, due to its effect on DNA melting point, is used to predict annealing temperature in PCR, another important biotechnology tool.

Implementation
Simply finding all the k-mers in a sequence is a simple task, although, as will be seen, doing so efficiently at scale is a nontrivial challenge. Below are sample implementations in common bioinformatics languages.

Pseudocode
procedure k_mers(sequence, k)     /* iterate over the length of sequence */ for i=1 to length(sequence)-k+1 inclusive do          /* output the k-mer from i to i+k in sequence*/ output sequence[i:i+k] end for end procedure

Python
In Python, an efficient generator function is included in the itertools documentation : from itertools import islice def k_mers(sequence, k): it = iter(sequence) result = tuple(islice(it, k)) if len(result) == k:        yield "".join(result) for elem in it: result = result[1:] + (elem,) yield "".join(result)

Perl
sub k_mers { my ($sequence, $k) = @_; my $len = length($sequence); my @result = ; for (my $i = 0; $i <= $len-$k; $i++) { push(@result, substr($sequence, $i, $k)); } 	return @result; }

R
k_mers <- function(sequence, k) { substring(sequence, 1:(nchar(sequence)-k+1), k:nchar(sequence)) }

In Bioinformatics Pipelines
Because the number of k-mers grows exponentially for values of k, counting k-mers for large values of k (>10) is a computationally difficult task. While the simple implementations above work for small values of k, they need to be adapted for high-throughput applications or when k is large. To solve this problem, various approaches have been developed:
 * Jellyfish uses a multithreaded, lock-free hash table for k-mer counting and has Python, Ruby, and Perl bindings.
 * KMC is a tool for k-mer counting that uses a multidisk architecture for optimized speed.
 * Gerbil uses a hash table approach but with added support for GPU acceleration.
 * K-mer Analysis Toolkit (KAT) uses a modified version of Jellyfish to analyze k-mer counts.

Acknowledgements
The author would like to thank James Mallet and Nathaniel Edelman for their early feedback on this article as well as Paul Gamble, Maria Barrios, Karl Ni, Cory Stephenson, and Todd Stavish for their feedback on the completed manuscript.

Wikipedia pages that should link here

 * BLAST
 * Oligonucleotide
 * Genomic signature
 * Gene prediction
 * Transposable element
 * Inferring horizontal gene transfer
 * De novo sequence assemblers

=References=