Files
obiskim/DevDoc/implementation/merge/index.html
T
Eric Coissac f1b4b4ebda docs: rename project to obiskim and expand documentation
Rename the project from "obikmer" to "obiskim" across all documentation, user guides, and developer notes. Add extensive new theoretical and implementation documentation covering chance sharing, sibling partition unification, pair-coverage sampling, MPHF batch queries, merge scaling, and hot resume/memoization. Update navigation structures to reflect these new topics and the new project name.

- Rename "obikmer" to "obiskim" in all HTML titles, headers, navigation labels, and code examples across `DevDoc/` and `doc/` directories.
- Add new navigation links for "Chance sharing across genomes", "Sibling partition unification", "Pair-coverage-biased family sampling", "MPHF batch queries", "Merge mmap audit", "Merge scaling", and "Hot resume and memoization" throughout the documentation site.
- Move `DevDoc/architecture/numa_worker_pools/index.html` to `DevDoc/architecture/hot_resume_memoization/index.html` and update content to focus on hot resume and memoization strategies.
- Move `DevDoc/implementation/evidence_elimination/index.html` to `DevDoc/implementation/merge_mmap_audit/index.html` and update content to detail merge mmap audit findings and plans.
- Move `DevDoc/implementation/superkmer.refs/index.html` to `DevDoc/implementation/merge_scaling/index.html` and update content to discuss merge scaling costs and dependencies.
- Move `DevDoc/theory/indexing/index.html` to `DevDoc/theory/chance_sharing/index.html` and rewrite content to discuss chance sharing across genomes and null models.
- Move `DevDoc/theory/minimizer/index.html` to `DevDoc/theory/sibling_partition_unification/index.html` and update content to discuss sibling partition unification and Can3 masked canonical form.
- Add new `DevDoc/implementation/mphf_batch_queries/index.html` documenting MPHF batch query performance and inventory.
- Add new `DevDoc/theory/pair_coverage_sampling/index.html` documenting pair-coverage-biased family sampling theory and diagnostics.
- Update `DevDoc/architecture/query/index.html` to describe `by_partition` using `Vec<PartitionKmers>` instead of `HashMap` for reduced memory usage.
- Update `DevDoc/implementation/merge/index.html` to describe bootstrap output logic selecting base source by largest `unitigs.bin` size and using `MatrixBuilder::resume`.
- Update `DevDoc/implementation/unitig_evidence/index.html` to change `MAX_KMERS_PER_CHUNK` from 256 to 128 and update rank field documentation.
- Update `DevDoc/implementation/obipipeline/index.html` to reflect that `obiskim` uses `make_pipe!` and `.apply()` instead of `make_pipeline!` / `WorkerPool`.
- Update `DevDoc/implementation/filtering/index.html` to change `FilterArgs` inheritance to `obiskim::cmd::predicate::FilterArgs`.
- Update `DevDoc/implementation/partition_layer_cache/index.html` to reflect new crate dependency structure requiring external reachability for algorithm implementation traits.
- Update `doc/formats/index_layout/index.html` to describe new directory structure for index files including `part_NNNNN/index/layer_X/` and updated merging/packing logic.
- Update `doc/formats/vcf/index.html` to use `obiskim` prefixes for contigs and update VCF header source.
- Update `doc/usage/estimate/index.html` to add "Comparing an index with random sharing" section and clarify `--index` and `--presence-threshold` options.
- Update `doc/usage/phylo/index.html` to clarify that running `obiskim phylo` twice draws independent samples and update `--sibling-annex` behavior.
- Update `doc/usage/select/index.html` to clarify that `select` always writes to a new output directory and explains hard-linking mechanism.
- Add new BibTeX entries for Karlin et al. and Bennett et al. in `doc/references.bib`.
- Delete `scripts/smoke_test_index2.sh` which contained end-to-end smoke tests for `obikmer2 index` and `obikmer query`.
- Update `src/Cargo.lock` to bump "obiskim" package dependency from 1.4.8 to 1.4.9.
2026-12-02 16:12:54 +01:00

