Skip to content

Transposing error with sce.pp.harmony_integrate() #3962

@hannahwilcox1011

Description

@hannahwilcox1011

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the main branch of scanpy.

What happened?

While using the sce.pp.harmony_integrate() function to correct for batch effect in single cell RNA data, we ran into a transposing error. In this error the function continuously produced a ValueError as X_pca_harmony needed to be of (# cells, # pcas) shape, whereas it was of (# pcas, # cells) shape. We found that going into the function within the package script and deleting the .T of the last line stopped the final transposition in the function, seeming to fix the error and produce the expected results of integrated data.

scanpy/external/pp/_harmony_integrate.py:
Changing
adata.obsm[adjusted_basis] = harmony_out.Z_corr.T
to
adata.obsm[adjusted_basis] = harmony_out.Z_corr

Minimal code sample

# /// script
# requires-python = ">=3.12"
# dependencies = [
#   "scanpy@git+https://github.com/scverse/scanpy.git@main",
# ]
# ///
#
# This script automatically imports the development branch of scanpy to check for issues

import scanpy as sc
# complete sc-rna data filtering 
sc.pp.normalize_total(adata)
sc.pp.log1p(adata)
sc.pp.highly_variable_genes(adata, n_top_genes=2000, batch_key="subject_id", flavor="seurat")

sc.pp.pca(adata, n_comps = 50)
sc.pl.pca_variance_ratio(adata, n_pcs=50, log=True)

adata.obs["subject_id"] = adata.obs["subject_id"].astype("category")
sce.pp.harmony_integrate(adata, key="subject_id", max_iter_harmony = 50)

Error output

ValueError: Value passed for key 'X_pca_harmony' is of incorrect shape. Values of obsm must match dimensions ('obs',) of parent. Value had shape (50,) while it should have had (160000,).

Versions

Details
scanpy 1.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    Triage 🩺This issue needs to be triaged by a maintainer

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions