Skip to content

Fix prot.pp.clr for old-style sparse matrices - #212

Merged
ilia-kats merged 1 commit into
mainfrom
clr_fix
Jul 23, 2026
Merged

Fix prot.pp.clr for old-style sparse matrices#212
ilia-kats merged 1 commit into
mainfrom
clr_fix

Conversation

@Zethson

@Zethson Zethson commented Jul 23, 2026

Copy link
Copy Markdown
Member

Problem

muon.prot.pp.clr crashes on the seurat flavor when adata.X is an old-style SciPy sparse matrix (csc_matrix / csr_matrix):

mu.prot.pp.clr(adata, axis=1)
# AttributeError: 'matrix' object has no attribute 'toarray'

For an spmatrix, np.log1p(x).mean(axis=axis) returns a numpy.matrix, which has no .toarray() method, so the existing line fails. This affects common datasets whose ADT .X is still an spmatrix (e.g. papalexi_2021).

Fix

Compute the per-feature log-mean once and coerce it to a plain array depending on the container type:

The axis type hint is also tightened to Literal[0, 1].

Verification

Installed this branch and ran the pertpy perturbation_efficacy tutorial (which calls mu.prot.pp.clr(mdata["adt"], axis=1) on papalexi_2021) end-to-end: all 32 code cells execute with no errors. CLR output on both axis=0 and axis=1 is finite, non-negative, and preserves sparsity as expected for the seurat flavor.

@ilia-kats
ilia-kats merged commit 11070b9 into main Jul 23, 2026
0 of 4 checks passed
@ilia-kats
ilia-kats deleted the clr_fix branch July 23, 2026 16:05
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