Skip to content

ImpliedLosses score is wrong: species tree nodes are compared by identity #115

Open

Description

@alpae

Problem

The ImpliedLosses score in the orthoXML is too high. A complete 1:1 family over all 30 species of fungi-30 (rootHOG F0848294, CompletenessScore 1.0 at every level) gets ImpliedLosses=22 at Fungi, where it should be 0. Roughly, every nested orthologGroup adds one loss. Families that really lost clades are also wrong: with species A and C of ((A,B),(C,D)) the expected value is 2.

Cause

_count_untouched_clades (_hog_class.py:82-86) decides with tree_node in reached_nodes / tree_node in r.get_ancestors() whether a clade is reached. ete3 TreeNode has no __eq__, so this compares object identity. The nodes come from different tree objects:

  • the scoring node is taken from full_species_tree, a copy() of the species tree (_hog_class.py:576, _infer_subhog.py:118);
  • each HOG's _tax_now points into the pruned working tree;
  • every taxonomic level is written to and read from its own pickle file (infer_hogs_this_level), so the HOGs of different levels point into different copies of the tree.

The existing unit tests (tests/test_hog_scores.py) build everything on one tree object, so they don't catch it. CompletenessScore and TCSScore are not affected (they use names / the size feature).

Tests

  • tests/test_hog_class.py::test_implied_losses_against_full_species_tree (strict xfail on PR Test suite ahead of the ete3 → ete4 migration #112; covers in-memory and pickled-per-level)
  • the golden snapshots in tests/data/fungi30/golden/ record the current, wrong values and will change with the fix.

Proposed fix

Compare species tree nodes by name (names are unique after check-input), or resolve each _tax_now into the scoring tree via _species_name_index before comparing. More generally, storing the taxon name in HOG instead of a TreeNode would remove this class of bug and shrink the per-level pickles (each currently contains a copy of the species tree); that also helps the ete4 migration.

After the fix, regenerate the golden snapshots and check that the diff only changes ImpliedLosses values.

Activity

  1. added
    bugSomething isn't working
    on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions