Skip to content

Add signature reversal scoring to enrichment - #1082

Open
daveringelberg wants to merge 7 commits into
scverse:mainfrom
daveringelberg:signature-reversal-enrichment
Open

Add signature reversal scoring to enrichment#1082
daveringelberg wants to merge 7 commits into
scverse:mainfrom
daveringelberg:signature-reversal-enrichment

Conversation

@daveringelberg

Copy link
Copy Markdown

PR Checklist

  • Referenced issue is linked
  • If you've fixed a bug or added code that should be tested, add tests!
  • Documentation in docs is updated

Description of changes

This adds a first CMap-style signature reversal workflow to pt.tl.Enrichment.

Given perturbation-level AnnData with perturbations as observations and genes as variables, users can provide either up/down query gene sets or a signed query signature. The method scores each perturbation by how strongly it opposes the query signature and stores the results back on the AnnData object.

This addresses the signature reversal part of #1036. It does not address Bliss/Loewe synergy, dose-response, or genetic interaction workflows.

Technical details

  • adds Enrichment.signature_reversal
  • stores reversal score, connectivity score, and rank in adata.obs
  • stores query metadata and result keys in adata.uns
  • supports .X, an optional layer, and optional gene-symbol matching through adata.var
  • documents signature reversal under the Enrichment tools section
  • adds compact tests for up/down gene sets and signed query signatures
  • adds no new dependency

Testing

  • ruff check src\pertpy\tools\_enrichment.py tests\tools\test_enrichment.py
  • ruff format --check src\pertpy\tools\_enrichment.py tests\tools\test_enrichment.py
  • pytest tests\tools\test_enrichment.py -q -p no:cacheprovider

Addresses part of #1036.

@codecov-commenter

codecov-commenter commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.78%. Comparing base (c2831c5) to head (ace13a9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1082      +/-   ##
==========================================
+ Coverage   79.45%   79.78%   +0.32%     
==========================================
  Files          53       53              
  Lines        7546     7667     +121     
==========================================
+ Hits         5996     6117     +121     
  Misses       1550     1550              
Files with missing lines Coverage Δ
src/pertpy/tools/_enrichment.py 83.33% <100.00%> (+16.94%) ⬆️

... and 2 files with indirect coverage changes

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

@daveringelberg

Copy link
Copy Markdown
Author

It looks like the ReadTheDocs failure is unrelated to this PR. The warnings seem to come from external intersphinx/scvi-lightning references.

@daveringelberg

Copy link
Copy Markdown
Author

After a further pass, the implementation now uses raw CMap WTCS. The remaining ReadTheDocs failure is caused by the same external issue noted above.

@Zethson

Zethson commented Aug 21, 2026

Copy link
Copy Markdown
Member

Thanks! I'll have a look at the RTD failure soon.

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.

3 participants