Skip to content

feat: add Harmony to scanpy#3953

Open
Intron7 wants to merge 29 commits intomainfrom
add-harmony
Open

feat: add Harmony to scanpy#3953
Intron7 wants to merge 29 commits intomainfrom
add-harmony

Conversation

@Intron7
Copy link
Copy Markdown
Member

@Intron7 Intron7 commented Jan 26, 2026

After recent changes from Harmonypy its necessary to move HarmonyBatchcorrection to scanpy. This function is based on harmony-pytorch and rapids-singlecell

@Intron7 Intron7 requested a review from flying-sheep January 26, 2026 09:50
@Intron7 Intron7 added this to the 1.12.1 milestone Jan 26, 2026
@Intron7 Intron7 marked this pull request as draft January 26, 2026 09:51
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@ea8e481). Learn more about missing BASE report.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@          Coverage Diff           @@
##             main   #3953   +/-   ##
======================================
  Coverage        ?       0           
======================================
  Files           ?       0           
  Lines           ?       0           
  Branches        ?       0           
======================================
  Hits            ?       0           
  Misses          ?       0           
  Partials        ?       0           

Copy link
Copy Markdown
Member

@flying-sheep flying-sheep left a comment

Choose a reason for hiding this comment

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

Looks good! I fixed the docs and made the code a bit nicer, but the reference tests have been failing from the start. Any idea why? You said they work locally for you?

@Intron7 Intron7 marked this pull request as ready for review March 2, 2026 09:49
@Intron7
Copy link
Copy Markdown
Member Author

Intron7 commented Mar 2, 2026

so 0.05 for L2 was way to low harmony-pytorch is at 0.0511. we were at 0.0501. I also ran harmoypy once and it was at 0.063. so I set L2 to 0.1

@Intron7 Intron7 requested a review from flying-sheep March 2, 2026 10:07
Copy link
Copy Markdown
Member

@flying-sheep flying-sheep left a comment

Choose a reason for hiding this comment

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

looks good! Some API considerations.

Please

  • add parameter descriptions and
  • rename the parameters (probably a good idea, this is how we do things in scanpy, but we might have to add a wrapper in .external for this)
  • add a towncrier fragment

Comment on lines +19 to +20
basis: str = "X_pca",
adjusted_basis: str = "X_pca_harmony",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

these will become refs in 2.0, but we might release harmony before that.

Comment on lines +22 to +32
theta: float | Sequence[float] | None = None,
sigma: float = 0.1,
n_clusters: int | None = None,
max_iter_harmony: int = 10,
max_iter_clustering: int = 200,
tol_harmony: float = 1e-4,
tol_clustering: float = 1e-5,
ridge_lambda: float = 1.0,
correction_method: Literal["fast", "original"] = "original",
block_proportion: float = 0.05,
tau: int = 0,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

theta, lambda, sigma, tau … we should probably

  1. rename these to make sense
  2. fix the docs:
  • tau “Discounting factor” – this one has a great description about what it does, let’s do that for the rest! e.g.
  • “Diversity penalty weight … default 2 for each batch variable” – “diversity” might be a good component of the param name, but what is it and what does “2” mean compared to smaller or bigger values?
  • “ridge regression regularization … default 1” – what does increasing and decreasing do, respectively?

Comment thread src/scanpy/preprocessing/_harmony_integrate.py Outdated
Comment thread tests/test_harmony.py
Comment thread src/scanpy/preprocessing/_harmony_integrate.py Outdated
@flying-sheep flying-sheep modified the milestones: 1.12.1, 1.12.2 Apr 10, 2026
@flying-sheep flying-sheep added this to the 1.13.0 milestone Apr 10, 2026
@flying-sheep flying-sheep changed the title Add Harmony to scanpy feat: add Harmony to scanpy Apr 20, 2026
@flying-sheep
Copy link
Copy Markdown
Member

OK, I got rid of random_state. Let’s see if the tests are robust against different k-means clustering.

Co-authored-by: Copilot <copilot@github.com>
@Intron7
Copy link
Copy Markdown
Member Author

Intron7 commented Apr 23, 2026

OK, I got rid of random_state. Let’s see if the tests are robust against different k-means clustering.

that is not a good way to do this. this test was designed to test if the math in fast and original is the same im going to revert it. We test the Kmeans in the overall test because those number were created with R

Intron7 and others added 7 commits April 23, 2026 15:42
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Philipp A. <flying-sheep@web.de>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Philipp A. <flying-sheep@web.de>
Co-authored-by: Copilot <copilot@github.com>
Copy link
Copy Markdown
Member

@flying-sheep flying-sheep left a comment

Choose a reason for hiding this comment

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

OK, looks good! Anything else you want to change before we merge it?

JhonatanFelix and others added 2 commits April 24, 2026 16:16
Co-authored-by: Philipp A. <flying-sheep@web.de>
Co-authored-by: Copilot <copilot@github.com>
@Intron7
Copy link
Copy Markdown
Member Author

Intron7 commented Apr 25, 2026

@flying-sheep we can merge

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.

scanpy.external.pp.harmony_integrate incompatible with newly updated harmonypy>=0.1.0

6 participants