k-mer counter

Counts every k-mer in DNA or a FASTA file, with canonical k-mers and a table you can download.

k-mer counts

What is a k-mer?

A k-mer is a substring of length k. A sequence is read one base at a time, and every window of k bases is one k-mer, so the windows overlap: ACGTA holds the 3-mers ACG, CGT and GTA. Counting them turns a sequence into a composition vector that can be compared, clustered or tested for bias, and it is the first step in assembly, read classification, repeat detection and motif discovery.

k-mers in a sequence of length L = L − k + 1
Possible k-mers = 4k
Canonical k-mers = (4k + 4k/2) / 2 for even k, 4k / 2 for odd k

The share printed next to each count is the count divided by the number of k-mers counted, not by the length of the sequence.

Worked example

"Try an example" loads a 240 nt sequence built around BamHI sites. With k = 4 there are 240 − 4 + 1 = 237 4-mers, and 78 of the 256 possible 4-mers occur. The most frequent is GATC with 17 counts, 7.2% of the 237, because every GGATCC site contains one. Turn on "Merge reverse complements" and the same sequence gives 50 canonical 4-mers of the 136 possible, with ATCC (ATCC plus GGAT) on top at 24.

Canonical k-mers and both strands

Double-stranded DNA carries a k-mer and its reverse complement at the same place. Counting them separately splits one observation in two and makes a genome look more diverse than it is, so read counters, assemblers and sketching tools collapse each pair into one canonicalk-mer, taking whichever of the two comes first alphabetically. Turn the option on for genomic DNA and sequencing reads. Leave it off for mRNA, single-stranded RNA or anything where the strand is part of the answer. An even k has 4k/2 k-mers that are their own reverse complement (GATC, AATT and so on), which is why the canonical total is not simply half.

How to choose k

kPossibleTypical use
14Base composition, GC content
216Dinucleotide bias, CpG depletion
364Triplet and codon-like composition
4 to 6256 to 4,096Motif enrichment, restriction site counts, genome signatures
7 to 1016,384 to 1,048,576Repeat and low-complexity work, small reference indexes
21 to 31very largeAssembly and read classification, command-line tools only

A rule of thumb: k is informative while 4k is well above the length of the sequence, and saturated once it is far below. With 240 nt and k = 4 most 4-mers are still missing, while k = 2 would give all 16.

How the sequence is read

  • Upper and lower case are the same, and U is counted as T, so RNA works too.
  • Windows containing N or any other ambiguity code are skipped rather than guessed.
  • In a multi-record FASTA every record is counted separately, so no k-mer spans two records. The totals are for the whole file.
  • Only the forward strand is read unless reverse complements are merged.

Related composition tools: GC and AT content for the k = 1 case,Shannon entropy for how even the composition is, andtandem repeat finder when a high k-mer count turns out to be one microsatellite.

Frequently asked questions

How do I count k-mers in a DNA sequence?

Paste the sequence or choose a FASTA file, then set k. Every window of k bases is counted, the headline tells you how many of the 4^k possible k-mers actually occur, and the table lists each k-mer with its count and share. Copy or Download gives the whole table as tab-separated text.

What are canonical k-mers?

A k-mer and its reverse complement are the same piece of double-stranded DNA read from the two strands. "Merge reverse complements" adds the two counts together and reports the alphabetically first of the pair, which is what assemblers and read counters mean by a canonical k-mer. Use it for genomic DNA and sequencing reads; leave it off for single-stranded RNA or when strand matters.

Which k should I use?

Small k for composition: 1 gives base composition, 2 dinucleotides, 3 codon-like triplets, 4 to 6 the usual motif and bias work. Larger k is for identity: 21 to 31 is common for assembly and read classification, but that needs a command-line counter, not a browser tab. This page allows k from 1 to 10.

What happens to N and ambiguity codes?

Any window that contains a character other than A, C, G, T or U is skipped, so an N does not create a false k-mer and does not silently become an A. The count of skipped windows follows from the totals: a record of length L contributes L − k + 1 windows in all.

Can it count k-mers in a whole genome?

A few megabases, such as a bacterial genome, are counted in well under a second, because the file is read and counted on your own device. For large eukaryotic genomes or sets of sequencing reads, and for k above 10, use jellyfish, KMC or BBTools on the command line.