BayraktarLab / cell2location

Comprehensive mapping of tissue cell architecture via integrated single cell and spatial transcriptomics (cell2location model)
https://cell2location.readthedocs.io/en/latest/
Apache License 2.0
324 stars 58 forks source link

plot spatial error with multiple slides #321

Closed jil100 closed 1 year ago

jil100 commented 1 year ago

I followed the latest tutorial (https://cell2location.readthedocs.io/en/latest/notebooks/cell2location_tutorial.html) and was able to reproduce the results successfully. When I used my own data with multiple slides, I followed the tutorial (https://cell2location.readthedocs.io/en/latest/notebooks/cell2location_short_demo.html#1.-Loading-Visium-data) to load the visium data, then proceeded with the latest tutorial. An error occurred as follows:

fig = mod.plot_spatial_QC_across_batches()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/il55/cell2loc_env/lib/python3.9/site-packages/cell2location/models/_cell2location_model.py", line 421, in plot_spatial_QC_across_batches
    scanpy.pl.spatial(
  File "/home/il55/cell2loc_env/lib/python3.9/site-packages/scanpy/plotting/_tools/scatterplots.py", line 1002, in spatial
    axs = embedding(
  File "/home/il55/cell2loc_env/lib/python3.9/site-packages/scanpy/plotting/_tools/scatterplots.py", line 391, in embedding
    cax = scatter(
  File "/home/il55/cell2loc_env/lib/python3.9/site-packages/scanpy/plotting/_utils.py", line 1107, in circles
    x = x * scale_factor
TypeError: can't multiply sequence by non-int of type 'float'

The same error occurred when I tried to plot cell abundance in spatial coordinates:

from cell2location.utils import select_slide
slide = select_slide(adata_vis, 'A1')

with mpl.rc_context({'axes.facecolor':  'black',
                     'figure.figsize': [4.5, 5]}):
    sc.pl.spatial(slide, cmap='magma',
                  color=['CD14+Mo', 'CD16+Mo', 'MoMP', 'LYVE1+IGF1+MP', 'LYVE1+TIMD4+MP',
                  'LYVE1+MP_cycling', 'DC', 'Neut'],
                  ncols=4, size=1.3,
                  img_key='hires',
                  # limit color scale at 99.2% quantile of cell abundance
                  vmin=0, vmax='p99.2'
                 )
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/home/il55/cell2loc_env/lib/python3.9/site-packages/scanpy/plotting/_tools/scatterplots.py", line 1002, in spatial
    axs = embedding(
  File "/home/il55/cell2loc_env/lib/python3.9/site-packages/scanpy/plotting/_tools/scatterplots.py", line 391, in embedding
    cax = scatter(
  File "/home/il55/cell2loc_env/lib/python3.9/site-packages/scanpy/plotting/_utils.py", line 1107, in circles
    x = x * scale_factor
TypeError: can't multiply sequence by non-int of type 'float'
vitkl commented 1 year ago

Hi @jil100

as you note with your second example, this is an issue with scanpy spatial plotting (related to scale_factor) rather than with cell2location. Can you plot the expression of genes? If you get the same error with gene plotting I would suggest creating an issue with scanpy package.

jil100 commented 1 year ago

@vitkl Thank you for your quick response. It was indeed an issue with scanpy spatial plotting.