ventolab / CellphoneDB

CellPhoneDB can be used to search for a particular ligand/receptor, or interrogate your own HUMAN single-cell transcriptomics data.
https://www.cellphonedb.org/
MIT License
308 stars 51 forks source link

numpy.core._exceptions._UFuncNoLoopError #74

Closed yjjeong86 closed 1 year ago

yjjeong86 commented 1 year ago

Hello,

Thanks for the great tools. I am new to bioinformatic analysis and running into the following error and hope you can help me to resolve it.

[ ][CORE][02/11/22-12:06:20][INFO] Initializing SqlAlchemy CellPhoneDB Core [ ][CORE][02/11/22-12:06:20][INFO] Using custom database at /Users/youngjaejeong/.cpdb/releases/v4.0.0/cellphone.db [ ][APP][02/11/22-12:06:20][INFO] Launching Method cpdb_analysis_local_method_launcher [ ][APP][02/11/22-12:06:20][INFO] Launching Method _set_paths [ ][APP][02/11/22-12:06:20][INFO] Launching Method _load_meta_counts [ ][APP][02/11/22-12:06:24][INFO] Launching Method _check_counts_data [ ][CORE][02/11/22-12:06:24][INFO] Launching Method cpdb_method_analysis_launcher [ ][CORE][02/11/22-12:06:24][INFO] Launching Method _counts_validations [ ][CORE][02/11/22-12:06:24][INFO] Launching Method get_interactions_genes_complex [ ][CORE][02/11/22-12:06:24][INFO] [Non Statistical Method] Threshold:0.1 Precision:3 [ ][CORE][02/11/22-12:06:25][INFO] Running Real Analysis [ ][APP][02/11/22-12:06:25][ERROR] Unexpected error Traceback (most recent call last): File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/pandas/core/ops/array_ops.py", line 143, in na_arithmetic_op result = expressions.evaluate(op, left, right) File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/pandas/core/computation/expressions.py", line 233, in evaluate return _evaluate(op, op_str, a, b) # type: ignore File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/pandas/core/computation/expressions.py", line 68, in _evaluate_standard return op(a, b) numpy.core._exceptions._UFuncNoLoopError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U21'), dtype('<U21')) -> dtype('<U21')

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/cellphonedb/src/api_endpoints/terminal_api/method_terminal_api_endpoints/method_terminal_commands.py", line 216, in analysis debug, File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/cellphonedb/src/local_launchers/local_method_launcher.py", line 119, in cpdb_analysis_local_method_launcher output_path) File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/cellphonedb/src/core/methods/method_launcher.py", line 155, in cpdb_method_analysis_launcher output_path) File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/cellphonedb/src/core/methods/cpdb_analysis_method.py", line 108, in call separator) File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/cellphonedb/src/core/methods/cpdb_statistical_analysis_helper.py", line 361, in mean_analysis columns=(pd.Series(cluster1_names) + separator + pd.Series(cluster2_names)).values) File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/pandas/core/ops/common.py", line 65, in new_method return method(self, other) File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/pandas/core/ops/init.py", line 343, in wrapper result = arithmetic_op(lvalues, rvalues, op) File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/pandas/core/ops/array_ops.py", line 190, in arithmetic_op res_values = na_arithmetic_op(lvalues, rvalues, op) File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/pandas/core/ops/array_ops.py", line 150, in na_arithmetic_op result = masked_arith_op(left, right, op) File "/opt/anaconda3/envs/cpdb/lib/python3.6/site-packages/pandas/core/ops/array_ops.py", line 112, in masked_arith_op result[mask] = op(xrav[mask], y) numpy.core._exceptions._UFuncNoLoopError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U21'), dtype('<U21')) -> dtype('<U21')

I have created text files by doing the following in the R

counts <- as.data.frame( as.matrix( cluster@assays$RNA@data) ) mouse_genes<-rownames(counts)

human <- useMart("ensembl", dataset = "hsapiens_gene_ensembl", host = "https://dec2021.archive.ensembl.org/") mouse <- useMart("ensembl", dataset = "mmusculus_gene_ensembl", host = "https://dec2021.archive.ensembl.org/")

genesV2 = getLDS(attributes = c("mgi_symbol"), filters = "mgi_symbol", values = mouse_genes , mart = mouse, attributesL = c("hgnc_symbol",'ensembl_gene_id'), martL = human, uniqueRows=F)

genesV2$Gene.stable.ID<-as.character(genesV2$Gene.stable.ID) genesV2$MGI.symbol<-as.character(genesV2$MGI.symbol) genesV2<-genesV2[!duplicated(genesV2$Gene.stable.ID),] genesV2<-genesV2[!duplicated(genesV2$MGI.symbol),] counts<-counts[genesV2$MGI.symbol,] rownames(counts)<-genesV2$Gene.stable.ID metadata <- data.frame(Cell = colnames(counts), cell_type = as.character(cluster@active.ident) )

metadata$Cell<-gsub('\-','\.',metadata$Cell) counts<-na.omit(counts) counts$Gene<-rownames(counts) counts<-counts[,c(ncol(counts), 1:(ncol(counts)-1))] colnames(counts)<-gsub('\-','\.',colnames(counts))

write.table(counts, file ='counts.txt', quote = F, col.names = T, row.names = F, sep = '\t')

write.table(metadata, file ='metadata.txt', quote = F, col.names = T, row.names = F, sep = '\t')

Thank you,

prete commented 1 year ago

Hi @yjjeong86, thank you for using CellPhoneDB. Can we do a quick version check before suggesting alternatives? What's the output of pip show numpy pandas in your environment?

yjjeong86 commented 1 year ago

Thanks for the quick response @prete. The output is as following

Name: numpy Version: 1.19.5 Summary: NumPy is the fundamental package for array computing with Python. Home-page: https://www.numpy.org Author: Travis E. Oliphant et al. Author-email: License: BSD Location: /opt/anaconda3/lib/python3.9/site-packages Requires: Required-by: anndata, astropy, basemap, bkcharts, bokeh, Bottleneck, cellrank, daal4py, datashader, datashape, gensim, h5py, hnswlib, holoviews, hvplot, imagecodecs, imageio, loompy, matplotlib, mkl-fft, mkl-random, numba, numexpr, pandas, patsy, pyerfa, pygam, pygpcca, PyWavelets, scanpy, scikit-image, scikit-learn, scipy, scrublet, scvelo, seaborn, statsmodels, tables, tifffile, umap-learn, xarray

Name: pandas Version: 1.1.4 Summary: Powerful data structures for data analysis, time series, and statistics Home-page: https://pandas.pydata.org Author: Author-email: License: BSD Location: /opt/anaconda3/lib/python3.9/site-packages Requires: numpy, python-dateutil, pytz Required-by: anndata, cellrank, datashader, holoviews, hvplot, scanpy, scrublet, scvelo, seaborn, statsmodels, xarray

prete commented 1 year ago

Hi @yjjeong86 those do look like the right versions. Could you check that the cluster/cell types on your meta file are not just numbers? if they are, could you please try changing them to strings by renaming them with something like cluster_1 instead of just simply1.

yjjeong86 commented 1 year ago

@prete It worked out. Thanks for the quick answers and solutions!