2073 lines
46 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="../persistent_bit_vec/">
<link rel="next" href="../merge_parallelism/">
<link rel="icon" href="../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.7.6">
<title>Merge command - obiskim</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="#merge-command" 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" class="md-header__button md-logo" aria-label="obiskim" 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
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Merge command
</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" class="md-nav__button md-logo" aria-label="obiskim" 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
</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--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
<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="false">
<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">
<a href="../../kmers/" class="md-nav__link">
<span class="md-ellipsis">
Kmers and super-kmers
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/encoding/" class="md-nav__link">
<span class="md-ellipsis">
DNA encoding
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/entropy/" class="md-nav__link">
<span class="md-ellipsis">
Entropy filter
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/minimizer/" class="md-nav__link">
<span class="md-ellipsis">
Minimizer selection
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/indexing/" class="md-nav__link">
<span class="md-ellipsis">
Partitioning architecture
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/chance_sharing/" class="md-nav__link">
<span class="md-ellipsis">
Chance sharing across genomes (discussion)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/evolutionary_distances/" class="md-nav__link">
<span class="md-ellipsis">
Central-position SNP distance (discussion)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/sibling_partition_unification/" class="md-nav__link">
<span class="md-ellipsis">
Sibling partition unification (discussion)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/pair_coverage_sampling/" class="md-nav__link">
<span class="md-ellipsis">
Pair-coverage-biased family sampling (discussion)
</span>
</a>
</li>
</ul>
</nav>
</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_4" checked>
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
<span class="md-ellipsis">
Implementation
</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="true">
<label class="md-nav__title" for="__nav_4">
<span class="md-nav__icon md-icon"></span>
Implementation
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../superkmer/" class="md-nav__link">
<span class="md-ellipsis">
SuperKmer
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../kmer/" class="md-nav__link">
<span class="md-ellipsis">
Kmer
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../chunkreader/" class="md-nav__link">
<span class="md-ellipsis">
Chunk reader
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../pipeline/" class="md-nav__link">
<span class="md-ellipsis">
Construction pipeline
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../obipipeline/" class="md-nav__link">
<span class="md-ellipsis">
obipipeline library
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../storage/" class="md-nav__link">
<span class="md-ellipsis">
On-disk storage
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../mphf/" class="md-nav__link">
<span class="md-ellipsis">
MPHF selection
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../mphf_batch_queries/" class="md-nav__link">
<span class="md-ellipsis">
MPHF batch queries (inventory)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../unitig_evidence/" class="md-nav__link">
<span class="md-ellipsis">
Unitig evidence encoding
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../evidence_elimination/" class="md-nav__link">
<span class="md-ellipsis">
Evidence elimination (discussion)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../layer_tier/" class="md-nav__link">
<span class="md-ellipsis">
obikindex layer tier
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../persistent_compact_int_vec/" class="md-nav__link">
<span class="md-ellipsis">
PersistentCompactIntVec
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../persistent_bit_vec/" class="md-nav__link">
<span class="md-ellipsis">
PersistentBitVec
</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">
Merge command
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Merge command
</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="#purpose" class="md-nav__link">
<span class="md-ellipsis">
Purpose
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#modes" class="md-nav__link">
<span class="md-ellipsis">
Modes
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#input-output-constraints" class="md-nav__link">
<span class="md-ellipsis">
Input / output constraints
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#evidence-compatibility" class="md-nav__link">
<span class="md-ellipsis">
Evidence compatibility
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#genome-label-deduplication" class="md-nav__link">
<span class="md-ellipsis">
Genome label deduplication
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#algorithm" class="md-nav__link">
<span class="md-ellipsis">
Algorithm
</span>
</a>
<nav class="md-nav" aria-label="Algorithm">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#1-validation" class="md-nav__link">
<span class="md-ellipsis">
1. Validation
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#2-bootstrap-output-from-the-base-source" class="md-nav__link">
<span class="md-ellipsis">
2. Bootstrap output from the base source
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#3-for-each-subsequent-source-parallel-across-partitions" class="md-nav__link">
<span class="md-ellipsis">
3. For each subsequent source (parallel across partitions)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#4-update-index-metadata" class="md-nav__link">
<span class="md-ellipsis">
4. Update index metadata
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#append_genome_column" class="md-nav__link">
<span class="md-ellipsis">
append_genome_column
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#column-count-invariant" class="md-nav__link">
<span class="md-ellipsis">
Column count invariant
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#error-variants-relevant-to-merge" class="md-nav__link">
<span class="md-ellipsis">
Error variants relevant to merge
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#on-disk-impact" class="md-nav__link">
<span class="md-ellipsis">
On-disk impact
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#known-issue-not-yet-fixed-2026-08-28" class="md-nav__link">
<span class="md-ellipsis">
Known issue (not yet fixed, 2026-08-28)
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../merge_parallelism/" class="md-nav__link">
<span class="md-ellipsis">
Merge parallelism & memory
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../merge_mmap_audit/" class="md-nav__link">
<span class="md-ellipsis">
Merge mmap audit (2026-11)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../merge_scaling/" class="md-nav__link">
<span class="md-ellipsis">
Merge scaling (open)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../filtering/" class="md-nav__link">
<span class="md-ellipsis">
Kmer filtering
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../select/" class="md-nav__link">
<span class="md-ellipsis">
Select command
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../obitaxonomy/" class="md-nav__link">
<span class="md-ellipsis">
obitaxonomy crate
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../benchmark_query_testing/" class="md-nav__link">
<span class="md-ellipsis">
Benchmark: query-path testing
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../partition_layer_cache/" class="md-nav__link">
<span class="md-ellipsis">
Partition and layer caching (discussion)
</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">
Architecture
</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>
Architecture
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../architecture/sequences/invariant/" class="md-nav__link">
<span class="md-ellipsis">
Sequences
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../architecture/index_architecture/" class="md-nav__link">
<span class="md-ellipsis">
Kmer index
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../architecture/siblings/" class="md-nav__link">
<span class="md-ellipsis">
Sibling annex
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../architecture/hot_resume_memoization/" class="md-nav__link">
<span class="md-ellipsis">
Hot resume and memoization
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../architecture/numa_worker_pools/" class="md-nav__link">
<span class="md-ellipsis">
NUMA-aware worker pools
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../architecture/numa_partition_runner/" class="md-nav__link">
<span class="md-ellipsis">
NUMA-aware partition runner
</span>
</a>
</li>
</ul>
</nav>
</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="#purpose" class="md-nav__link">
<span class="md-ellipsis">
Purpose
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#modes" class="md-nav__link">
<span class="md-ellipsis">
Modes
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#input-output-constraints" class="md-nav__link">
<span class="md-ellipsis">
Input / output constraints
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#evidence-compatibility" class="md-nav__link">
<span class="md-ellipsis">
Evidence compatibility
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#genome-label-deduplication" class="md-nav__link">
<span class="md-ellipsis">
Genome label deduplication
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#algorithm" class="md-nav__link">
<span class="md-ellipsis">
Algorithm
</span>
</a>
<nav class="md-nav" aria-label="Algorithm">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#1-validation" class="md-nav__link">
<span class="md-ellipsis">
1. Validation
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#2-bootstrap-output-from-the-base-source" class="md-nav__link">
<span class="md-ellipsis">
2. Bootstrap output from the base source
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#3-for-each-subsequent-source-parallel-across-partitions" class="md-nav__link">
<span class="md-ellipsis">
3. For each subsequent source (parallel across partitions)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#4-update-index-metadata" class="md-nav__link">
<span class="md-ellipsis">
4. Update index metadata
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#append_genome_column" class="md-nav__link">
<span class="md-ellipsis">
append_genome_column
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#column-count-invariant" class="md-nav__link">
<span class="md-ellipsis">
Column count invariant
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#error-variants-relevant-to-merge" class="md-nav__link">
<span class="md-ellipsis">
Error variants relevant to merge
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#on-disk-impact" class="md-nav__link">
<span class="md-ellipsis">
On-disk impact
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#known-issue-not-yet-fixed-2026-08-28" class="md-nav__link">
<span class="md-ellipsis">
Known issue (not yet fixed, 2026-08-28)
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="merge-command">Merge command</h1>
<h2 id="purpose">Purpose</h2>
<p><code>obiskim merge</code> combines multiple existing kmer indexes into a single index. The result contains all kmers from all sources, with per-genome presence/absence or count data for every genome across every layer.</p>
<hr />
<h2 id="modes">Modes</h2>
<div class="highlight"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">enum</span><span class="w"> </span><span class="nc">MergeMode</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">Presence</span><span class="p">,</span><span class="w"> </span><span class="n">Count</span><span class="w"> </span><span class="p">}</span>
</code></pre></div>
<p>Default mode is <code>Presence</code>. <code>Count</code> mode requires <strong>all</strong> source indexes to have <code>with_counts=true</code>; mixing count and non-count sources is rejected at validation.</p>
<table>
<thead>
<tr>
<th>Mode</th>
<th>Column type</th>
<th>Constraint</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Presence</code></td>
<td><code>PersistentBitMatrix</code> (one bit per genome per slot)</td>
<td>none</td>
</tr>
<tr>
<td><code>Count</code></td>
<td><code>PersistentCompactIntMatrix</code> (one u32 per genome per slot)</td>
<td>all sources <code>with_counts=true</code></td>
</tr>
</tbody>
</table>
<hr />
<h2 id="input-output-constraints">Input / output constraints</h2>
<p>All source indexes must satisfy:</p>
<ul>
<li><code>IndexState::Indexed</code> (fully built — <code>index.done</code> sentinel present)</li>
<li>Same <code>kmer_size</code>, <code>minimizer_size</code>, <code>n_partitions</code></li>
<li>Same evidence kind: all <code>Exact</code>, or all <code>Approx</code> with identical <code>(b, z)</code> parameters</li>
<li>If <code>Count</code> mode: all sources must have <code>with_counts=true</code></li>
</ul>
<p><code>--force</code>: if the output directory already exists, it is deleted before the merge begins.</p>
<hr />
<h2 id="evidence-compatibility">Evidence compatibility</h2>
<p><code>validate_evidence_compat(sources)</code> is called before any I/O. It compares each source's <code>EvidenceKind</code> against <code>sources[0]</code>:</p>
<ul>
<li>All <code>Exact</code> → accepted, output uses <code>Exact</code></li>
<li>All <code>Approx { b, z }</code> with same <code>(b, z)</code> → accepted, output uses those parameters</li>
<li>Any other combination → <code>OKIError::IncompatibleEvidence</code>, with a message directing the user to run <code>reindex</code> first</li>
</ul>
<p>Mixed exact/approx is a hard error, not a silent conversion.</p>
<div class="highlight"><pre><span></span><code><span class="k">fn</span><span class="w"> </span><span class="nf">validate_evidence_compat</span><span class="p">(</span><span class="n">sources</span><span class="p">:</span><span class="w"> </span><span class="kp">&amp;</span><span class="p">[</span><span class="o">&amp;</span><span class="n">KmerIndex</span><span class="p">])</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="nc">OKIResult</span><span class="o">&lt;</span><span class="n">EvidenceKind</span><span class="o">&gt;</span>
</code></pre></div>
<hr />
<h2 id="genome-label-deduplication">Genome label deduplication</h2>
<p><code>compute_labels(sources, rename_duplicates)</code> assigns final genome labels across all sources before any file is written. The first occurrence of a label keeps the original name. Subsequent occurrences receive <code>.1</code>, <code>.2</code>, … suffixes when <code>rename_duplicates</code> is true, or trigger <code>OKIError::DuplicateGenomeLabel</code> otherwise.</p>
<hr />
<h2 id="algorithm">Algorithm</h2>
<h3 id="1-validation">1. Validation</h3>
<p>Check all sources against the constraints above. Abort on any mismatch.</p>
<h3 id="2-bootstrap-output-from-the-base-source">2. Bootstrap output from the base source</h3>
<p>The base is chosen by <code>choose_base</code> (<code>merge.rs</code>): the source with the largest total <code>unitigs.bin</code> size (restricted to approximate-evidence sources when the output must be approximate). It is not necessarily <code>sources[0]</code>, and the genome columns follow the base first. Because <code>obiskim index</code> is not byte-reproducible (unitig segmentation varies), two near-equal sources can swap roles between runs. Its directory is copied to <code>output</code> (hard links for files <code>merge_partition</code> never rewrites, see below). Immediately after the copy:</p>
<ul>
<li><code>index.meta</code> is rewritten with the final genome list (all sources, possibly renamed) and the effective evidence kind.</li>
<li>In <code>Presence</code> mode, any <code>counts/</code> directories inherited from source_0 are removed.</li>
<li><code>spectrums/</code> from source_0 is removed and rebuilt from scratch across all sources, applying the (possibly renamed) labels.</li>
</ul>
<p>This establishes the partition layout, all existing MPHFs, unitigs, and evidence files. The base source's genomes occupy columns 0 … <code>n_dst_genomes - 1</code> in the destination.</p>
<h3 id="3-for-each-subsequent-source-parallel-across-partitions">3. For each subsequent source (parallel across partitions)</h3>
<p><code>obikmerge::partition_merge::merge_partition(dst, i, sources, mode, n_dst_genomes, block_bits, evidence)</code> runs once per partition index <code>i</code> (scheduled largest first by <code>PartitionRunner</code>). Each entry of <code>sources</code> is <code>(&amp;KmerIndex, n_genomes)</code>, where <code>n_genomes</code> is the number of columns that source contributes (&gt; 1 for an already-merged source). Code: <code>partition_merge/mod.rs</code> (orchestration, pass 1) and <code>partition_merge/pass2.rs</code> (per-group fill pipeline).</p>
<p><strong>First merge, Presence mode</strong>: when <code>n_dst_genomes == 1</code>, <code>TypedLayer::&lt;()&gt;::init_presence_matrix</code> is called on every existing dst layer first. It materialises the implicit single-genome matrix (<code>presence/col_000000.pbiv</code>, all true) so that source columns can be appended to it.</p>
<p>The dst layers are opened once per partition and shared by both passes.</p>
<p><strong>Pass 1 — new k-mers into a de Bruijn graph.</strong> Only the sources' <code>unitigs.bin</code> <em>paths</em> are needed (<code>KmerLayer::new(..).unitigs_path()</code>); no source layer is opened. The files are streamed (at most <code>max_open = 2</code> open at once), and every k-mer absent from all dst layers is pushed into one <code>GraphDeBruijn</code>. All new k-mers of all sources go into a <strong>single</strong> new layer per merge, built by <code>materialize_layer</code> (unitigs + MPHF + evidence).</p>
<p><strong>New-layer matrix.</strong> If a new layer exists, its matrix is created with <code>n_dst_genomes</code> absent columns (all zero/false) and closed immediately. This keeps the column-count invariant, and every source group then appends to it like to the existing layers.</p>
<p><strong>Pass 2 — by consecutive groups of <code>SRC_GROUP = 2</code> sources, in source order.</strong> Per group:</p>
<ol>
<li>open the group's source layers for this partition;</li>
<li><code>MatrixBuilder::resume</code> every dst matrix (existing layers + new layer), check <code>n_cols == n_dst_genomes + col_base</code>, append the group's <code>group_n</code> columns;</li>
<li>run the pipeline: stream each source layer's k-mers, <code>hash_batch</code> + <code>fill_sub_matrix</code> on the source, locate each k-mer in the dst layers (<code>find_batch_grouped</code>) or else in the new layer's MPHF, and write the values column-major into the group's builders;</li>
<li>close the columns, then the matrices; drop the group's layers; <code>col_base += group_n</code>.</li>
</ol>
<p>Only one group's source layers and destination columns are alive at a time, so the number of live mappings per partition does not depend on the number of sources. Columns are appended in source order, so every genome lands in the same absolute column as in a single-session merge.</p>
<p><strong>In-memory columns.</strong> The group's columns are built in RAM (<code>MatrixBuilder::add_mem_col</code> → <code>MemBitVecBuilder</code> / <code>MemCompactIntVecBuilder</code>) and written once, sequentially, at <code>close</code> (<code>.building</code> file, then <code>rename</code>). The files are byte-identical to the former mmap-backed builders' output. There is no sparse file and no <code>MmapMut</code> on this path, so a block the FS cannot allocate is an <code>io::Error</code> instead of a SIGBUS. Files are not <code>fsync</code>ed: one sync per column file made merge ~8× slower. RAM per partition is at most <code>SRC_GROUP × src_n × N_part × (1/8 | 1)</code> bytes (presence | counts). History and figures: <code>merge_mmap_audit.md</code>; scaling limits: <code>merge_scaling.md</code>.</p>
<h3 id="4-update-index-metadata">4. Update index metadata</h3>
<p><code>index.meta</code> was already written during bootstrap with the complete genome list and evidence kind. No further update is needed after the partition loop.</p>
<hr />
<h2 id="append_genome_column"><code>append_genome_column</code></h2>
<p>Defined on two concrete specialisations of <code>Layer&lt;D&gt;</code>:</p>
<div class="highlight"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="n">Layer</span><span class="o">&lt;</span><span class="n">PersistentCompactIntMatrix</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="nf">append_genome_column</span><span class="p">(</span><span class="n">layer_dir</span><span class="p">:</span><span class="w"> </span><span class="kp">&amp;</span><span class="nc">Path</span><span class="p">,</span><span class="w"> </span><span class="n">value_of</span><span class="p">:</span><span class="w"> </span><span class="nc">impl</span><span class="w"> </span><span class="nb">Fn</span><span class="p">(</span><span class="kt">usize</span><span class="p">)</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="kt">u32</span><span class="p">)</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="nc">OLMResult</span><span class="o">&lt;</span><span class="p">()</span><span class="o">&gt;</span>
<span class="p">}</span>
<span class="k">impl</span><span class="w"> </span><span class="n">Layer</span><span class="o">&lt;</span><span class="n">PersistentBitMatrix</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="nf">append_genome_column</span><span class="p">(</span><span class="n">layer_dir</span><span class="p">:</span><span class="w"> </span><span class="kp">&amp;</span><span class="nc">Path</span><span class="p">,</span><span class="w"> </span><span class="n">value_of</span><span class="p">:</span><span class="w"> </span><span class="nc">impl</span><span class="w"> </span><span class="nb">Fn</span><span class="p">(</span><span class="kt">usize</span><span class="p">)</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="kt">bool</span><span class="p">)</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="nc">OLMResult</span><span class="o">&lt;</span><span class="p">()</span><span class="o">&gt;</span>
<span class="p">}</span>
</code></pre></div>
<p>Each appends one column file to the matrix subdirectory (<code>counts/</code> or <code>presence/</code>). In <code>merge_partition</code>, columns are written through <code>MatrixBuilder::add_mem_col</code> (in-memory builders) rather than through these helpers, but the invariant they enforce is the same.</p>
<hr />
<h2 id="column-count-invariant">Column count invariant</h2>
<p>After any merge, <strong>every layer in every partition has exactly <code>n_genomes</code> columns</strong>, where <code>n_genomes</code> is the total genome count in the index at that point.</p>
<p>Maintained by three mechanisms:</p>
<ol>
<li><strong>Existing layers</strong>: <code>n_src_total</code> columns appended (one per source genome), group by group.</li>
<li><strong>New layers created during merge</strong>: <code>n_dst_genomes</code> absent columns prepended before source columns.</li>
<li><strong>First merge, Presence mode</strong>: <code>init_presence_matrix</code> retroactively creates <code>presence/col_0</code> all-true for genome 0.</li>
</ol>
<p>The invariant is a precondition of <code>LayeredStore</code> aggregation traits: <code>col_weights()</code> and all partial distance methods assume every inner store has the same column count.</p>
<hr />
<h2 id="error-variants-relevant-to-merge">Error variants relevant to merge</h2>
<table>
<thead>
<tr>
<th>Variant</th>
<th>Condition</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>OKIError::NotIndexed(path)</code></td>
<td>Source not in <code>Indexed</code> state</td>
</tr>
<tr>
<td><code>OKIError::IncompatibleConfig</code></td>
<td>Mismatched <code>kmer_size</code>, <code>minimizer_size</code>, or <code>n_partitions</code></td>
</tr>
<tr>
<td><code>OKIError::MismatchedMode</code></td>
<td>Count mode but a source has <code>with_counts=false</code></td>
</tr>
<tr>
<td><code>OKIError::IncompatibleEvidence(msg)</code></td>
<td>Mixed exact/approx or different approx <code>(b, z)</code></td>
</tr>
<tr>
<td><code>OKIError::DuplicateGenomeLabel(label)</code></td>
<td>Duplicate label and <code>rename_duplicates=false</code></td>
</tr>
</tbody>
</table>
<hr />
<h2 id="on-disk-impact">On-disk impact</h2>
<p>After merging <code>G</code> genomes (sources_0 contributes <code>G0</code>, subsequent sources the rest), <em>before</em> <code>finalize</code> packs each matrix (sparse by default, <code>matrix.pbmx</code> with <code>--dense</code>):</p>
<div class="highlight"><pre><span></span><code>partitions/
part_00000/
index/
meta.json ← n_layers updated if new layer added
layer_0/
mphf.bin ← unchanged
unitigs.bin ← unchanged
evidence.bin ← unchanged
presence/ ← created on first merge (Presence mode)
meta.json {&quot;n&quot;: N, &quot;n_cols&quot;: G}
col_000000.pbiv ← all-true (genome 0 … G0-1)
col_000001.pbiv ← next source
...
counts/ ← extended (Count mode)
meta.json {&quot;n&quot;: N, &quot;n_cols&quot;: G}
col_000000.pciv ← genome 0 counts (from original build)
col_000001.pciv ← next source
...
layer_N/ ← new layer (if new kmers found)
mphf.bin
unitigs.bin
evidence.bin
presence/ or counts/
meta.json {&quot;n&quot;: N1, &quot;n_cols&quot;: G}
col_000000.pbiv ← all-false (absent for existing genomes)
...
spectrums/
&lt;label&gt;.json ← one file per genome, rebuilt from all sources
index.meta ← complete genome list + evidence kind written at bootstrap
</code></pre></div>
<p><code>mphf.bin</code>/<code>unitigs.bin</code>/<code>evidence.bin</code>/<code>unitigs.bin.idx</code>/<code>fingerprint.bin</code>/<code>layer_meta.json</code> marked "unchanged" above are hard-linked from the base source's own files during the bootstrap copy (2026-08-28), not copied — <code>merge_partition</code> never rewrites them for pre-existing layers, only the <code>presence</code>/<code>counts</code> subdirectory gets widened in place, so only that subdirectory is a real, independent copy. Falls back to a real copy per file if linking itself fails (different filesystems). Verified: source files are byte-identical (checksummed) before/after a normal merge.</p>
<h2 id="known-issue-not-yet-fixed-2026-08-28">Known issue (not yet fixed, 2026-08-28)</h2>
<p>Merging an index against itself — literally the same directory passed twice as separate source arguments (e.g. <code>obiskim merge -o out IDX IDX --rename-duplicates</code>) — panics deep in the MPHF's rank-select structure (<code>common_traits::select_in_word</code>, <code>assertion failed: rank &lt; self.count_ones()</code>), inside <code>MphfLayer::find</code> called from <code>merge_partition</code>'s "is this source kmer already in dst" check against the bootstrap-copied <code>dst_layers</code>. Root cause not identified; ruled out so far:</p>
<ul>
<li><strong>Not an empty-new-layer issue</strong>: a source contributing zero new kmers (verified both as the sole additional source and as a third, fully-redundant source in a 3-way merge) is handled correctly — no layer is created for it, no crash, exit 0.</li>
<li><strong>Not caused by the hard-link change above</strong>: verified via checksum that a normal (two distinct sources) merge leaves every source file byte-identical.</li>
</ul>
<p>Only reproduces when <code>sources[0]</code> and <code>sources[1]</code> are the exact same on-disk path opened as two independent <code>KmerIndex</code> handles — an artificial scenario (nobody merges an index with itself intentionally), deprioritized rather than investigated further for now. Does terminate cleanly rather than hang, since <code>PartitionRunner</code>'s panic propagation fix (see <code>architecture/numa_partition_runner.md</code>) now surfaces it as a normal process panic/exit 101 instead of a silent deadlock.</p>
</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>