Introduces complex sampling mechanisms including quartet filtering, pair balance weighting, and entropy bias. Enforces the `--no-ambiguity` convention for family counting and updates annex storage for scalar data. This includes new logic for calculating family weights based on overlap, quota-based layer determination, and filtering families based on quartet informativeness. Updates also include argument parsing for `--n-sites` and improved handling of family overlap files.
69 lines
3.0 KiB
Rust
69 lines
3.0 KiB
Rust
//! The single trunk every sampled sibling-family computation runs
|
|
//! through: one [`sample_index`] pass, fanned out to whichever
|
|
//! [`LayerReducer`]s the caller actually needs. Replaces three previously
|
|
//! independent drivers (a pseudo-alignment-only one, a tally-only one, and
|
|
//! a hand-fused alignment+tally one for `--sankoff`) that each ran their
|
|
//! own `sample_index` call — meaning two of them combined in the same CLI
|
|
//! invocation used to draw two different random samples for what was
|
|
//! supposed to be one shared site selection. A caller that needs several
|
|
//! outputs from the same sample now passes several reducers to one
|
|
//! [`sampled_scan`] call instead of calling several higher-level functions
|
|
//! and hoping they agree.
|
|
|
|
use obikidxcache::index_cache::IndexCache;
|
|
use obikindex::OKIResult;
|
|
|
|
use super::stats::sibling_family_size_histogram;
|
|
use super::subsample::{SamplingSpec, SurvivingFamily, sample_index};
|
|
|
|
/// One accumulator fed every layer's [`SurvivingFamily`] batch during a
|
|
/// [`sampled_scan`] pass — self-contained (no sampling/masking logic of
|
|
/// its own), so any number of these can run side by side over the exact
|
|
/// same batches without knowing about each other. Implement this once per
|
|
/// kind of output the trunk should be able to produce (see
|
|
/// `algorithms::alignment::AlignmentReducer`, `algorithms::pairwise::PairwiseReducer`).
|
|
pub trait LayerReducer {
|
|
fn reduce(&mut self, partition: usize, layer: usize, survivors: &[SurvivingFamily]);
|
|
}
|
|
|
|
/// `n`: `Some(target)` samples proportionally per layer, up to `target`
|
|
/// sites index-wide (`--subsample`); `None` means exhaustive — every
|
|
/// non-monomorphic minorant of the whole index, driven through the exact
|
|
/// same [`sample_index`] machinery at a quota equal to the total eligible
|
|
/// count (so every family is drawn with certainty) rather than a separate
|
|
/// full-scan code path.
|
|
fn resolve_target(cache: &IndexCache, n: Option<usize>) -> OKIResult<usize> {
|
|
match n {
|
|
Some(target) => Ok(target),
|
|
None => {
|
|
let counts = sibling_family_size_histogram(cache)?;
|
|
Ok((counts[1] + counts[2] + counts[3]) as usize)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Run one shared, possibly-subsampled/entropy-biased/quartet-restricted
|
|
/// selection over `cache` (`n`/`spec`/`excluded` — see [`sample_index`]'s
|
|
/// own docs and [`SamplingSpec`] for what each controls), feeding every
|
|
/// surviving family of every visited layer to every reducer in
|
|
/// `reducers`, in the same order, before moving to the next layer. A
|
|
/// no-op (not an error) if the resolved target is `0`.
|
|
pub fn sampled_scan(
|
|
cache: &IndexCache,
|
|
n: Option<usize>,
|
|
spec: SamplingSpec,
|
|
excluded: &[bool],
|
|
reducers: &mut [&mut dyn LayerReducer],
|
|
) -> OKIResult<()> {
|
|
let target = resolve_target(cache, n)?;
|
|
if target == 0 {
|
|
return Ok(());
|
|
}
|
|
sample_index(cache, target, spec, excluded, 0, |partition, layer, _raw_index, survivors| {
|
|
for reducer in reducers.iter_mut() {
|
|
reducer.reduce(partition, layer, &survivors);
|
|
}
|
|
})?;
|
|
Ok(())
|
|
}
|