scverse / squidpy

Spatial Single Cell Analysis in Python
https://squidpy.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
401 stars 72 forks source link

error loading Nanosctring CosMx dataset #757

Closed GhobrialMoheb closed 3 weeks ago

GhobrialMoheb commented 9 months ago

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'),) ...

giovp commented 9 months ago

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

feinan-technion commented 3 months ago

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 "_exprMatfile.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>_"- 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

LLehner commented 3 weeks ago

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