Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scanpy.pl.spatial TypeError: can't multiply sequence by non-int of type 'float' #2391

Closed
2 of 3 tasks
cf98 opened this issue Dec 29, 2022 · 4 comments
Closed
2 of 3 tasks

Comments

@cf98
Copy link

cf98 commented Dec 29, 2022

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the master branch of scanpy.

Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

It is hard to show the error without my data, but here it is what I did. I read in my 10 visium data (output from SpaceRanger 2.0.0) and everything seems fine. All I had to do was to change a file name (tissue_positions.csv to tissue_positions_list.csv) in my outs/spatial folder.

healthy_A1 = sc.read_visium('../data/MGI3535_A1_010322NHK/outs/', count_file='raw_feature_bc_matrix.h5')

I calculated qc metrics with this command.

sc.pp.calculate_qc_metrics(healthy_A1, percent_top=None, log1p=False, inplace=True)

But then, the problem occurs when I try to use scanpy.pl.spatial

Minimal code sample (that we can copy&paste without having any data)

sc.pl.spatial(healthy_A1, img_key = "hires", color = "total_counts") 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_1314047/3602867448.py in <module>
----> 1 sc.pl.spatial(healthy_A1, img_key = "hires", color = "ACTA2")

~/.conda/envs/python_spatial/lib/python3.7/site-packages/scanpy/plotting/_tools/scatterplots.py in spatial(adata, basis, img, img_key, library_id, crop_coord, alpha_img, bw, size, scale_factor, spot_size, na_color, show, return_fig, save, **kwargs)
   1009         show=False,
   1010         save=False,
-> 1011         **kwargs,
   1012     )
   1013     if not isinstance(axs, list):

~/.conda/envs/python_spatial/lib/python3.7/site-packages/scanpy/plotting/_tools/scatterplots.py in embedding(adata, basis, color, gene_symbols, use_raw, sort_order, edges, edges_width, edges_color, neighbors_key, arrows, arrows_kwds, groups, components, dimensions, layer, projection, scale_factor, color_map, cmap, palette, na_color, na_in_legend, size, frameon, legend_fontsize, legend_fontweight, legend_loc, legend_fontoutline, colorbar_loc, vmax, vmin, vcenter, norm, add_outline, outline_width, outline_color, ncols, hspace, wspace, title, show, save, ax, return_fig, **kwargs)
    397                 rasterized=settings._vector_friendly,
    398                 norm=normalize,
--> 399                 **kwargs,
    400             )
    401 

~/.conda/envs/python_spatial/lib/python3.7/site-packages/scanpy/plotting/_utils.py in circles(x, y, s, ax, marker, c, vmin, vmax, scale_factor, **kwargs)
   1106     # while you can only set `facecolors` with a value for all.
   1107     if scale_factor != 1.0:
-> 1108         x = x * scale_factor
   1109         y = y * scale_factor
   1110     zipped = np.broadcast(x, y, s)

TypeError: can't multiply sequence by non-int of type 'float'

Bascially, the same type of error keeps showing up no matter what the color = parameter is. I put a gene name there, and the same message showed up.

Additional information about the error (the image that showed up together with the error message from the jupyter notebook cell): image

Versions


anndata 0.8.0
scanpy 1.9.1

PIL 9.2.0
annoy NA
asciitree NA
backcall 0.2.0
beta_ufunc NA
binom_ufunc NA
cffi 1.15.1
cloudpickle 2.2.0
cycler 0.10.0
cython_runtime NA
dask 2022.02.0
dateutil 2.8.2
debugpy 1.6.3
decorator 5.1.1
defusedxml 0.7.1
entrypoints 0.4
fasteners 0.18
fbpca NA
fsspec 2022.11.0
google NA
h5py 3.7.0
igraph 0.10.2
intervaltree NA
ipykernel 6.16.2
ipython_genutils 0.2.0
ipywidgets 8.0.4
jedi 0.18.2
jinja2 3.1.2
joblib 1.2.0
jupyter_server 1.23.4
kiwisolver 1.4.4
leidenalg 0.9.1
llvmlite 0.39.1
markupsafe 2.1.1
matplotlib 3.5.3
matplotlib_inline 0.1.6
mpl_toolkits NA
msgpack 1.0.4
natsort 8.2.0
nbinom_ufunc NA
numba 0.56.4
numcodecs 0.10.2
numpy 1.21.6
packaging 22.0
pandas 1.3.5
parso 0.8.3
pexpect 4.8.0
pickleshare 0.7.5
pkg_resources NA
prompt_toolkit 3.0.36
psutil 5.9.3
ptyprocess 0.7.0
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
pytz 2022.7
scanorama 1.7.1
scipy 1.7.3
seaborn 0.12.1
session_info 1.0.0
setuptools 65.6.3
six 1.16.0
sklearn 1.0.2
sortedcontainers 2.4.0
statsmodels 0.13.5
storemagic NA
texttable 1.6.7
threadpoolctl 3.1.0
tlz 0.12.0
toolz 0.12.0
tornado 6.2
traitlets 5.8.0
typing_extensions NA
wcwidth 0.2.5
yaml 6.0
zarr 2.12.0
zipp NA
zmq 24.0.1

IPython 7.33.0
jupyter_client 7.4.8
jupyter_core 4.11.1
jupyterlab 3.5.2
notebook 6.5.2

Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:21) [GCC 9.4.0]
Linux-5.4.0-121-generic-x86_64-with-debian-bullseye-sid

Session information updated at 2022-12-28 21:40

@cf98
Copy link
Author

cf98 commented Dec 29, 2022

This seems to be a compatibility issue with outputs from SpaceRanger 2.0.0.
Following this issue on Seurat, I was finally able to solve it.
Please consider an official fix for this. I am new to github and still trying to figure out how to do a pull request. Thanks! @falexwolf

@cf98 cf98 closed this as completed Dec 29, 2022
@alexcwsmith
Copy link

Hi @cf98 what was the fix for this? Did you revert to SpaceRanger 1.0, or did you find a way to make scanPy compatible with SpaceRanger 2.0? I didn't see anything directly applicable to this in the Seurat thread.
Thanks!

@cf98
Copy link
Author

cf98 commented Feb 1, 2023

Hi Alex,

I basically followed the discussion thread in Seurat: remove the header of the tissue_positions.csv, and change this file name to tissue_positions_list.csv.

Based on the discussion of another thread, the scanpy authors are maintaining squidpy for the spatial transcriptomics part. If you use the squidpy function to load the data, there's no such issue (they considered the versions in their code).

Best,
Changfeng

@swainasish
Copy link

@cf98 Thank you its work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants