Skip to content

feat(tl): add normalize param and by_tree support to ancestral_linkage permutation#55

Merged
colganwi merged 2 commits intomainfrom
feat/ancestral-linkage-perm-improvements
Mar 30, 2026
Merged

feat(tl): add normalize param and by_tree support to ancestral_linkage permutation#55
colganwi merged 2 commits intomainfrom
feat/ancestral-linkage-perm-improvements

Conversation

@colganwi
Copy link
Copy Markdown
Collaborator

Summary

  • normalize parameter (bool, default False): when True and test='permutation', subtract the permuted mean from observed values.
    • Pairwise: uns[linkage] stores observed - permuted_mean instead of raw linkage.
    • Single-target: obs['{target}_linkage'] is replaced by cell_score - category_permuted_mean.
  • Single-target by_tree + permutation: runs the permutation test independently per tree, producing per-tree stats (with a "tree" column, consistent with pairwise by_tree). When normalize=True, each cell is normalized against its own tree's null distribution.

Test plan

  • test_pairwise_normalize_stores_value_minus_permuted — linkage matrix = value - permuted_value when normalize=True
  • test_pairwise_no_normalize_stores_raw_linkage — raw linkage unchanged when normalize=False
  • test_single_target_normalize_overwrites_linkage — per-cell linkage = score - cat_permuted_mean
  • test_single_target_no_normalize_keeps_raw — raw scores unchanged when normalize=False
  • test_single_target_by_tree_permutation — per-tree stats with "tree" column
  • test_single_target_by_tree_normalize — per-tree normalization updates _linkage
  • test_single_target_by_tree_perm_non_target — non_target mode works with by_tree

🤖 Generated with Claude Code

colganwi and others added 2 commits March 29, 2026 22:07
… mode

Three related changes:
- Pairwise permutation: update docstring to reflect that the stored linkage
  matrix is observed - permuted_mean (not z-scores).
- Single-target + permutation: add tdata.obs['{target}_norm_linkage'] with
  per-cell z-scores normalized by each cell's source-category null distribution.
- Single-target + by_tree + permutation: run permutation, stats, and
  normalization independently per tree so each cell is normalized by its
  own tree's null model.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds normalize: bool = False to ancestral_linkage. When True and
test='permutation':
- Pairwise: linkage matrix stores observed - permuted_mean instead of raw values.
- Single-target: tdata.obs['{target}_linkage'] is replaced with
  cell_score - category_permuted_mean.
- Both modes support by_tree, where per-tree null distributions are used
  for normalization independently per tree.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 98.46154% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.99%. Comparing base (4d64ddc) to head (5785893).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/pycea/tl/ancestral_linkage.py 98.46% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #55      +/-   ##
==========================================
+ Coverage   93.92%   93.99%   +0.07%     
==========================================
  Files          35       35              
  Lines        2932     2983      +51     
==========================================
+ Hits         2754     2804      +50     
- Misses        178      179       +1     
Files with missing lines Coverage Δ
src/pycea/tl/ancestral_linkage.py 98.25% <98.46%> (-0.09%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 5785893917

ℹ️ 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 on lines 523 to 525
test: Literal["permutation", None] = None,
normalize: bool = False,
alternative: Literal["two-sided", None] = 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 Keep normalize from shifting positional arguments

Adding normalize between test and alternative changes the positional call contract of this public API: existing callers that previously passed alternative (or later args) positionally will now silently bind those values to normalize instead. For example, a positional 'two-sided' now becomes a truthy normalize value while alternative stays None, which changes both p-value calculation and stored linkage values without raising an error. Please make normalize keyword-only or append it after existing positional parameters to preserve backward compatibility.

Useful? React with 👍 / 👎.

@colganwi colganwi merged commit 2afbd61 into main Mar 30, 2026
8 checks passed
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