Skip to content

Add symmetrized linkage stats to ancestral_linkage#60

Open
colganwi wants to merge 2 commits into
mainfrom
symmetrized-linkage-stats
Open

Add symmetrized linkage stats to ancestral_linkage#60
colganwi wants to merge 2 commits into
mainfrom
symmetrized-linkage-stats

Conversation

@colganwi

@colganwi colganwi commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.92%. Comparing base (b3b8abd) to head (19ed242).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #60      +/-   ##
==========================================
+ Coverage   93.83%   93.92%   +0.08%     
==========================================
  Files          37       37              
  Lines        3344     3373      +29     
==========================================
+ Hits         3138     3168      +30     
+ Misses        206      205       -1     
Files with missing lines Coverage Δ
src/pycea/pl/plot_ancestral_linkage.py 97.52% <100.00%> (+0.02%) ⬆️
src/pycea/tl/ancestral_linkage.py 95.54% <100.00%> (+0.48%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

When symmetrize is not False and test='permutation' in pairwise mode,
ancestral_linkage now writes tdata.uns['{key_added}_symmetrized_linkage_stats']:
a long-form table with one row per unordered category pair (upper triangle
incl. diagonal) giving the symmetrized value, permuted value, z-score, and a
p-value for the symmetrized linkage.

The p-value is computed by symmetrizing each permutation's null matrix (with
the same mean/max/min rule as the observed matrix) and testing the observed
symmetrized value against that null distribution.

- Add _symmetrize_array (symmetrizes along the last two axes; reused by
  _symmetrize_matrix) and _symmetrized_stats_rows helpers.
- _run_permutation_test / _run_permutation_test_non_target now also return the
  raw null_array so the symmetrized null can be derived.
- Wire into both global and by_tree pairwise paths; clear any stale table when
  conditions aren't met.
- Exclude the new key from pl.ancestral_linkage's groupby auto-inference.
- Add test and CHANGELOG entry.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@colganwi colganwi force-pushed the symmetrized-linkage-stats branch from 33ed43b to d6e3aac Compare July 14, 2026 17:28

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 33ed43b599

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/pycea/tl/ancestral_linkage.py Outdated
Comment on lines +1250 to +1255
sym_key = f"{key_added}_symmeterized_linkage_stats"
if sym_stats_rows:
tdata.uns[sym_key] = pd.DataFrame(sym_stats_rows)
else:
# Drop any stale table from a previous run (e.g. when symmetrize was truthy then).
tdata.uns.pop(sym_key, None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear stale symmetrized stats in single-target runs

This cleanup only runs in the pairwise branch, so a prior pairwise call with test='permutation' and truthy symmetrize leaves {key_added}_symmeterized_linkage_stats behind if the next call uses the same key_added in single-target mode. In that scenario tdata.uns still advertises a symmetrized pairwise stats table even though the current result is single-target-only, which can make downstream code consume stale p-values/results.

Useful? React with 👍 / 👎.

- Drop {key_added}_symmetrized_linkage_stats before the mode branch so a later
  single-target run under the same key_added does not leave a stale pairwise
  table for downstream code to consume (flagged by review).
- Cover the by_tree + permutation_mode='all' symmetrized path in tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@colganwi

Copy link
Copy Markdown
Collaborator Author

Addressed in 19ed242:

  • Stale symmetrized stats in single-target runs (Codex P2): {key_added}_symmetrized_linkage_stats is now dropped before the single-target/pairwise branch, so reusing the same key_added in single-target mode no longer leaves a stale pairwise table for downstream code to consume.
  • Patch coverage: added a test covering the by_tree + permutation_mode="all" symmetrized path (the previously-uncovered line), plus the single-target stale-key scenario above.

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