refactor: replace no_ambiguity bool with AmbiguityPolicy enum
Replace the binary `no_ambiguity` flag with an `AmbiguityPolicy` enum (`Keep`, `Forbid`, `OnlyDiploid`) to support multiple ambiguity conventions. This change updates CLI arguments, internal logic, and persistent storage formats to distinguish between keeping all genomes, forbidding ambiguous ones, or restricting analysis to diploid sites only. - Add `src/obikphylo/src/siblings/ambiguity.rs` defining the `AmbiguityPolicy` enum with variants `Keep`, `Forbid`, and `OnlyDiploid`, including methods for header flags and determining if a genome is dropped. - Update `PhyloArgs` in `args.rs` to derive `AmbiquityPolicy` from CLI flags and construct `AnnexSelection` for sibling annexes. - Modify `SamplingSpec` in `subsample.rs` to store `ambiguity: AmbiguityPolicy` instead of `no_ambiguity`, updating masking and scalar value logic accordingly. - Update `SiblingExt` in `sibling_ext.rs` so `build_sibling_annex` accepts an `AnnexSelection` to build only requested derived annexes, and `family_overlap` uses the specific policy. - Refactor `FamilyOverlap` in `family_overlap.rs` to store and use `AmbiguityPolicy`, replacing boolean checks with policy-based carrier determination. - Update `FamilyScalarAnnex` in `family_scalar_annex.rs` to store `AmbiguityPolicy` in headers, enabling distinct file names for each policy variant. - Modify `quartet_annex.rs` to generate distinct file names based on `AmbiguityPolicy`, ensuring no overlap between Keep, Forbid, and OnlyDiploid annexes. - Update `family_annexes.rs` to use `AnnexSelection` for building entropy, quartet, and pair weight annexes under specific policies instead of a single boolean convention. - Refactor algorithm modules (`entropy.rs`, `masking.rs`, `pair_weight.rs`, `quartet.rs`, `snp_distance.rs`) to accept `AmbiguityPolicy` arguments, replacing boolean checks with policy-specific logic (e.g., `OnlyDiploid` masking). - Update documentation in `phylo.md` and `evolutionary_distances.md` to describe the new `--only-diploid` option, the behavior of `--sibling-annex` with specific policies, and the separate storage of entropies per convention.
This commit is contained in:
1 parent
b55123a376
commit
5368c98875
21 files changed
+477
-278
No files matched your search
@@ -2923,14 +2923,29 @@ for a real dosage (polyploids) would need k-mer counts (`--with-counts`),
|
||||
not used by the pseudo-alignment scan today. `--only-diploid` (selection option, `conflicts_with --no-ambiguity`) adds a
|
||||
third `masked_state` rule: `count_ones() > 2` -> missing. It lives in
|
||||
`SamplingSpec`/`masked_state`, i.e. the post-hoc masking and
|
||||
`survives_masking`, so FASTA, Sankoff and `snp-*` see it too. The persisted
|
||||
entropy/quartet/pair-weight/overlap annexes are keyed by the `no_ambiguity`
|
||||
bool (two variants on disk); a third variant was not added: they are read
|
||||
under `no_ambiguity = false`, which for the quartet pre-filter is a superset
|
||||
of what survives the stricter masking (reasoned, not tested) and for the
|
||||
entropy/pair-weight draw weights only changes the weighting. Unit-tested
|
||||
`survives_masking`, so FASTA, Sankoff and `snp-*` see it too. Unit-tested
|
||||
(`masked_state`); the toy index has no 3/4-member cells, so the end-to-end
|
||||
run is identical to the default mode. Toy index: default mode 187
|
||||
run is identical to the default mode.
|
||||
|
||||
First version of this flag read the persisted annexes under the default
|
||||
convention (a third variant was judged not worth it). Rejected: the draw
|
||||
would then describe other genomes than the alignment, and the pair-balance
|
||||
weights and entropy are computed from the carrier set. Replaced by
|
||||
`AmbiguityPolicy { Keep, Forbid, OnlyDiploid }` (one type instead of
|
||||
`free_loss`/`no_ambiguity`/`only_diploid` booleans in `masked_state`,
|
||||
`is_carrier`, `SamplingSpec` and every annex key). Annex headers store
|
||||
`AmbiguityPolicy::header_flags` (0 = Keep, 1 = Forbid, as the old bit, 2 =
|
||||
OnlyDiploid), so annexes written before the change stay valid; each policy
|
||||
has its own file (`*.diploid.*` for the new one). `--sibling-annex` no longer
|
||||
precomputes everything (`AnnexRequest::everything` removed, a rebuild only
|
||||
costs the base annex): it builds the derived annexes named by the other
|
||||
options of the command (`AnnexSelection`: `--entropy`, `--quartet`,
|
||||
`--pair-balance`, `--family-overlap`/`--min-shared-family`, under the one
|
||||
policy given); the rest is built on demand as before. A rebuild still drops
|
||||
every derived annex (their `family_idx` numbering is tied to the base one).
|
||||
Checked on the toy index: `--sibling-annex` alone leaves only
|
||||
`siblings.psib`; `--quartet --only-diploid` adds `quartet.diploid.pbiv` only.
|
||||
Toy index: default mode 187
|
||||
lines, no `ALT = .`; `--no-ambiguity` 93 lines (the sites whose polymorphism
|
||||
was only ambiguity codes disappear, since those cells became `?`).
|
||||
|
||||
|
||||
Reference in new issue
Block a user