scverse / scanpy

Single-cell analysis in Python. Scales to >1M cells.
https://scanpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.92k stars 600 forks source link

phenograph Expected list, got numpy.ndarray #1407

Closed asmariyaz23 closed 4 years ago

asmariyaz23 commented 4 years ago

While trying to cluster using phenograph I get the error below. Could you help me understand why this happens?

>>adata1
AnnData object with n_obs × n_vars = 77969 × 18417
    obs: 'Id', 'Donor', 'Sample', 'Method', 'Position', 'UMI.Count', 'Expressed.Genes', 'Percent.Mitochond.', 'Percent.Ribo', 'CellType', 'Sex', 'Age'
    var: 'name'
    uns: 'pca'
    obsm: 'X_pca'
    varm: 'PCs'

>>import scanpy.external as sce
>>result=sce.tl.phenograph(adata1.obsm['X_pca'],k=100)

PhenoGraph clustering
Finding 100 nearest neighbors using minkowski metric and 'auto' algorithm
Neighbors computed in 67.26673102378845 seconds
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-22-2cf1719c59ce> in <module>
      1 import scanpy.external as sce
----> 2 result=sce.tl.phenograph(adata1.obsm['X_pca'],k=100)

/usr/local/lib/python3.8/site-packages/scanpy/external/tl/_phenograph.py in phenograph(data, k, directed, prune, min_cluster_size, jaccard, primary_metric, n_jobs, q_tol, louvain_time_limit, nn_method)
    143         )
    144 
--> 145     communities, graph, Q = phenograph.cluster(
    146         data=data,
    147         k=k,

/usr/local/lib/python3.8/site-packages/phenograph/cluster.py in cluster(data, clustering_algo, k, directed, prune, min_cluster_size, jaccard, primary_metric, n_jobs, q_tol, louvain_time_limit, nn_method, partition_type, resolution_parameter, n_iterations, use_weights, seed, **kargs)
    243             "Leiden completed in {} seconds".format(time.time() - tic_), flush=True,
    244         )
--> 245         communities = np.asarray(communities.membership)
    246 
    247         print("Sorting communities by size, please wait ...", flush=True)

/usr/local/lib/python3.8/site-packages/phenograph/core.py in neighbor_graph(kernel, kernelargs)
     82     :return graph: n-by-n COO sparse matrix
     83     """
---> 84     i, j, s = kernel(**kernelargs)
     85     n, k = kernelargs["idx"].shape
     86     graph = sp.coo_matrix((s, (i, j)), shape=(n, n))

/usr/local/lib/python3.8/site-packages/phenograph/core.py in parallel_jaccard_kernel(idx)
    152         graph.data[i] = tup[1]
    153 
--> 154     i, j = graph.nonzero()
    155     s = graph.tocoo().data
    156     return i, j, s[s > 0]

/usr/local/lib/python3.8/site-packages/scipy/sparse/base.py in nonzero(self)
    774 
    775         # convert to COOrdinate format
--> 776         A = self.tocoo()
    777         nz_mask = A.data != 0
    778         return (A.row[nz_mask], A.col[nz_mask])

/usr/local/lib/python3.8/site-packages/scipy/sparse/base.py in tocoo(self, copy)
    904         the resultant coo_matrix.
    905         """
--> 906         return self.tocsr(copy=False).tocoo(copy=copy)
    907 
    908     def tolil(self, copy=False):

/usr/local/lib/python3.8/site-packages/scipy/sparse/lil.py in tocsr(self, copy)
    475         indices = np.empty(nnz, dtype=idx_dtype)
    476         data = np.empty(nnz, dtype=self.dtype)
--> 477         _csparsetools.lil_flatten_to_array(self.rows, indices)
    478         _csparsetools.lil_flatten_to_array(self.data, data)
    479 

_csparsetools.pyx in scipy.sparse._csparsetools.lil_flatten_to_array()

_csparsetools.pyx in scipy.sparse._csparsetools._lil_flatten_to_array_int32()

TypeError: Expected list, got numpy.ndarray
mat10d commented 4 years ago

Getting this same identical issue

prubbens commented 4 years ago

Also since recently. Used to work like a charm previously, before I update some packages. I guess it has to do with the latter. Any solutions?

prubbens commented 4 years ago

I guess it has to do with the dependency on scipy. Downgrading to a previous setup of packages did the trick for me.

mat10d commented 4 years ago

Same here, downgrading made everything work

asmariyaz23 commented 4 years ago

@prubbens @mat10d what version of scipy worked for you?

mat10d commented 4 years ago

1.4.1

prubbens commented 4 years ago

1.4.2. 1.5.X seemed to break the dependencies.

mssher07 commented 4 years ago

Hmmm. I am getting this error with scipy 1.4.1. New install of phenograph so I don't have an older version to roll back to. Hopefully they fix this soon!

giovp commented 4 years ago

Phneograph was recently updated and also new wrappers are available in external thanks to @awnimo @Koncopd . Does this work for you @asmariyaz23 ? I will close this but feel free to reopen

sinnamone commented 3 years ago

I solved the problem after installing with this command:

pip install scipy==1.4.1 --use-feature=2020-resolver

prubbens commented 3 years ago

Still have to use scipy 1.4.1 or 1.4.2. There's now 1.6.1 but this also results in the same error...

giovp commented 3 years ago

maybe @awnimo has more insights on this? meanwhile you can also report this issue in original repo: https://github.com/dpeerlab/PhenoGraph

JulienVerdier commented 3 years ago

I had the same issue using pip3 install git+https://github.com/jacoblevine/phenograph.git that gave version 1.5.2 but it worked using pip install Phenograph==1.5.7

RobTesf commented 2 years ago

I've Phenograph 1.5.7 scipy 1.7.3 and the issue comes up. Tried older versions same issue plus some incompatibility with Phenograph.