Add per-family Shannon entropy calculation and reporting

Introduces an entropy.pent persisted format and algorithms to compute per-family Shannon entropy across genomic partitions. Refactors IndexCache to use Arc-based layer sharing for efficient iteration and restructures the siblings module with extension traits for annex generation. Adds a --shannon CLI flag to export partition-level entropy metrics to CSV.
This commit is contained in:
Eric Coissac committed 2026-08-28 20:45:47 +02:00
1 parent bbb58a698f
commit 5a0b71d105
14 files changed
+762 -136

No files matched your search

+28 -7
View File
@@ -1,13 +1,34 @@
//! Sibling-annex construction algorithm: the cross-partition sweep that
//! fills in one layer's [`crate::siblings::FamilyMask`] slots — driven, one
//! layer at a time, by
//! [`crate::siblings::extensions::SiblingExt`]. Kept apart from
//! that trait (and from the `siblingannex`/`helpers` data model) the same
//! way `obikindexer` splits `algorithms` from `extensions`: this module
//! depends on the data model, never the reverse.
//! Sibling-annex construction algorithms — driven, one layer (or one
//! partition/layer sweep) at a time, by the traits in
//! [`crate::siblings::extensions`]. Kept apart from those traits (and from
//! the `siblingannex`/`entropy_annex`/`helpers` data model) the same way
//! `obikindexer` splits `algorithms` from `extensions`: this module depends
//! on the data model, never the reverse.
//!
//! [`annex`] builds the sibling-count/minorant annex itself; [`family_scan`]
//! is the shared cross-partition traversal every other consumer
//! (`entropy`, and future ones — cardinality, alignment, stats) is built
//! on; [`minorant_selection`] and [`entropy`] are the first such consumer.
mod annex;
mod entropy;
mod family_scan;
mod minorant_selection;
use obikidxcache::index_cache::IndexCache;
pub(crate) use annex::build_layer_sibling_annex;
pub(crate) use entropy::{ensure_layer_entropy_annex, family_entropy, family_entropy_4};
pub(crate) use family_scan::{Selection, scan_layer_families};
/// Whether every layer number in `cache` fits in a `FamilyMask` field
/// (`< 7`) — a single fact about the whole index, decided once here so
/// every writer/reader of a per-layer `FamilyMask` field agrees. Layer
/// count is guaranteed identical across every partition (a merge adds one
/// layer to all of them at once), so the max over cached partitions speaks
/// for the whole index. Shared by every `extensions` impl that writes or
/// interprets that field (`SiblingExt::build_sibling_annex`,
/// `SiblingBuilder::ensure_entropy_annexes`), so they can never disagree.
pub(crate) fn is_fast_mode(cache: &IndexCache) -> bool {
cache.partitions().filter_map(|p| cache.n_layer(p)).max().unwrap_or(0) <= 7
}