cNMF
cNMF copied to clipboard
Cannot cast ufunc 'divide' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'
Hi.
While performing tutorial code, I got a problem.
I installed cnmf followed by your instruction and performed "simulated data".
But, when I did #6 line, I got an error message.
#6 cnmf_obj.prepare(counts_fn=countfn, components=K, n_iter=numiter, seed=seed, num_highvar_genes=numhvgenes)
UFuncTypeError Traceback (most recent call last) Cell In[6], line 1 ----> 1 cnmf_obj.prepare(counts_fn=countfn, components=K, n_iter=numiter, seed=seed, num_highvar_genes=numhvgenes)
File ~/anaconda3/envs/cnmf_env/lib/python3.11/site-packages/cnmf/cnmf.py:320, in cNMF.prepare(self, counts_fn, components, n_iter, densify, tpm_fn, seed, beta_loss, num_highvar_genes, genes_file, alpha_usage, alpha_spectra, init) 317 input_counts.X = np.array(input_counts.X.todense()) 319 if tpm_fn is None: --> 320 tpm = compute_tpm(input_counts) 321 sc.write(self.paths['tpm'], tpm) 322 elif tpm_fn.endswith('.h5ad'):
File ~/anaconda3/envs/cnmf_env/lib/python3.11/site-packages/cnmf/cnmf.py:183, in compute_tpm(input_counts) 179 """ 180 Default TPM normalization 181 """ 182 tpm = input_counts.copy() --> 183 sc.pp.normalize_per_cell(tpm, counts_per_cell_after=1e6) 184 return(tpm)
File ~/anaconda3/envs/cnmf_env/lib/python3.11/site-packages/scanpy/preprocessing/_simple.py:527, in normalize_per_cell(data, counts_per_cell_after, counts_per_cell, key_n_counts, copy, layers, use_rep, min_counts) 525 adata._inplace_subset_obs(cell_subset) 526 counts_per_cell = counts_per_cell[cell_subset] --> 527 normalize_per_cell(adata.X, counts_per_cell_after, counts_per_cell) 529 layers = adata.layers.keys() if layers == 'all' else layers 530 if use_rep == 'after':
File ~/anaconda3/envs/cnmf_env/lib/python3.11/site-packages/scanpy/preprocessing/_simple.py:562, in normalize_per_cell(data, counts_per_cell_after, counts_per_cell, key_n_counts, copy, layers, use_rep, min_counts) 560 warnings.simplefilter("ignore") 561 counts_per_cell += counts_per_cell == 0 --> 562 counts_per_cell /= counts_per_cell_after 563 if not issparse(X): 564 X /= materialize_as_ndarray(counts_per_cell[:, np.newaxis])
UFuncTypeError: Cannot cast ufunc 'divide' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'
What should I do?
I encountered the same problem as you. May I ask how you solved it?
I encountered the same problem as you. May I ask how you solved it?
I encountered the same problem as you. May I ask how you solved it?
I was able to fix this error by going into the cnmf.py script and changing sc.pp.normalize_per_cell()
to sc.pp.normalize_total()
as was suggested in #67
Is anyone on the team fixing this so we don't have to edit the source code or cnmf.py script? Thanks! @dylkot
I see you are using python v3.11. Could you try re-installing the cnmf into a fresh conda env with specifically the version 3.7 of python? I have a hunch that might be the issue here
conda deactivate
conda remove -n cnmf_env --all
conda create -n cnmf_env --yes --channel bioconda --channel conda-forge --channel defaults python=3.7 fastcluster matplotlib numpy palettable pandas scipy 'scikit-learn>=1.0' pyyaml 'scanpy>=1.8' && conda clean --yes --all
conda activate cnmf_env
pip install cnmf
PS this won't work if you have an arm64 machine, as there is no python below 3.8 for that arch. You'll have to go with the hack proposed by @avdl25
Hi All, I fixed this issue on the development branch using sc.pp.normalize_total() as was suggested. Sorry for being so slow to get to this.
I will update on this thread when I push it to the master branch and to pypi
Thanks for pointing this out!
OK closing it now since it is updated on the main branch and in pypi version 1.5.2