Skip to content

Fix dependency-gated validation flow in DE/SCTransform/Numbat paths#23

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/check-for-bugs
Draft

Fix dependency-gated validation flow in DE/SCTransform/Numbat paths#23
Copilot wants to merge 2 commits intomainfrom
copilot/check-for-bugs

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 3, 2026

Description

This PR addresses multiple concrete failure paths found during detailed bug inspection, where optional dependency imports preempted expected validation errors or produced unstable behavior under mocked environments.
The changes are surgical and focused on restoring correct error semantics and deterministic control flow.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring

Related Issues

N/A

Changes Made

  • Added/modified spatial analysis methods

  • Updated MCP server functionality

  • Improved data preprocessing

  • Enhanced visualization capabilities

  • Updated documentation

  • Added tests

  • Other: Fixed dependency/validation ordering and import robustness in optional-tool paths

  • Differential expression (_run_pydeseq2)

    • Moved pydeseq2 import from function entry to post-precondition stage.
    • Ensures group/sample/pseudobulk validation errors surface even when pydeseq2 is not installed.
  • Preprocessing (normalization="sct")

    • Reordered flow so memory-sensitive CSC conversion executes before rpy2 import.
    • Added explicit DependencyError guidance when rpy2 is unavailable instead of generic processing failure.
  • CNV Numbat path (_infer_cnv_numbat)

    • Hardened rpy2 submodule resolution (sys.modules + importlib) for compatibility with test-time module stubbing.
    • Preserved existing dependency-error contract (rpy2 not installed) for downstream expectations.
  • Focused test update

    • Added top-level rpy2 module stub in test_infer_cnv_numbat_requires_allele_dataframe to make the mocked import graph complete and deterministic.
# before: dependency import could fail before validation
require("pydeseq2", ctx, feature="DESeq2 differential expression")

# after: validate first, import only when actually needed
if any(condition_counts < 2):
    raise DataError(...)
require("pydeseq2", ctx, feature="DESeq2 differential expression")

Testing

  • All existing tests pass
  • Added new tests for new functionality
  • Tested with different data types (Visium, Slide-seq, etc.)
  • Tested MCP integration with Claude Desktop
  • Manual testing performed

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • 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
  • New and existing unit tests pass locally with my changes

Screenshots (if applicable)

N/A (no UI changes)

Additional Notes

This PR intentionally avoids unrelated cleanup and keeps scope to bug-reproducing paths only.

Copilot AI changed the title [WIP] Check for bugs in the application Fix dependency-gated validation flow in DE/SCTransform/Numbat paths Apr 3, 2026
Copilot AI requested a review from cafferychen777 April 3, 2026 02:56
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.

2 participants