Starlitnightly / omicverse

A python library for multi omics included bulk, single cell and spatial RNA-seq analysis.
https://starlitnightly.github.io/omicverse/
GNU General Public License v3.0
469 stars 57 forks source link

an error about cnmf_obj #147

Closed yanbosmu closed 1 month ago

yanbosmu commented 2 months ago

When I was running CNMF,

import numpy as np Initialize the cnmf object that will be used to run analyses cnmf_obj = ov.single.cNMF(adata,components=np.arange(5,11), n_iter=20, seed=14, num_highvar_genes=2000, output_dir='example_dg/cNMF', name='dg_cNMF')

The error showed as below.

TypeError Traceback (most recent call last) Cell In[16], line 3 1 import numpy as np 2 ## Initialize the cnmf object that will be used to run analyses ----> 3 cnmf_obj = ov.single.cNMF(adata,components=np.arange(5,11), n_iter=20, seed=14, num_highvar_genes=2000, 4 output_dir='example_dg/cNMF', name='dg_cNMF')

File /data/Conda_envs/your_path/omicverse/lib/python3.10/site-packages/omicverse/single/_cnmf.py:222, in cNMF.init(self, adata, components, n_iter, densify, tpm_fn, seed, beta_loss, num_highvar_genes, genes_file, alpha_usage, alpha_spectra, init, output_dir, name) 220 self.paths = None 221 self._initialize_dirs() --> 222 self.prepare(adata, components, n_iter, densify, tpm_fn, seed, 223 beta_loss, num_highvar_genes, genes_file, 224 alpha_usage, alpha_spectra, init)

File /data/Conda_envs/your_path/omicverse/lib/python3.10/site-packages/omicverse/single/_cnmf.py:316, in cNMF.prepare(self, adata, components, n_iter, densify, tpm_fn, seed, beta_loss, num_highvar_genes, genes_file, alpha_usage, alpha_spectra, init) 313 input_counts.X = np.array(input_counts.X.todense()) 315 if tpm_fn is None: --> 316 tpm = compute_tpm(input_counts) 317 sc.write(self.paths['tpm'], tpm) 318 elif tpm_fn.endswith('.h5ad'):

File /data/Conda_envs/your_path/omicverse/lib/python3.10/site-packages/omicverse/single/_cnmf.py:186, in compute_tpm(input_counts) 182 """ 183 Default TPM normalization 184 """ 185 tpm = input_counts.copy() --> 186 sc.pp.normalize_per_cell(tpm, counts_per_cell_after=1e6) 187 return(tpm)

File /data/Conda_envs/your_path/omicverse/lib/python3.10/site-packages/scanpy/preprocessing/_simple.py:566, in normalize_per_cell(data, counts_per_cell_after, counts_per_cell, key_n_counts, copy, layers, use_rep, min_counts) 564 adata = data.copy() if copy else data 565 if counts_per_cell is None: --> 566 cell_subset, counts_per_cell = materialize_as_ndarray( 567 filter_cells(adata.X, min_counts=min_counts) 568 ) 569 adata.obs[key_n_counts] = counts_per_cell 570 adata._inplace_subset_obs(cell_subset)

File /data/Conda_envs/your_path/omicverse/lib/python3.10/site-packages/scanpy/preprocessing/_distributed.py:45, in materialize_as_ndarray(a) 42 return np.asarray(a) 44 if not any(isinstance(arr, DaskArray) for arr in a): ---> 45 return tuple(np.asarray(arr) for arr in a) 47 import dask.array as da 49 return da.compute(*a, sync=True)

File /data/Conda_envs/your_path/omicverse/lib/python3.10/site-packages/scanpy/preprocessing/_distributed.py:45, in (.0) 42 return np.asarray(a) 44 if not any(isinstance(arr, DaskArray) for arr in a): ---> 45 return tuple(np.asarray(arr) for arr in a) 47 import dask.array as da 49 return da.compute(*a, sync=True)

File cupy/_core/core.pyx:1481, in cupy._core.core._ndarray_base.array()

TypeError: Implicit conversion to a NumPy array is not allowed. Please use .get() to construct a NumPy array explicitly.

Starlitnightly commented 2 months ago

Maybe you need to update scanpy, numpy and pandas to newlest version using pip install -U scanpy