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

Can't use sc.pl.spatial - TypeError: can't multiply sequence by non-int of type 'float #2778

Closed
2 of 3 tasks
Rafael-Silva-Oliveira opened this issue Dec 6, 2023 · 4 comments
Labels
Needs info❔ More information needed

Comments

@Rafael-Silva-Oliveira
Copy link

Rafael-Silva-Oliveira commented Dec 6, 2023

Please make sure these conditions are met

  • 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.

What happened?

I'm trying to use sc.pl.spatial with the dataset that is available on 10X Visium with the sample ID CytAssist_FFPE_Human_Lung_Squamous_Cell_Carcinoma

I can open and do some basic QC just fine, but when I try to plot, I get the error TypeError: can't multiply sequence by non-int of type 'float

Minimal code sample

import scanpy as sc
import anndata as an
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
import scanorama

sc.set_figure_params(facecolor="white", figsize=(8, 8))
sc.settings.verbosity = 3


# Loading dataset
adata = sc.read_visium(
    path=r"\external",
    count_file="CytAssist_FFPE_Human_Lung_Squamous_Cell_Carcinoma_filtered_feature_bc_matrix.h5",
    load_images=True,
    source_image_path=r"\spatial",
)

adata.var_names_make_unique()

# Quality control
adata.var["mito"] = adata.var_names.str.startswith("MT-")
sc.pp.calculate_qc_metrics(
    adata, qc_vars=["mito"], percent_top=None, log1p=False, inplace=True
)
sc.pl.spatial(adata)

Error output

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "\scanpy\plotting\_tools\scatterplots.py", line 1002, in spatial
  File "\plotting\_tools\scatterplots.py", line 391, in embedding
    # if user did not set alpha, set alpha to 0.7
  File "\scanpy\plotting\_utils.py", line 1107, in circles
    if scale_factor != 1.0:
TypeError: can't multiply sequence by non-int of type 'float'

The json file on the spatial folder with the scale factors is as follows:

{
  "regist_target_img_scalef": 0.16836435,
  "tissue_hires_scalef": 0.056121446,
  "tissue_lowres_scalef": 0.016836435,
  "fiducial_diameter_fullres": 384.18505640709947,
  "spot_diameter_fullres": 256.12337093806633
}

tissue_hires_scalef is being passed as scale_factor variable and hence why it's throwing the error

Versions

scanpy 1.9.6
@flying-sheep
Copy link
Member

Hi, please provide the data you use, otherwise this is not reproducible:

FileNotFoundError: [Errno 2] Unable to open file (unable to open file: name = '\external/CytAssist_FFPE_Human_Lung_Squamous_Cell_Carcinoma_filtered_feature_bc_matrix.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

@flying-sheep flying-sheep added the Needs info❔ More information needed label Dec 7, 2023
@Rafael-Silva-Oliveira
Copy link
Author

Rafael-Silva-Oliveira commented Dec 7, 2023

Hi, please provide the data you use, otherwise this is not reproducible:

FileNotFoundError: [Errno 2] Unable to open file (unable to open file: name = '\external/CytAssist_FFPE_Human_Lung_Squamous_Cell_Carcinoma_filtered_feature_bc_matrix.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

Hey, the data is publicly available under this link: https://www.10xgenomics.com/resources/datasets/human-lung-cancer-ffpe-2-standard

I simple copied the curl bash script to download all the files and then unzipped the file corresponding to the images to get the "spatial" folder

Rafael-Silva-Oliveira added a commit to Rafael-Silva-Oliveira/scanpy that referenced this issue Dec 8, 2023
Rafael-Silva-Oliveira added a commit to Rafael-Silva-Oliveira/scanpy that referenced this issue Dec 8, 2023
@Rafael-Silva-Oliveira
Copy link
Author

Rafael-Silva-Oliveira commented Dec 8, 2023

@flying-sheep Added this snippet to eval the coordinates as int and not str (plotting > _utils.py > circles, lines 1138 - 1145):

        if not np.issubdtype(x.dtype, np.integer) or not np.issubdtype(
            y.dtype, np.integer
        ):
            try:
                x = x.astype(int)
                y = y.astype(int)
            except ValueError as e:
                print("Error converting to int:", e)

This has solved my issue and can now see the tissue images using sc.pl.spatial. Do feel free to change the code though, this would be my first contribution!

@flying-sheep
Copy link
Member

flying-sheep commented Dec 8, 2023

This was fixed in #2424:

@ivirshup when should we release 1.10?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs info❔ More information needed
Projects
None yet
Development

No branches or pull requests

2 participants