slowkow / harmonypy

🎼 Integrate multiple high-dimensional datasets with fuzzy k-means and locally linear adjustments.
https://portals.broadinstitute.org/harmony/
GNU General Public License v3.0
198 stars 22 forks source link

Harmony with two or more covariates #19

Closed Sayyam-Shah closed 2 years ago

Sayyam-Shah commented 2 years ago

Hello @slowkow,

Thank you for adding Harmony to Python!

May you please allow harmony to be run with multiple covariates in harmonypy as this will make many workflows easier? This can be done in the R package.

slowkow commented 2 years ago

Thanks for opening the issue!

harmonypy version 0.0.4 (and later versions) supports multiple covariates.

Please see #4 for discussion of this issue.

Sayyam-Shah commented 2 years ago

Hello @slowkow

Thank you! Has this been added to the Scanpy function?

I assume the line will look like: sce.pp.harmony_integrate(adata, ['batch1', 'batch2'])

slowkow commented 2 years ago

Try it! If it doesn't work, then please consider reporting the issue to scanpy developers.

Please also consider reading the source code for the packages that you use:

Here is what I see inside the harmony_integrate() scanpy function (lines 77-84):

    try:
        import harmonypy
    except ImportError:
        raise ImportError("\nplease install harmonypy:\n\n\tpip install harmonypy")

    harmony_out = harmonypy.run_harmony(adata.obsm[basis], adata.obs, key, **kwargs)

    adata.obsm[adjusted_basis] = harmony_out.Z_corr.T