From ab5451a5412507515636ce5348100a5224bbd775 Mon Sep 17 00:00:00 2001 From: hyperpolymath <6759885+hyperpolymath@users.noreply.github.com> Date: Fri, 23 Oct 2026 15:52:31 +0000 Subject: [PATCH] Pin the weighted-UniFrac expectation to the library-size definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Julia tests` on `main` is red on one assertion, and it was already red when #239 merged: that PR's own `Julia tests` check failed with the same line. Dual-hierarchy CladeCumulus, ...: Test Failed at test_clade_cumulus.jl:730 Expression: ≈((jp_body.diversity.weighted_unifrac[1])[2], 0.15636363636363637) Evaluated: 0.1378181818181818 ≈ 0.15636363636363637 The expectation predates #239's `totals` plumbing. That PR's stated fix is "totals/total_a/total_b library-size denominators", and the code now divides by the 55-read library rather than the 34/20 reads that reached the tree. The value follows directly from that definition — the grafted tree contributes 0.02 (ASV_1's pendant), 0.05 (the rest of Ref_1's branch), 0.02 (ASV_2's pendant), 0.15 (the rest of Ref_2's branch) and 0.30 (the joining clade): (0.02*24 + 0.05*24 + 0.02*10 + 0.15*10 + 0.30*(34-20)) / 55 = 7.58 / 55 = 0.1378181818... which is exactly what the route returns. The assertion now states the arithmetic, so the next convention change has to argue with it rather than with a bare decimal. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com> --- test/unit/test_clade_cumulus.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/unit/test_clade_cumulus.jl b/test/unit/test_clade_cumulus.jl index b0d3fe03..670d119f 100644 --- a/test/unit/test_clade_cumulus.jl +++ b/test/unit/test_clade_cumulus.jl @@ -727,8 +727,14 @@ echo "(MMTIP_000001:0.05,(MMTIP_000002:0.03,MMTIP_000003:0.04)0.910:0.12,MMTIP_0 @test jp_body.diversity.mapped_tips == 2 @test jp_body.diversity.unplaced_reads.SampleA ≈ 21.0 atol = 1e-9 @test jp_body.diversity.unplaced_reads.SampleB ≈ 35.0 atol = 1e-9 - @test jp_body.diversity.weighted_unifrac[1][2] ≈ - 0.15636363636363636 atol = 1e-9 + # Raw weighted UniFrac against the 55-read library sizes (the + # `totals` denominators that keep unplaced mass off the tree): the + # grafted tree contributes 0.02 (ASV_1's pendant), 0.05 (the rest + # of Ref_1's branch), 0.02 (ASV_2's pendant), 0.15 (the rest of + # Ref_2's branch) and 0.30 (the clade joining them), so + # (0.02*24 + 0.05*24 + 0.02*10 + 0.15*10 + 0.30*(34-20)) / 55 + # = 7.58 / 55 = 0.1378181... + @test jp_body.diversity.weighted_unifrac[1][2] ≈ 7.58 / 55 atol = 1e-9 # The clade tree is a count view of the table and still conserves # every observed read; only the abundance-weighted diversity matrix # discounts the unplaced mass.