scverse / squidpy

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

Error of <sq.pl.spatial_scatter()> by analyzing FFPE Visium data #623

Closed sps-01 closed 1 year ago

sps-01 commented 1 year ago

Description

Hi, Whenever we are trying in our FFPE Visium data to visualize cluster annotation in spatial context with squidpy.pl.spatial_scatter() an error occurs stating that it "can't multiply sequence by non-int of type 'float'"

Minimal reproducible example

We get this following error: Bildschirmfoto 2022-11-21 um 16 44 35 by using this command:

sq.pl.spatial_scatter(adata, color='clusters')

We are getting the same error by using the corresponding scanpy command:

sc.pl.spatial(adata, color='clusters')

You can reproduce the error by downloading the example FFPE Visium data set of 10X 10X Genomics example data set of FFPE Visium

Version

1.2.2.

michalk8 commented 1 year ago

Hi @sps-01 , can you please check whether the spatial coordinates stored adata.obsm[...] is a numpy.array?

sps-01 commented 1 year ago

Hi, yes, we checked it and it is.

michalk8 commented 1 year ago

Thanks for checking this. This means that the scalefactor is somehow wrong, will investigate.

michalk8 commented 1 year ago

I can't reproduce it with that data, here are my versions (running scanpy.loggings.print_versions() and print(squidpy.__full_version__):

```bash ----- anndata 0.8.0 scanpy 1.9.1 ----- PIL 9.3.0 PyQt5 NA appdirs 1.4.4 asciitree NA asttokens NA awkward 1.5.1 babel 2.9.1 backcall 0.2.0 cachey 0.2.1 cffi 1.15.0 cloudpickle 2.2.0 colorama 0.4.5 cycler 0.10.0 cython_runtime NA dask 2022.12.0 dask_image 2022.09.0 dateutil 2.8.2 debugpy 1.6.3 decorator 5.1.1 defusedxml 0.7.1 docrep 0.3.2 docstring_parser NA entrypoints 0.4 executing 1.0.0 fasteners 0.18 fsspec 2022.11.0 google NA h5py 3.7.0 heapdict NA hsluv 5.0.2 igraph 0.10.2 imageio 2.22.4 intervaltree NA ipykernel 6.15.3 ipython_genutils 0.2.0 ipywidgets 8.0.2 jedi 0.18.1 jinja2 3.1.2 joblib 1.2.0 kiwisolver 1.4.4 leidenalg 0.9.0 llvmlite 0.38.1 louvain 0.7.1 magicgui 0.3.7 markupsafe 2.1.1 matplotlib 3.6.2 matplotlib_scalebar 0.8.1 mpl_toolkits NA msgpack 1.0.4 napari 0.4.15 natsort 8.2.0 networkx 2.8.8 npe2 0.1.2 numba 0.55.2 numcodecs 0.10.2 numpy 1.22.4 numpydoc 1.2 packaging 21.3 pandas 1.5.2 parso 0.8.3 pexpect 4.8.0 pickleshare 0.7.5 pkg_resources NA plotly 5.9.0 prompt_toolkit 3.0.31 psutil 5.9.2 psygnal 0.3.3 ptyprocess 0.7.0 pure_eval 0.2.2 pyarrow 8.0.0 pycparser 2.21 pydantic 1.10.2 pydev_ipython NA pydevconsole NA pydevd 2.8.0 pydevd_file_utils NA pydevd_plugins NA pydevd_tracing NA pygments 2.13.0 pyparsing 3.0.9 pytomlpp NA pytz 2022.6 pywt 1.4.1 qtpy 2.0.1 scipy 1.9.3 seaborn 0.12.1 session_info 1.0.0 setuptools 65.6.3 setuptools_scm NA sip NA six 1.16.0 skimage 0.19.3 sklearn 1.1.3 sortedcontainers 2.4.0 sparse 0.13.0 sphinxcontrib NA squidpy 1.2.3 stack_data 0.5.0 statsmodels 0.13.5 superqt 0.2.5.post1 texttable 1.6.7 threadpoolctl 3.1.0 tifffile 2022.10.10 tlz 0.12.0 toolz 0.12.0 tornado 6.2 tqdm 4.64.1 traitlets 5.4.0 typing_extensions NA validators 0.20.0 vispy 0.9.6 wcwidth 0.2.5 wrapt 1.14.1 xarray 2022.11.0 yaml 6.0 zarr 2.13.3 zipp NA zmq 24.0.1 ----- IPython 8.5.0 jupyter_client 7.3.5 jupyter_core 4.11.1 notebook 6.4.12 ----- Python 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:18) [GCC 10.3.0] Linux-5.10.0-19-amd64-x86_64-with-glibc2.10 ----- Session information updated at 2022-12-02 22:34 ```

squidpy='1.2.3+g3d19b33.d20221202'

Given that this error happens both in scanpy/squidpy, I'd suspect some issue with numpy or some platform-specific issue (I tried it locally on Debian, will try on Mac later).

hmassalha commented 1 year ago

I had the same issue. This line solved it for me adata.obsm['spatial'] = adata.obsm['spatial'].astype(np.float)

giovp commented 1 year ago

another points to check would possibly be the scalefactors in adata.uns ?

sps-01 commented 1 year ago

Perfect, thanks a lot for all help. This line (adata.obsm['spatial'] = adata.obsm['spatial'].astype(np.float)) works for me as well!