squidpy icon indicating copy to clipboard operation
squidpy copied to clipboard

Ligand-receptor plot always report Error

Open ruoyeruolan opened this issue 1 year ago • 4 comments

Description

When I use sq.pl.ligrec after sq.gr.ligrec( adata, n_perms=100, cluster_key="cluster", clusters=["Polydendrocytes", "Oligodendrocytes"], ) , it always report an error 'ValueError: After removing rows with only NaN interactions, none remain'. Is thes normal? I use the data fro tutorials adata = sq.datasets.seqfish() or adata = sq.datasets.slideseqv2(), which do not raise error in examples. How should I solve it? Thanks.

Minimal reproducible example

adata = sq.datasets.seqfish() or adata = sq.datasets.slideseqv2() ...

sq.gr.ligrec( adata, n_perms=100, cluster_key="cluster", clusters=["Polydendrocytes", "Oligodendrocytes"], )

sq.pl.ligrec( adata, cluster_key="cluster", source_groups="Oligodendrocytes", target_groups=["Polydendrocytes"], pvalue_threshold=0.05, swap_axes=True, )

Traceback

ValueError Traceback (most recent call last) Cell In[56], line 1 ----> 1 sq.pl.ligrec( 2 adata, 3 cluster_key="cluster", 4 source_groups="Oligodendrocytes", 5 target_groups=["Polydendrocytes"], 6 pvalue_threshold=0.05, 7 swap_axes=True, 8 )

287 pvals = pvals[pvals <= pvalue_threshold]
289 if remove_empty_interactions:

--> 290 pvals, means = filter_values(pvals, means, mask=~(pd.isnull(means) | pd.isnull(pvals)), kind="NaN") 291 if remove_nonsig_interactions and alpha is not None: 292 pvals, means = filter_values(pvals, means, mask=pvals <= alpha, kind="non-significant")

197 means = means.loc[mask_rows]
199 if pvals.empty:

--> 200 raise ValueError(f"After removing rows with only {kind} interactions, none remain.") 202 mask_cols = mask.any(axis=0) 203 pvals = pvals.loc[:, mask_cols]

ValueError: After removing rows with only NaN interactions, none remain.

Version

python 3.12.4 squidpy==1.6.0

...

ruoyeruolan avatar Aug 09 '24 11:08 ruoyeruolan

hi @ryrl970311 did you normalize and log1p the data before using this function?

giovp avatar Aug 19 '24 08:08 giovp

I also encountered this error. In this new version, even the official example tutorial encounters the same issue.

noob000007 avatar Aug 20 '24 06:08 noob000007

update: tried 1.5.0 from conda-forge and 1.6.1 self-built conda package (from pypi source) got the same error

same here, my code

# hidden code for read in the data
# then preprocess using standard scanpy pipeline
# standard scanpy pipeline for slice1
sc.pp.filter_cells(slice1, min_genes=200)
sc.pp.filter_genes(slice1, min_cells=3)
slice1.raw = slice1
slice1.layers["counts"] = slice1.X.copy()
sc.pp.normalize_total(slice1)
sc.pp.log1p(slice1)
sc.pp.highly_variable_genes(slice1, n_top_genes=2000)
sc.tl.pca(slice1)
sc.pp.neighbors(slice1)
sc.tl.umap(slice1)
sc.tl.leiden(slice1)

# then spatial scatterplot
# see it on the spatial image
sq.pl.spatial_scatter(
    slice1,
    img_res_key="lowres",
    color=["leiden"],
    size=12000,
)

image

# then do the ligand receptor analysis
sq.gr.ligrec(
    slice1,
    n_perms=100,
    cluster_key="leiden",
    use_raw=True,
)
# above runs normally,

# plot fails
sq.pl.ligrec(
    slice1,
    cluster_key="leiden",
    source_groups=["4"],
    target_groups=["1", "2"],
    means_range=(0.1, np.inf),
    alpha=1e-4,
    swap_axes=True,
)

traceback image

TTTPOB avatar Sep 03 '24 14:09 TTTPOB

update, running the code from the tutorial would fail as well (the dataset is from this tutorial as well) https://squidpy.readthedocs.io/en/stable/notebooks/tutorials/tutorial_visium_hne.html#import-packages-data

sq.gr.ligrec(
    adata,
    n_perms=100,
    cluster_key="cluster",
)
sq.pl.ligrec(
    adata,
    cluster_key="cluster",
    source_groups="Hippocampus",
    target_groups=["Pyramidal_layer", "Pyramidal_layer_dentate_gyrus"],
    means_range=(3, np.inf),
    alpha=1e-4,
    swap_axes=True,
)

TTTPOB avatar Sep 03 '24 18:09 TTTPOB

Hello, I’m encountering the same issue. Have there been any updates or resolutions so far?

wxicu avatar Oct 28 '24 09:10 wxicu

I confirmed this error by data adata = sq.datasets.seqfish(), it still report this error. After analysing the data process pipeline, I found that Only four tissues have effective pvalue, others all NA, which led the error. Maybe this is not an Error? Anyone test it on other dataset?

Image

ruoyeruolan avatar Jan 21 '25 17:01 ruoyeruolan

@timtreis how can we check if these values are calculated correctly on these datasets? Is there another implementation we can compare with? I want to know if this is because the dataset is handled incorrectly or there is a bug on permutation test. (I also checked and these errors in fact occur)

selmanozleyen avatar Apr 07 '25 10:04 selmanozleyen