zhengrongbin / MEBOCOST

A python-based package and software to predict metabolite mediated cell-cell communications by single-cell RNA-seq data
BSD 3-Clause "New" or "Revised" License
63 stars 10 forks source link

urgent! TypeError: no supported conversion for types: (dtype('O'),) #8

Closed jiangzh-coder closed 7 months ago

jiangzh-coder commented 1 year ago

i met following error, should i do this software by using server? what i do is to transfer a expression matrix into python environment by following sentence: exp_mat = pd.read_csv(your_exp_data_file)

mebo_obj = mebocost.create_obj( ... adata = None, ... group_col = ['majorcelltype'], ... met_est = 'mebocost', ... config_path = './mebocost.conf', ... exp_mat=exp_mat, ... cell_ann=cell_ann, ... species='human', ... met_pred=None, ... met_enzyme=None, ... met_sensor=None, ... met_ann=None, ... scFEA_ann=None, ... compass_met_ann=None, ... compass_rxn_ann=None, ... gene_network=None, ... gmt_path=None, ... cutoff_exp='auto', ... cutoff_met='auto', ... cutoff_prop=0.25, ... sensortype=['Receptor', 'Transporter', 'Nuclear Receptor'], ... thread=8 ... ) Traceback (most recent call last): File "C:\Users\zhou\miniconda3\envs\mebocost\lib\site-packages\scipy\sparse_base.py", line 376, in asformat return convertmethod(copy=copy) File "C:\Users\zhou\miniconda3\envs\mebocost\lib\site-packages\scipy\sparse_coo.py", line 361, in tocsc data = np.emptylike(self.data, dtype=upcast(self.dtype)) File "C:\Users\zhou\miniconda3\envs\mebocost\lib\site-packages\scipy\sparse_sputils.py", line 51, in upcast raise TypeError('no supported conversion for types: %r' % (args,)) TypeError: no supported conversion for types: (dtype('O'),)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "C:\Users\zhou\miniconda3\envs\mebocost\lib\site-packages\mebocost-1.0.3-py3.10.egg\mebocost\mebocost.py", line 348, in init File "C:\Users\zhou\miniconda3\envs\mebocost\lib\site-packages\scipy\sparse_compressed.py", line 84, in init self._setself(self.class( File "C:\Users\zhou\miniconda3\envs\mebocost\lib\site-packages\scipy\sparse_compressed.py", line 33, in init arg1 = arg1.asformat(self.format) File "C:\Users\zhou_\miniconda3\envs\mebocost\lib\site-packages\scipy\sparse_base.py", line 378, in asformat return convertmethod() File "C:\Users\zhou\miniconda3\envs\mebocost\lib\site-packages\scipy\sparse_coo.py", line 361, in tocsc data = np.emptylike(self.data, dtype=upcast(self.dtype)) File "C:\Users\zhou\miniconda3\envs\mebocost\lib\site-packages\scipy\sparse_sputils.py", line 51, in upcast raise TypeError('no supported conversion for types: %r' % (args,)) TypeError: no supported conversion for types: (dtype('O'),)

zhengrongbin commented 1 year ago

Hi - Thanks for your interest! I guess this problem happens when converting a python data frame to the sparse matrix by scipy package. May I have the version of scipy in your python?

jiangzh-coder commented 1 year ago

import scipy scipy.version '1.9.3' 是 1.9.3

jiangzh-coder commented 1 year ago

i reinstall scipy by version 1.8.1, the error still: image

jiangzh-coder commented 1 year ago

i tried to modify Seurat file format as .H5ad. However, When i loaded this .H5ad file into Python enviroment by using scanpy, it always showed that ONLY 2000 genes(scale.data gene amount), but i need raw data! Therefore, i am wondering what is scRNAseq data you used in the begining? Is it not normalized (counts data)? My results are as following:

image

zhengrongbin commented 1 year ago

i tried to modify Seurat file format as .H5ad. However, When i loaded this .H5ad file into Python enviroment by using scanpy, it always showed that ONLY 2000 genes(scale.data gene amount), but i need raw data! Therefore, i am wondering what is scRNAseq data you used in the begining? Is it not normalized (counts data)? My results are as following:

image

We recommend using normalized expression data rather than count data. If only 2000 genes, highly possible that your seurat object saved only variable genes to the h5ad, you may want to check if you have all genes in your seurat object. If you have all genes in your seurat object, it should be in [["RNA"]]@data. I would recommend outputting expression data and metadata to separate files and read into Python by pandas as our tutorial suggested. Because some users reported h5ad formatting problems from seurat. Also, it seems likely your adata does not have obs which is cell annotation (same with metadata in seurat). Hopefully these help you solve the problem!

zhengrongbin commented 1 year ago

i reinstall scipy by version 1.8.1, the error still: image

It is good to know the version is not the problem. According to the error report, I suspect the problem comes from the data frame (exp_mat) where the data type was an object rather than a float. To help me confirm this, Could you please show me your exp_mat? You can just show me the top lines and check the data type for some columns in your data, for example by doing the following in python:

exp_mat.head()

and

exp_mat.iloc[0].dtype
mellyS commented 1 year ago

Hi, I had a similar issue but was able to solve it by saving separately the expression matrix & metadata in two separated files that I loaded on python. The error came from the "gene names" column that remained in the matrix when converting it to a sparse matrix.

haukeh90 commented 1 year ago

Dear Dr Zheng, Thank you for providing this valuable tool! Similar to the aforementioned issue, I get the following Error when setting up the Mebocost object from the normalized expression matrix and meta data (cell annotation) from Seurat: TypeError: no supported conversion for types: (dtype('O'),)

Have you figured out any solution already?

It is possible to setup the object from adata object after converting from Seurat. However, only 2500 genes are transferred as previously reported.

Thank you in advance for your help.

zhengrongbin commented 1 year ago

Hi, I had a similar issue but was able to solve it by saving separately the expression matrix & metadata in two separated files that I loaded on python. The error came from the "gene names" column that remained in the matrix when converting it to a sparse matrix.

Hello - I think this is one of the most possible reasons. You can check your expression matrix in adata to see if they are all floats. For the 2500 genes problem, I think you only saved expression data for variable genes from Seurat. Here provides a solution at https://github.com/mojaveazure/seurat-disk/issues/75