calico / solo

software to detect doublets
MIT License
85 stars 13 forks source link

hashsolo requires dense array #80

Open zktuong opened 10 months ago

zktuong commented 10 months ago

Hi I'm trying to run the following:

import scanpy as sc
adata = sc.read_10x_h5("sample_filtered_feature_bc_matrix.h5", gex_only=False)
hdata = adata[:, adata.var.index.isin(["HTO_C0301", "HTO_C0302"])].copy()
from solo import hashsolo
hashsolo.hashsolo(hdata., number_of_noise_barcodes=1)

And it gives me this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/uqztuong/miniforge3/envs/dandelion/lib/python3.11/site-packages/solo/hashsolo.py", line 392, in hashsolo
    posterior_dict = _calculate_bayes_rule(data, priors, number_of_noise_barcodes)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/uqztuong/miniforge3/envs/dandelion/lib/python3.11/site-packages/solo/hashsolo.py", line 238, in _calculate_bayes_rule
    log_likelihoods_for_each_hypothesis, _, _ = _calculate_log_likelihoods(
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/uqztuong/miniforge3/envs/dandelion/lib/python3.11/site-packages/solo/hashsolo.py", line 92, in _calculate_log_likelihoods
    data = np.log(data + 1)
                  ~~~~~^~~
  File "/home/uqztuong/miniforge3/envs/dandelion/lib/python3.11/site-packages/scipy/sparse/_base.py", line 462, in __add__
    raise NotImplementedError('adding a nonzero scalar to a '
NotImplementedError: adding a nonzero scalar to a sparse array is not supported

converting the .X to dense array manually worked. just want to flag this as others may encounter this issue.

versions: scipy==1.11.3 solo-sc==1.3 scanpy==1.9.3 anndata==0.9.1 umap==0.5.4 numpy==1.24.4 scipy==1.11.3 pandas==2.1.0 scikit-learn==1.3.1 statsmodels==0.14.0 python-igraph==0.10.8 pynndescent==0.5.1