deweylab/CellO

sparsematrix toarray in cello.py

Closed this issue · 2 comments

I encountered this error when I run scanoy_cello

File /mnt/data/hong/anaconda3/envs/scanpy/lib/python3.10/site-packages/cello/cello.py:454, in _aggregate_expression(X)
    448 def _aggregate_expression(X):
    449     """
    450     Given a matrix of log(TPM+1) where rows correspond to cells
    451     and columns correspond to genes, aggregate the counts
    452     to form a psuedo-bulk expression profile.
    453     """
--> 454     X = (np.exp(X)-1) / 1e6
    455     x_clust = np.sum(X, axis=0)
    456     sum_x_clust = float(sum(x_clust))

TypeError: loop of ufunc does not support argument 0 of type SparseCSRView which has no callable exp method

I added

from scipy.sparse import issparse
## in function _combine_by_cluster
    X_clust = ad[cells,:].copy().X
    X_clust = X_clust.toarray() if issparse(X_clust) else X_clust

in cello.py to deal with this error.

Any best solution?
Best,

Hi, this error is due to CellO being incompatible with sparse matrix formats. I just updated to CellO so that it works on sparse matrices (Version 2.1.0) which is now available on PyPI and installable via pip. Please let me know if this new version does not fix this error.

Hi, this error is due to CellO being incompatible with sparse matrix formats. I just updated to CellO so that it works on sparse matrices (Version 2.1.0) which is now available on PyPI and installable via pip. Please let me know if this new version does not fix this error.

Nice! I just tested the new version and it works on sparse matrices in my case!
Many Thanks!