This is a test version of Biostars. For the public version, visit https://www.biostars.org.
error plotting spatial data in scanpy

Hello everyone

I am following https://nbisweden.github.io/workshop-scRNAseq/labs/compiled/scanpy/scanpy_07_spatial.html for the spatial transcriptome data. Every thing works fine. I tried same code for the my custom datasets with four samples. I performed all steps : QC filtration -> integration -> dimensionality reduction and clustering analysis.

For visulization of spatial data, I used sc.pl.spatial function.

library_names = ["A1", "B1","C1","D1"]

for library in library_names:
    sc.pl.spatial(adata[adata.obs.library_id == library,:], library_id=library, color = ["total_counts", "n_genes_by_counts",'pct_counts_mt', 'pct_counts_hb'])

KeyError                                  Traceback (most recent call last)
Cell In [131], line 6
      1 # need to plot the four sections separately and specify the library_id
      5 for library in library_names:
----> 6     sc.pl.spatial(adata[adata.obs.library_id == library,:], library_id=library, color = ["total_counts", "n_genes_by_counts",'pct_counts_mt', 'pct_counts_hb'])

File ~/miniconda3/envs/seurat/lib/python3.10/site-packages/scanpy/plotting/_tools/scatterplots.py:988, 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)
    936 """\
    937 Scatter plot in spatial coordinates.
    938 
   (...)
    985     Tutorial on spatial analysis.
    986 """
    987 # get default image params if available
--> 988 library_id, spatial_data = _check_spatial_data(adata.uns, library_id)
    989 img, img_key = _check_img(spatial_data, img, img_key, bw=bw)
    990 spot_size = _check_spot_size(spatial_data, spot_size)

File ~/miniconda3/envs/seurat/lib/python3.10/site-packages/scanpy/plotting/_tools/scatterplots.py:1300, in _check_spatial_data(uns, library_id)
   1298         library_id = None
   1299 if library_id is not None:
-> 1300     spatial_data = spatial_mapping[library_id]
   1301 else:
   1302     spatial_data = None

KeyError: 'A1'

I have library_id information included in adata.obs. If anyone faced same issue, please help me to fix it.

I would appreciate all the suggestion.

scanpy spatial-transcriptome

0 answers

No answers yet.

Log in to answer this question.