Skip to content

Fix ImpliedLosses: look up taxonomic levels by name - #126

Merged
alpae merged 1 commit into
devfrom
fix/implied-losses
Nov 4, 2026
Merged

alpae merged 1 commit into
devfrom
fix/implied-losses

Conversation

@alpae

@alpae alpae commented Nov 4, 2026

Copy link
Copy Markdown
Member

Step 2 of #124. Stacked on #125: the base is fix/small-bugs-input-validation, so this PR only shows the #115 change. GitHub retargets it to dev once #125 is merged.

Problem

ImpliedLosses was too high: roughly one extra loss per nested orthologGroup. A complete 1:1 family over all 30 fungi-30 species (F0848294, CompletenessScore 1.0 everywhere) got ImpliedLosses=22 at Fungi instead of 0.

_count_untouched_clades compares species tree nodes by identity (ete3 TreeNode has no __eq__), but the nodes came from different tree objects:

  • the scoring tree is full_species_tree, a copy;
  • each HOG's _tax_now points into the pruned working tree;
  • every taxonomic level is pickled separately, so the HOGs of different levels point into different copies.

Fix

_hog_implied_losses now looks up the sub-HOGs' taxonomic levels by name in the scoring tree (_species_name_index), so all comparisons stay within one tree object. CompletenessScore and TCSScore were not affected.

Storing taxon names instead of TreeNodes in HOG (fewer ete3 dependencies, smaller pickles) is left to a separate, output-neutral refactor.

Tests

  • test_implied_losses_against_full_species_tree, previously a strict xfail, now passes (complete family = 0, two lost clades = 2; in memory and pickled per level).
  • New test_implied_losses_with_duplication_independent_of_tree_copies: with a duplication, the value is the same whether the levels share one tree object or are pickled separately. It fails with the old code.
  • Golden snapshots regenerated in dessimozlab/fastoma:dev. Apart from ImpliedLosses values, all 13 are unchanged: structure, TaxRange, CompletenessScore and TCSScore are identical. In the text diff, some sibling groups also change places, because the snapshot sorts siblings by their text, which includes the scores. The sum of all ImpliedLosses values in the snapshots drops from 1483 to 910.
  • Fast pytest suite green locally (345 passed).

Fixes #115

🤖 Generated with Claude Code

_count_untouched_clades compares species tree nodes by identity, but the
scoring tree (full_species_tree) and the trees of the separately pickled levels
are different copies. Every nested level therefore counted one extra loss; a
complete 1:1 family over the 30 fungi-30 species got ImpliedLosses=22 at Fungi
instead of 0. _hog_implied_losses now resolves the sub-HOGs' levels by name in
the scoring tree, so all comparisons stay within one tree object.

Golden snapshots regenerated: apart from ImpliedLosses values (and the order of
siblings, which the snapshot sorts by their text), all 13 are unchanged. The sum
of all ImpliedLosses values in the snapshots drops from 1483 to 910.

Fixes #115

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the scoring-tree taxonomic lookup changes.

No open issues 🎉

What changed in this PR

Fixes #115 by resolving sub-HOG taxonomic levels by name in the scoring tree, preventing incorrect ImpliedLosses counts caused by comparing nodes from different tree copies.

Changes:

  • Uses the scoring tree’s name index for recursive loss calculations and reached-clade comparisons.
  • Enables previously failing regression tests and adds duplication coverage across separately pickled tree copies.
  • Refreshes golden snapshots with corrected loss scores, including zero losses for the complete F0848294 family.
File Description
tests/​test_hog_class.py Enables loss regressions and tests duplication across tree copies.
tests/​data/​fungi30/​golden/​F1085561.txt Updates loss scores and resulting group ordering.
tests/​data/​fungi30/​golden/​F0848294.txt Records zero losses throughout the complete family.
tests/​data/​fungi30/​golden/​F0848191.txt Updates loss scores across multiple families.
tests/​data/​fungi30/​golden/​F0489906.txt Refreshes expected loss scores.
tests/​data/​fungi30/​golden/​F0480898.txt Refreshes expected loss scores.
tests/​data/​fungi30/​golden/​F0478382.txt Refreshes expected loss scores.
tests/​data/​fungi30/​golden/​F0477229.txt Refreshes expected loss scores.
tests/​data/​fungi30/​golden/​F0476910.txt Refreshes expected loss scores.
tests/​data/​fungi30/​golden/​F0459413.txt Refreshes expected loss scores.
tests/​data/​fungi30/​golden/​F0453151.txt Refreshes expected loss scores.
tests/​data/​fungi30/​golden/​F0413304.txt Updates loss scores and resulting group ordering.
tests/​data/​fungi30/​golden/​clust12762.txt Refreshes expected loss scores.
FastOMA/​_hog_class.py Resolves taxonomic nodes within one scoring tree by name.

Review effort: Balanced

Base automatically changed from fix/small-bugs-input-validation to dev November 4, 2026 20:06
@alpae
alpae merged commit 721d630 into dev Nov 4, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants