squidpy icon indicating copy to clipboard operation
squidpy copied to clipboard

error loading Nanosctring CosMx dataset

Open GhobrialMoheb opened this issue 1 year ago • 2 comments

Hi, good day. Thank you for the very nice package.

I have an issue loading the Nanostring CosMx dataset: Nanosctring CosMx dataset

Here is the error I am getting:

Traceback (most recent call last): File "/mnt/c/Users/mohebg/Desktop/newscanpyinR/.venv/lib/python3.7/site-packages/scipy/sparse/base.py", line 322, in asformat return convert_method(copy=copy) File "/mnt/c/Users/mohebg/Desktop/newscanpyinR/.venv/lib/python3.7/site-packages/scipy/sparse/coo.py", line 404, in tocsr data = np.empty_like(self.data, dtype=upcast(self.dtype)) File "/mnt/c/Users/mohebg/Desktop/newscanpyinR/.venv/lib/python3.7/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 5, in File "/mnt/c/Users/mohebg/Desktop/newscanpyinR/.venv/lib/python3.7/site-packages/squidpy/read/_read.py", line 215, in nanostring csr_matrix(counts.loc[common_index, :].values), File "/mnt/c/Users/mohebg/Desktop/newscanpyinR/.venv/lib/python3.7/site-packages/scipy/sparse/compressed.py", line 86, in init self._set_self(self.class(coo_matrix(arg1, dtype=dtype))) File "/mnt/c/Users/mohebg/Desktop/newscanpyinR/.venv/lib/python3.7/site-packages/scipy/sparse/compressed.py", line 34, in init arg1 = arg1.asformat(self.format) File "/mnt/c/Users/mohebg/Desktop/newscanpyinR/.venv/lib/python3.7/site-packages/scipy/sparse/base.py", line 324, in asformat return convert_method() File "/mnt/c/Users/mohebg/Desktop/newscanpyinR/.venv/lib/python3.7/site-packages/scipy/sparse/coo.py", line 404, in tocsr data = np.empty_like(self.data, dtype=upcast(self.dtype)) File "/mnt/c/Users/mohebg/Desktop/newscanpyinR/.venv/lib/python3.7/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'),) ...

GhobrialMoheb avatar Oct 05 '23 17:10 GhobrialMoheb

hi @GhobrialMoheb unfortunately I am not able to help with this error message, can you try to create the anndata from the various files instead of reading it with the squidpy function? also I would make sure you have the latest version of squidpy

giovp avatar Oct 06 '23 07:10 giovp

Hi @GhobrialMoheb ,

I tried to load my own CosMx data generated in our facility using squidpy.read.nanostring function and got the same TypeError. Looking into it, it seems that the error was raised because my "<sample_id>_exprMat_file.csv" had an additional column named "cell" which represented cell IDs in string type. The ID values in it were in the format of "c_<slide>_<fov>_<cell_ID>"- e.g.: "c_1_1_1". In my data, it was the third column in the CSV.

I was able to overcome the issue by removing this column using a simple cut function: cut -d, -f3 --complement <sample_id>_exprMat_file.csv > <sample_id>_exprMat_new_file.csv I'm not 100% sure that this was your problem also, but it's worth a try.

Best, Einan

feinan-technion avatar Mar 25 '24 09:03 feinan-technion

Hi @GhobrialMoheb, for loading CosMx datasets efficiently I would highly recommend to use spatialdata-io, which has a reader for CosMx called cosmx().

LLehner avatar Jun 13 '24 12:06 LLehner