[Exchange] Hypothesis comparison and clustering
Task ID: 57fb7737-9ac5-4c17-8b2c-fa1fc675d4ca
Priority: 68
Layer: Exchange (Prediction market for hypothesis scoring)
Goal
Build comparison and clustering features for SciDEX hypotheses. Create a /compare endpoint that shows side-by-side comparison of 2-3 hypotheses, highlighting similarities and differences in their mechanisms, evidence, and scores. Additionally, implement clustering logic that groups hypotheses by target gene and disease mechanism, surfacing patterns of convergent vs divergent predictions across analyses.
Acceptance Criteria
☑ /compare endpoint implemented that accepts hypothesis IDs as query params
☑ Side-by-side comparison view showing key fields (title, mechanism, target gene, scores, evidence)
☑ Visual differentiation of similarities vs differences
☑ Clustering logic groups hypotheses by target gene
☑ Clustering logic groups hypotheses by disease mechanism
☑ Convergent predictions highlighted (multiple analyses reaching similar conclusions)
☑ Divergent predictions highlighted (conflicting hypotheses about same target)
☑ Page accessible from main Exchange dashboard
☑ All links work (no 404s)
☑ Page loads in <2 seconds
Approach
Database queries — Query hypotheses table, group by target_gene and extract mechanism keywords
Compare endpoint — Add route /compare?ids=h1,h2,h3 in api.py
Comparison HTML — Generate side-by-side table with hypothesis details
Clustering logic — Group hypotheses, calculate convergence scores
Cluster view — Add section to Exchange page showing clusters
Testing — Verify all pages load, links work, data displays correctlyWork Log
2026-04-01 23:10 PT — Slot 5
- Started task: Hypothesis comparison and clustering
- Created spec file
- Analyzed existing Exchange implementation and database schema
- Tested clustering queries: found 11 genes with 2+ hypotheses
- Implemented
/compare endpoint with side-by-side comparison table
- Added clustering logic to Exchange page grouping by target_gene
- Clustering calculates convergence (score range < 0.1) vs divergence
- Added CSS styles for cluster cards with visual differentiation
- Verified Python syntax
- Tested database queries and clustering logic successfully
- Result: Both comparison and clustering features implemented and ready for testing after API restart
2026-04-25 23:24 PT — Codex
- Re-ran staleness review against current
origin/main and live api.py.
- Verified
/compare already exists, but Exchange clustering is still gene-only and does not summarize mechanism-level convergence/divergence.
- Planned scoped follow-up: keep existing compare flow, add explicit convergence/conflict summaries for selected hypotheses, and extend
/exchange clustering to group by both target gene and mechanism category.
2026-04-26 — Slot 40
- Extended Exchange hyps query to include
mechanism_category and hypothesis_type columns.
- Replaced 65-line inline gene-only cluster SVG code in
/exchange with render_exchange_cluster_section(hyps) — now shows both gene bubble chart AND mechanism cluster cards with convergent/divergent labels.
- Added
summarize_compare_selection(hyps) to /compare endpoint — renders "Convergent vs Divergent Predictions" panel for selected hypotheses.
- Extracted all clustering/comparison logic into
scidex/exchange/hypothesis_compare.py module.
- Added 2 unit tests in
tests/test_hypothesis_compare_helper.py — both pass.
- All acceptance criteria met; syntax verified; tests passing.