Skip to content

fix: shift signed CLR only for differential_abundance Wilcoxon - #472

Open
elhb wants to merge 1 commit into
PNA-3531from
PNA-3532
Open

elhb wants to merge 1 commit into
PNA-3531from
PNA-3532

Conversation

@elhb

@elhb elhb commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

Makes differential_abundance valid on signed CLR.

difference is still mean(target) - mean(reference) on the original
matrix, matching PixelatorR RunDAA (fc.name = "difference"). Wilcoxon
runs on a test-only copy where each marker is shifted so its minimum is 0.
That shift is the same for every cell, so ranks (and thus p-values) match a
Wilcoxon on the original CLR. Scanpy still computes log-fold changes
internally, which break on negatives; we do not use those values.

Based on PNA-3531.

Fixes: PNA-3532

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

How Has This Been Tested?

uv run pytest tests/pna/analysis/test_differential_abundance.py
  • test_differential_abundance_returns_expected_columns
  • test_differential_abundance_layer_from_obsm
  • test_differential_abundance_group_vars_splits_rows
  • test_differential_abundance_invalid_reference_raises
  • test_differential_abundance_signed_clr_keeps_original_difference_sign

PR checklist:

  • This comment contains a description of changes (with reason).
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • If a new tool or package is included, I have updated dependencies in pyproject.toml and cited it properly
  • I have checked my code and documentation and corrected any misspellings
  • I have documented any significant changes to the code in CHANGELOG.md

Note

Low Risk
Scoped change to PNA differential abundance statistics; non-negative CLR paths are unchanged, with clearer behavior for signed CLR effect sizes and p-values.

Overview
differential_abundance now supports matrices with negative values (e.g. signed CLR) without relying on scanpy Wilcoxon on raw signed data.

When negatives are present, the helper builds a test-only layer (_pixelator_daa_nonneg) by shifting each marker so its column minimum is at least zero (same shift for every cell, preserving ranks). scanpy.tl.rank_genes_groups Wilcoxon p-values use that layer; difference, pct_1, and pct_2 stay on the original selected matrix, aligned with pixelatorR RunDAA. The previous runtime warning filter and negative-value warning are replaced by a one-time info log. Docs and CHANGELOG describe the new flow; the signed-CLR test now asserts the reported mean difference matches the original matrix and that input adata.X is unchanged.

Reviewed by Cursor Bugbot for commit 3a3b424. Bugbot is set up for automated code reviews on this repo. Configure here.

@elhb
elhb force-pushed the PNA-3532 branch 2 times, most recently from adc2abc to 71a7191 Compare September 23, 2026 07:20
Keep mean difference on the original matrix, like PixelatorR RunDAA.

Co-authored-by: Cursor <cursoragent@cursor.com>

This branch has not been deployed

No deployments
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