Files
Eric Coissac e4528725d4 docs: update k-mer indexing docs to use obiskim terminology
Replace references to OBIKmer with obiskim in k-mer indexing documentation and clarify technical constraints. The changes align the documentation with the current implementation details, including representation limits and ordering rules.

- Update `.crate-kit/VERSION` from 0.3.6+0.1.1 to 0.3.7+0.1.1.
- Modify `Makefile` `clean-doc-user` target to delete existing wiki markdown files before regeneration and clarify that wiki commits are manual.
- Rename `OBIKmer` to `obiskim` in `UserDocMD/theory/kmer_indexing/kmers.md` and update k-mer constraints to reflect obiskim's two-bit-per-nucleotide representation ($k \leq 32$, odd $k$).
- Update `UserDocMD/theory/kmer_indexing/minimizer_selection.md` to reference obiskim and specify ordering via deterministic hash function $H$.
- Apply corresponding terminology and constraint updates in `doc/theory/kmer_indexing/kmers/index.html`, including the $11 \leq k \leq 31$ range rationale.
- Update `doc/theory/kmer_indexing/minimizer_selection/index.html` to reference obiskim and the deterministic hash ordering rule.
2026-12-02 16:13:48 +01:00

2084 lines
47 KiB
HTML

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="prev" href="../encoding/">
<link rel="next" href="../minimizer_selection/">
<link rel="icon" href="../../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.7.6">
<title>Kmers - obiskim — User Guide</title>
<link rel="stylesheet" href="../../../assets/stylesheets/main.484c7ddc.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<script>__md_scope=new URL("../../..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#k-mer-size" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<header class="md-header md-header--shadow" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href="../../.." title="obiskim — User Guide" class="md-header__button md-logo" aria-label="obiskim — User Guide" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
obiskim — User Guide
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Kmers
</span>
</div>
</div>
</div>
<script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
</nav>
</header>
<div class="md-container" data-md-component="container">
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href="../../.." title="obiskim — User Guide" class="md-nav__button md-logo" aria-label="obiskim — User Guide" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
</a>
obiskim — User Guide
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../.." class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../installation/" class="md-nav__link">
<span class="md-ellipsis">
Installation
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" checked>
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
<span class="md-ellipsis">
Theory
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_3">
<span class="md-nav__icon md-icon"></span>
Theory
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_1" checked>
<label class="md-nav__link" for="__nav_3_1" id="__nav_3_1_label" tabindex="0">
<span class="md-ellipsis">
Kmer indexing
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_3_1_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_3_1">
<span class="md-nav__icon md-icon"></span>
Kmer indexing
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../encoding/" class="md-nav__link">
<span class="md-ellipsis">
DNA encoding
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
Kmers
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Kmers
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#representation-limit" class="md-nav__link">
<span class="md-ellipsis">
Representation limit
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#odd-k-mer-lengths" class="md-nav__link">
<span class="md-ellipsis">
Odd k-mer lengths
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#k-mer-specificity" class="md-nav__link">
<span class="md-ellipsis">
K-mer specificity
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#choosing-an-appropriate-k-mer-size" class="md-nav__link">
<span class="md-ellipsis">
Choosing an appropriate k-mer size
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#chance-sharing-across-genomes" class="md-nav__link">
<span class="md-ellipsis">
Chance sharing across genomes
</span>
</a>
<nav class="md-nav" aria-label="Chance sharing across genomes">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#the-null-model-and-genome-specific-probabilities" class="md-nav__link">
<span class="md-ellipsis">
The null model and genome-specific probabilities
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#computing-the-poisson-binomial-distribution" class="md-nav__link">
<span class="md-ellipsis">
Computing the Poisson-binomial distribution
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#comparing-observed-and-expected-sharing-in-the-index" class="md-nav__link">
<span class="md-ellipsis">
Comparing observed and expected sharing in the index
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#estimating-the-false-discovery-rate" class="md-nav__link">
<span class="md-ellipsis">
Estimating the false discovery rate
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#limits-of-the-model" class="md-nav__link">
<span class="md-ellipsis">
Limits of the model
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../minimizer_selection/" class="md-nav__link">
<span class="md-ellipsis">
Minimizer selection
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../superkmers/" class="md-nav__link">
<span class="md-ellipsis">
Super-kmers
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../indexing_architecture/" class="md-nav__link">
<span class="md-ellipsis">
Partitioning and indexing architecture
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../entropy_filter/" class="md-nav__link">
<span class="md-ellipsis">
Low-complexity kmer filter
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_2" >
<label class="md-nav__link" for="__nav_3_2" id="__nav_3_2_label" tabindex="0">
<span class="md-ellipsis">
Phylogeny
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_3_2_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_2">
<span class="md-nav__icon md-icon"></span>
Phylogeny
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_2_1" >
<label class="md-nav__link" for="__nav_3_2_1" id="__nav_3_2_1_label" tabindex="0">
<span class="md-ellipsis">
Kmer-based
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="3" aria-labelledby="__nav_3_2_1_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_2_1">
<span class="md-nav__icon md-icon"></span>
Kmer-based
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../phylogeny/kmer_based/kmer_set_distances/" class="md-nav__link">
<span class="md-ellipsis">
Whole k-mer set distances
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_2_2" >
<label class="md-nav__link" for="__nav_3_2_2" id="__nav_3_2_2_label" tabindex="0">
<span class="md-ellipsis">
SNP-based
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="3" aria-labelledby="__nav_3_2_2_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3_2_2">
<span class="md-nav__icon md-icon"></span>
SNP-based
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../phylogeny/snp_based/central_snp_model/" class="md-nav__link">
<span class="md-ellipsis">
Central-position SNP model
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../phylogeny/snp_based/gamma_rate_heterogeneity/" class="md-nav__link">
<span class="md-ellipsis">
Gamma rate heterogeneity
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../phylogeny/snp_based/sankoff_model/" class="md-nav__link">
<span class="md-ellipsis">
Sankoff model
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../phylogeny/snp_based/sampling_design/" class="md-nav__link">
<span class="md-ellipsis">
Sampling design
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" >
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
<span class="md-ellipsis">
Usage
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_4">
<span class="md-nav__icon md-icon"></span>
Usage
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../usage/superkmer/" class="md-nav__link">
<span class="md-ellipsis">
superkmer
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/index_command/" class="md-nav__link">
<span class="md-ellipsis">
index
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/merge/" class="md-nav__link">
<span class="md-ellipsis">
merge
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/filter/" class="md-nav__link">
<span class="md-ellipsis">
filter
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/select/" class="md-nav__link">
<span class="md-ellipsis">
select
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/query/" class="md-nav__link">
<span class="md-ellipsis">
query
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/dump/" class="md-nav__link">
<span class="md-ellipsis">
dump
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/annotate/" class="md-nav__link">
<span class="md-ellipsis">
annotate
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/phylo/" class="md-nav__link">
<span class="md-ellipsis">
phylo
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/unitig/" class="md-nav__link">
<span class="md-ellipsis">
unitig
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/estimate/" class="md-nav__link">
<span class="md-ellipsis">
estimate
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/convert/" class="md-nav__link">
<span class="md-ellipsis">
convert
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/utils/" class="md-nav__link">
<span class="md-ellipsis">
utils
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/pack/" class="md-nav__link">
<span class="md-ellipsis">
pack
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../usage/predicates/" class="md-nav__link">
<span class="md-ellipsis">
Predicates and taxonomy paths
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" >
<label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
<span class="md-ellipsis">
Formats
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5">
<span class="md-nav__icon md-icon"></span>
Formats
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../formats/index_layout/" class="md-nav__link">
<span class="md-ellipsis">
Index construction and on-disk layout
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../../formats/vcf/" class="md-nav__link">
<span class="md-ellipsis">
VCF pseudo-alignment
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../../../architecture/" class="md-nav__link">
<span class="md-ellipsis">
Architecture notes
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#representation-limit" class="md-nav__link">
<span class="md-ellipsis">
Representation limit
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#odd-k-mer-lengths" class="md-nav__link">
<span class="md-ellipsis">
Odd k-mer lengths
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#k-mer-specificity" class="md-nav__link">
<span class="md-ellipsis">
K-mer specificity
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#choosing-an-appropriate-k-mer-size" class="md-nav__link">
<span class="md-ellipsis">
Choosing an appropriate k-mer size
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#chance-sharing-across-genomes" class="md-nav__link">
<span class="md-ellipsis">
Chance sharing across genomes
</span>
</a>
<nav class="md-nav" aria-label="Chance sharing across genomes">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#the-null-model-and-genome-specific-probabilities" class="md-nav__link">
<span class="md-ellipsis">
The null model and genome-specific probabilities
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#computing-the-poisson-binomial-distribution" class="md-nav__link">
<span class="md-ellipsis">
Computing the Poisson-binomial distribution
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#comparing-observed-and-expected-sharing-in-the-index" class="md-nav__link">
<span class="md-ellipsis">
Comparing observed and expected sharing in the index
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#estimating-the-false-discovery-rate" class="md-nav__link">
<span class="md-ellipsis">
Estimating the false discovery rate
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#limits-of-the-model" class="md-nav__link">
<span class="md-ellipsis">
Limits of the model
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="k-mer-size">K-mer size</h1>
<p>A k-mer is a DNA sequence of length <span class="arithmatex">\(k\)</span>. obiskim is designed to index
large k-mers. Here, <em>large</em> refers to a k-mer length for which the
probability of observing the same k-mer in several genomes by chance
alone is sufficiently small. The k-mer length must therefore be large
enough that, when a k-mer is observed in several genomes of the dataset,
the probability that this shared occurrence is due to chance alone is
sufficiently low for the match to be considered evidence of homology.</p>
<p>obiskim restricts <span class="arithmatex">\(k\)</span> to odd values in the range</p>
<div class="arithmatex">\[
11 \leq k \leq 31.
\]</div>
<p>These limits result from two different considerations. The upper bound
is imposed by the representation used by obiskim, whereas the lower
bound defines a practical range of k-mer lengths for genome-scale
sequence comparisons. This range covers most practical applications: the
lower limit is well below the k-mer size that can be considered large,
even for the smallest bacterial genomes, whereas the upper limit
provides sufficient specificity for most applications, including those
involving very large genomes.</p>
<h2 id="representation-limit">Representation limit</h2>
<p>obiskim uses two bits to encode each nucleotide. Therefore, a k-mer
requires <span class="arithmatex">\(2k\)</span> bits. To ensure computational efficiency, obiskim limits
the representation of k-mers to a single 64-bit word, thereby
restricting their length.</p>
<div class="arithmatex">\[
2k \leq 64,
\]</div>
<p>This gives the hard representation limit: <span class="arithmatex">\(k \leq 32.\)</span> Furthermore,
obiskim only considers odd values of <span class="arithmatex">\(k\)</span>, meaning the largest supported
k-mer size is <span class="arithmatex">\(31\)</span>.</p>
<h2 id="odd-k-mer-lengths">Odd k-mer lengths</h2>
<p>obiskim additionally requires <span class="arithmatex">\(k\)</span> to be odd. This constraint is
independent of the specificity considerations discussed below.</p>
<p>For an odd-length DNA sequence, a k-mer cannot be identical to its own
reverse complement. Every k-mer therefore belongs to a pair of distinct
orientations, which can be represented by a single canonical k-mer. For
even <span class="arithmatex">\(k\)</span>, self-reverse-complementary sequences exist.</p>
<p>Odd <span class="arithmatex">\(k\)</span> is not required for canonicalization itself: the canonical form</p>
<div class="arithmatex">\[
s^c=\min_{\mathrm{lex}}\left(s,\operatorname{RC}(s)\right)
\]</div>
<p>is well defined for both odd and even lengths. Restricting <span class="arithmatex">\(k\)</span> to odd
values guarantees that the two orientations are always distinct,
simplifying the representation and orientation handling used by obiskim.</p>
<h2 id="k-mer-specificity">K-mer specificity</h2>
<p>A simple way to illustrate the effect of k-mer size is to consider a
random DNA sequence in which the four nucleotides are independent and
equally probable. There are <span class="arithmatex">\(4^k\)</span> possible oriented k-mers, so the
expected number of occurrences of a particular oriented k-mer in a
sequence of length <span class="arithmatex">\(G\)</span> is approximately <span class="arithmatex">\(G/4^k\)</span>. For canonical k-mers,
the corresponding number of possible sequences is halved, and the
expected number of occurrences is approximately <span class="arithmatex">\(2G/4^k\)</span>.</p>
<p>Increasing <span class="arithmatex">\(k\)</span> therefore reduces the probability that a particular k-mer
occurs by chance. However, the probability of a match somewhere in a
collection of sequences also depends on the amount of sequence searched
and on the number of possible k-mers considered. The following sections
formalize this distinction and describe how chance sharing can be
assessed across an indexed set of genomes.</p>
<h2 id="choosing-an-appropriate-k-mer-size">Choosing an appropriate k-mer size</h2>
<p>The theoretical k-mer space grows exponentially with <span class="arithmatex">\(k\)</span>. Thus, increasing <span class="arithmatex">\(k\)</span> from 11 to 31 greatly expands the sequence space and reduces the probability that unrelated sequences share a particular k-mer by chance. The following table gives the size of the theoretical k-mer space and, after canonicalization, the number of distinct representations.</p>
<table>
<thead>
<tr>
<th style="text-align: right;"><span class="arithmatex">\(k\)</span></th>
<th style="text-align: right;"><span class="arithmatex">\(4^k\)</span></th>
<th style="text-align: right;"><span class="arithmatex">\(4^k/2\)</span> after canonicalization</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: right;">11</td>
<td style="text-align: right;"><span class="arithmatex">\(4.19\times10^6\)</span></td>
<td style="text-align: right;"><span class="arithmatex">\(2.10\times10^6\)</span></td>
</tr>
<tr>
<td style="text-align: right;">15</td>
<td style="text-align: right;"><span class="arithmatex">\(1.07\times10^9\)</span></td>
<td style="text-align: right;"><span class="arithmatex">\(5.37\times10^8\)</span></td>
</tr>
<tr>
<td style="text-align: right;">21</td>
<td style="text-align: right;"><span class="arithmatex">\(4.40\times10^{12}\)</span></td>
<td style="text-align: right;"><span class="arithmatex">\(2.20\times10^{12}\)</span></td>
</tr>
<tr>
<td style="text-align: right;">25</td>
<td style="text-align: right;"><span class="arithmatex">\(1.13\times10^{15}\)</span></td>
<td style="text-align: right;"><span class="arithmatex">\(5.63\times10^{14}\)</span></td>
</tr>
<tr>
<td style="text-align: right;">31</td>
<td style="text-align: right;"><span class="arithmatex">\(4.61\times10^{18}\)</span></td>
<td style="text-align: right;"><span class="arithmatex">\(2.31\times10^{18}\)</span></td>
</tr>
</tbody>
</table>
<p>Genome sizes illustrate the range of sequence scales for which k-mers may be used. Bacterial genomes are typically a few megabases long, although some symbiotic bacteria have much smaller genomes, while other bacteria have genomes exceeding ten megabases. Plant genomes span an even wider range, from tens of megabases to more than one hundred gigabases. In very large and repeat-rich genomes, the main limitation is not necessarily the exhaustion of the theoretical k-mer space, but the non-uniform distribution of k-mers caused by sequence composition and repeated DNA.</p>
<p>The supported range <span class="arithmatex">\(11\leq k\leq31\)</span> should therefore be understood as an engineering and application-oriented compromise, not as a universal biological optimum. Shorter k-mers are more likely to be shared by unrelated regions, whereas longer k-mers provide greater sequence specificity. However, longer k-mers are also more sensitive to substitutions and indels: a single difference can disrupt an exact match across the whole k-mer. The appropriate value within the supported range consequently depends on the size and characteristics of the genomes being compared, as well as on the biological question.</p>
<p>The following section introduces a random-sequence model to quantify the probability of chance sharing across an indexed set of genomes. This provides a formal basis for assessing how the choice of <span class="arithmatex">\(k\)</span> affects the interpretation of shared k-mers.</p>
<h2 id="chance-sharing-across-genomes">Chance sharing across genomes</h2>
<p>obiskim indexes distinct canonical k-mers and records the genomes in
which each k-mer occurs. This makes it possible to compare the observed
sharing of k-mers with the sharing expected under a random-sequence
model. The same probability model can be used for two related purposes:
measuring the excess of sharing among k-mers present in the index, and
estimating the number of chance k-mers among those shared by at least a
specified number of genomes.</p>
<h3 id="the-null-model-and-genome-specific-probabilities">The null model and genome-specific probabilities</h3>
<p>The null hypothesis assumes that the <span class="arithmatex">\(S\)</span> indexed genomes are unrelated
and that each genome is an independent random sequence in which
nucleotides are independent and equiprobable.</p>
<p>Since obiskim uses odd-length canonical k-mers, reverse-complement
canonicalization reduces the number of possible k-mers by half. The size
of the canonical k-mer space is therefore</p>
<div class="arithmatex">\[
M_k=\frac{4^k}{2}.
\]</div>
<p>Let <span class="arithmatex">\(N_i\)</span> be the number of distinct canonical k-mers recorded for genome
<span class="arithmatex">\(i\)</span> in the index. Under the null model, these can be regarded as a
uniform sample without replacement from the <span class="arithmatex">\(M_k\)</span> possible canonical
k-mers. The probability that a given canonical k-mer is present in
genome <span class="arithmatex">\(i\)</span> is then</p>
<div class="arithmatex">\[
p_i=\frac{N_i}{M_k}=\frac{2N_i}{4^k}.
\]</div>
<p>This is the inclusion probability for a distinct k-mer. It differs from
the probability of at least one occurrence in a positional model,
because repeated occurrences within a genome are not counted separately.</p>
<p>Let <span class="arithmatex">\(X\)</span> denote the number of genomes, among the <span class="arithmatex">\(S\)</span> indexed genomes,
that contain a given canonical k-mer under the null model. Since genomes
are assumed to be independent, <span class="arithmatex">\(X\)</span> is a sum of independent presence
indicators with probabilities <span class="arithmatex">\(p_1,\ldots,p_S\)</span>. When these probabilities
differ, <span class="arithmatex">\(X\)</span> follows a Poisson-binomial distribution.</p>
<h3 id="computing-the-poisson-binomial-distribution">Computing the Poisson-binomial distribution</h3>
<p>The distribution of <span class="arithmatex">\(X\)</span> can be computed by processing genomes one at a
time. Let <span class="arithmatex">\(P_i(j)\)</span> denote the probability that the k-mer occurs in
exactly <span class="arithmatex">\(j\)</span> of the first <span class="arithmatex">\(i\)</span> genomes. Initially,</p>
<div class="arithmatex">\[
P_0(0)=1,\qquad P_0(j)=0 \quad (j&gt;0).
\]</div>
<p>When genome <span class="arithmatex">\(i\)</span> is added, the k-mer is either absent, with probability
<span class="arithmatex">\(1-p_i\)</span>, or present, with probability <span class="arithmatex">\(p_i\)</span>. Thus,</p>
<div class="arithmatex">\[
P_i(j)=(1-p_i)P_{i-1}(j)+p_iP_{i-1}(j-1).
\]</div>
<p>This recurrence avoids enumerating the subsets of genomes. Computing the
complete distribution requires <span class="arithmatex">\(O(S^2)\)</span> operations and <span class="arithmatex">\(O(S)\)</span> memory. To
compute the upper-tail probability, only the probabilities for fewer
than <span class="arithmatex">\(r\)</span> presences need to be tracked:</p>
<div class="arithmatex">\[
P_{\mathrm{null}}(X\geq r)=1-\sum_{j=0}^{r-1}P_S(j).
\]</div>
<p>The computation can therefore be restricted to <span class="arithmatex">\(P_i(0),\ldots,P_i(r-1)\)</span>,
requiring <span class="arithmatex">\(O(Sr)\)</span> operations and <span class="arithmatex">\(O(r)\)</span> memory. The resulting
distribution depends on the genome-specific values <span class="arithmatex">\(N_i\)</span>, but not on the
identity of the k-mer, and can thus be computed once for a given index
and k-mer length.</p>
<h3 id="comparing-observed-and-expected-sharing-in-the-index">Comparing observed and expected sharing in the index</h3>
<p>The index contains only k-mers observed in at least one genome.
Consequently, when comparing sharing proportions among the k-mers
recorded in the index, the relevant null probability is conditional on
at least one presence:</p>
<div class="arithmatex">\[
q_r=P(X\geq r\mid X\geq 1)
=\frac{P_{\mathrm{null}}(X\geq r)}{P_{\mathrm{null}}(X\geq 1)}.
\]</div>
<p>Let <span class="arithmatex">\(n_{\geq r}\)</span> be the number of distinct canonical k-mers observed in
at least <span class="arithmatex">\(r\)</span> genomes, and let <span class="arithmatex">\(n_{\geq 1}\)</span> be the total number of
distinct canonical k-mers recorded in the index. The observed proportion
of indexed k-mers shared by at least <span class="arithmatex">\(r\)</span> genomes is</p>
<div class="arithmatex">\[
O_r=\frac{n_{\geq r}}{n_{\geq 1}}.
\]</div>
<p>Under the random-sequence model, the expected proportion is <span class="arithmatex">\(q_r\)</span>. The
difference</p>
<div class="arithmatex">\[
D_r=O_r-q_r
\]</div>
<p>therefore measures the excess or deficit of sharing relative to the null
expectation. Positive values indicate that k-mers are shared across
genomes more frequently than expected by chance, whereas negative values
indicate less frequent sharing. A value of zero indicates agreement with
the random-sequence model.</p>
<p>Since both <span class="arithmatex">\(O_r\)</span> and <span class="arithmatex">\(q_r\)</span> are proportions between zero and one, <span class="arithmatex">\(D_r\)</span>
is bounded:</p>
<div class="arithmatex">\[
-1\leq D_r\leq 1.
\]</div>
<p>More precisely, for a given <span class="arithmatex">\(q_r\)</span>, its bounds are <span class="arithmatex">\(-q_r\)</span> and <span class="arithmatex">\(1-q_r\)</span>. By
construction, <span class="arithmatex">\(D_1=0\)</span>, since all k-mers recorded in the index occur in
at least one genome. Unlike a ratio-based measure, this difference
remains defined when no k-mers are observed in at least <span class="arithmatex">\(r\)</span> genomes.</p>
<h3 id="estimating-the-false-discovery-rate">Estimating the false discovery rate</h3>
<p>The probability <span class="arithmatex">\(P_{\mathrm{null}}(X\geq r)\)</span> applies to one specified canonical k-mer.
To estimate the number of k-mers that could reach this sharing threshold
by chance across the entire canonical k-mer space, this probability must
be considered over all <span class="arithmatex">\(M_k\)</span> possible canonical k-mers.</p>
<p>The expected number of chance k-mers present in at least <span class="arithmatex">\(r\)</span> genomes is</p>
<div class="arithmatex">\[
E[\mathrm{FP}(r)]=M_kP_{\mathrm{null}}(X\geq r).
\]</div>
<p>The observed number of k-mers passing the threshold is <span class="arithmatex">\(n_{\geq r}\)</span>. An
estimate of the false discovery rate (FDR) for this set is therefore</p>
<div class="arithmatex">\[
\widehat{\mathrm{FDR}}(r)=
\begin{cases}
1 &amp; \text{if } n_{\geq r}=0,\\[4pt]
\displaystyle
\min\left(1,
\frac{M_k P_{\mathrm{null}}(X\geq r)}
{n_{\geq r}}\right)
&amp; \text{otherwise}.
\end{cases}
\]</div>
<p>The numerator estimates the number of false positives under the null
model, while the denominator is the observed number of k-mers passing
the sharing threshold. This estimate assumes that all possible canonical
k-mers are subject to the null model. It is therefore conservative in
the sense that it does not attempt to estimate the proportion of the
k-mer space corresponding to true homology. The estimate is capped at
one because a proportion cannot exceed one.</p>
<p>The distinction between <span class="arithmatex">\(D_r\)</span> and the FDR is important. <span class="arithmatex">\(D_r\)</span> compares
the observed and expected proportions among k-mers already present in
the index. The FDR estimate instead compares the expected number of
chance k-mers in the entire canonical k-mer space with the observed
number passing the sharing threshold.</p>
<p>The smallest value of <span class="arithmatex">\(r\)</span> for which <span class="arithmatex">\(\widehat{\mathrm{FDR}}(r)\)</span> falls
below a chosen threshold, for example 5%, can be used as a minimum
sharing threshold. This interpretation is conditional on the assumptions
of the null model and should not be taken as a model-independent
guarantee of the biological false discovery rate.</p>
<p>As an illustration, consider <span class="arithmatex">\(k=21\)</span>, for which
<span class="arithmatex">\(M_k\simeq2.2\times10^{12}\)</span>, and an index containing <span class="arithmatex">\(S=10\)</span> genomes.
Suppose that the numbers of distinct canonical k-mers in these genomes
range from <span class="arithmatex">\(0.5\times10^9\)</span> to <span class="arithmatex">\(1.4\times10^9\)</span>, in increments of
<span class="arithmatex">\(0.1\times10^9\)</span>. Applying the Poisson-binomial model with the
corresponding genome-specific probabilities gives the following
expected numbers of k-mers shared by chance:</p>
<table>
<thead>
<tr>
<th style="text-align: right;"><span class="arithmatex">\(r\)</span></th>
<th style="text-align: right;"><span class="arithmatex">\(M_kP_{\mathrm{null}}(X\geq r)\)</span></th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: right;">2</td>
<td style="text-align: right;"><span class="arithmatex">\(1.82\times10^7\)</span></td>
</tr>
<tr>
<td style="text-align: right;">3</td>
<td style="text-align: right;"><span class="arithmatex">\(2.06\times10^4\)</span></td>
</tr>
<tr>
<td style="text-align: right;">4</td>
<td style="text-align: right;"><span class="arithmatex">\(15\)</span></td>
</tr>
<tr>
<td style="text-align: right;">5</td>
<td style="text-align: right;"><span class="arithmatex">\(0.0075\)</span></td>
</tr>
</tbody>
</table>
<p>In this example, chance alone can produce many pairwise shared 21-mers,
whereas the expected number of k-mers shared by five or more genomes is
very small. Whether a given sharing threshold is sufficiently stringent
depends on the number of k-mers actually observed at that level.</p>
<h3 id="limits-of-the-model">Limits of the model</h3>
<p>The FDR estimate is based on a simplified null model and has two
important limitations.</p>
<p>First, the model assumes independent, equiprobable nucleotides. Real
genomes exhibit nucleotide-composition biases, oligonucleotide
dependencies, and repeated sequences. These properties can increase the
probability of particular k-mers beyond the uniform expectation.
Removing low-complexity k-mers reduces some of these effects but does
not eliminate all compositional biases. Karlin and colleagues showed
that relative oligonucleotide abundances, including dinucleotide
frequencies, form characteristic genomic signatures that can differ
between organisms and remain relatively stable within genomes
(Karlin <em>et al.</em> 1994; Karlin &amp; Burge 1995)<sup id="fnref:Karlin1995-lt"><a class="footnote-ref" href="#fn:Karlin1995-lt">1</a></sup> <sup id="fnref:Karlin1994-on"><a class="footnote-ref" href="#fn:Karlin1994-on">2</a></sup>.</p>
<p>Second, the FDR is computed per k-mer. Consecutive k-mers extracted from
the same homologous region overlap and are therefore not independent
observations. A single homologous region can contribute many correlated
k-mers to the index. The estimate presented here consequently describes
the expected fraction of chance k-mers, not the fraction of false
homologous regions. A region-level FDR would require a model that treats
matching regions, rather than individual k-mers, as the units of
observation.</p>
<div class="footnote">
<hr />
<ol>
<li id="fn:Karlin1995-lt">
<p>Karlin S, Burge C (1995) <a href="https://doi.org/10.1016/s0168-9525(00)89076-9">[Dinucleotide relative abundance extremes: a genomic signature]{.nocase}</a>. <em>Trends in Genetics: TIG</em>, <strong>11</strong>, 283--290.&#160;<a class="footnote-backref" href="#fnref:Karlin1995-lt" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
<li id="fn:Karlin1994-on">
<p>Karlin S, Ladunga I, Blaisdell BE (1994) <a href="https://doi.org/10.1073/pnas.91.26.12837">[Heterogeneity of genomes: measures and values]{.nocase}</a>. <em>Proceedings of the National Academy of Sciences of the United States of America</em>, <strong>91</strong>, 12837--12841.&#160;<a class="footnote-backref" href="#fnref:Karlin1994-on" title="Jump back to footnote 2 in the text">&#8617;</a></p>
</li>
</ol>
</div>
</article>
</div>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"annotate": null, "base": "../../..", "features": [], "search": "../../../assets/javascripts/workers/search.2c215733.min.js", "tags": null, "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": null}</script>
<script src="../../../assets/javascripts/bundle.79ae519e.min.js"></script>
<script src="https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js"></script>
</body>
</html>