Skip to content

fix: top-level paralogGroups get the TaxRange directly above the duplication - #129

Merged
alpae merged 3 commits into
devfrom
fix/root-paralog-taxrange
Nov 12, 2026
Merged

alpae merged 3 commits into
devfrom
fix/root-paralog-taxrange

Conversation

@alpae

@alpae alpae commented Nov 11, 2026

Copy link
Copy Markdown
Member

Fixes #128.

What changes

A top-level HOG that starts with a duplication (all its copies come from one clade) is written as a paralogGroup inside an extra orthologGroup. That wrapper used hog.taxname as its TaxRange and scoring level. Usually this is the top of the whole rootHOG, because HOGs that nothing joins are still wrapped at every level above.

The wrapper now sits at the direct parent, in the full species tree, of the common ancestor of all species in the paralogGroup. CompletenessScore, ImpliedLosses and TCSScore are computed at that level too.

  • root_orthoxml() (new, _hog_class.py): builds the top-level element of a HOG. It replaces the inline code in read_infer_xml_rhog. The wrapping no longer depends on the orthoxml_v03 flag, which is removed.
  • ImpliedLosses looks through the wrapper HOGs above the scored level. Without this, scoring a HOG below the level it was built at counted losses against the wrong clades. Nested groups never have such wrappers, so their scores do not change.
  • _species_mrca returned the root of the tree for a single species (ete3's get_common_ancestor with one node). It now returns the species' leaf. Before this, in-paralogs of one species would have been wrapped at the root. This is a separate commit.

Effect on output

In the fungi-30 run (FastOMA 0.5.1, 2026-11-02), 509 of 25,734 top-level groups are such wrappers. 246 of them had a TaxRange 1–6 levels too old (details in #128). For those groups, these change:

  • TaxRange, CompletenessScore and ImpliedLosses;
  • the HOG id: collect_subhogs builds the top-level id as <family>_<taxid of TaxRange>, e.g. HOG:0000127_1 → HOG:0000127_<Basidiomycota taxid>.

All TaxRange values are still nodes of the full species tree, so collect_subhogs's name2taxid lookup works unchanged. utils/orthoxml2rootHOGidLevel.py now reports the corrected level for these rootHOGs.

Testing

  • New unit tests in tests/test_hog_class.py:
    • the Hominini example from the issue: Primates, CompletenessScore 0.6667, 1 loss, the same whether or not the HOG is wrapped up to Mammals;
    • in-paralogs of a single species;
    • a duplication right below the root;
    • no wrapper for a speciation;
    • _species_mrca of a single species.
  • Full Python suite: 375 passed, 13 skipped, 32 xfailed.
  • fungi-30 golden snapshots regenerated in dessimozlab/fastoma:dev: no change. Their only wrapper (F0413304, two paralogs in the Fungiincertaesedis polytomy) already sat at the correct level, Fungi.
  • The nf-test test data (3 species) has no wrapper groups, so its snapshot is unaffected. nf-test was not run.
  • Not done: rerunning the full fungi-30 pipeline and recounting. The script from Root-level groups that start with a duplication can get a TaxRange that is too old #128 should then report 0 wrappers that are too old.

🤖 Generated with Claude Code

alpae and others added 3 commits November 11, 2026 11:12
ete3's get_common_ancestor with a single node returns the root of the tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es' LCA

A top-level HOG that starts with a duplication is put into an orthologGroup
whose TaxRange (and scores) is the direct parent, in the full species tree, of
the common ancestor of all species in the paralogGroup. Before, the level of
the HOG was used, which is usually the top of the whole rootHOG because HOGs
that nothing joins are still wrapped at every level above (#128).

The wrapping no longer depends on the orthoxml_v03 flag, which is removed.
ImpliedLosses looks through the wrapper HOGs above the scored level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
If the paralogs' LCA is the root, there is no parent level for the wrapper:
each copy becomes its own top-level group (same rules, recursively), and
single-gene copies are not written. Stale MRCA xfails now expect the parent.

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

alpae commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

Added 2d5664c: when the LCA of a top-level paralogGroup's species is the root of the species tree, there is no parent level for the wrapper. The copies are then written as separate top-level groups. The same rules apply to each copy, so a copy that starts with its own duplication is wrapped at the parent of its LCA, or split again. They keep their subHOG ids, so they still share the OMAmerRootHOG property. Single-gene copies are not written; the protein trace logs them as final_singleton_not_written.

Also replaced the two stale xfails that expected TaxRange = MRCA for the wrapper (test_level_processor, test_subhog_stage[D0625237]). They now check the parent rule and pass. Full suite: 380 passed, 13 skipped, 30 xfailed.

@alpae
alpae merged commit d8531b4 into dev Nov 12, 2026
26 of 28 checks passed
@alpae
alpae deleted the fix/root-paralog-taxrange branch November 12, 2026 14:59
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.

1 participant