spatialdata-io icon indicating copy to clipboard operation
spatialdata-io copied to clipboard

error from minimalistic reading of xenium data

Open EliHei2 opened this issue 1 year ago • 2 comments

Hola! just updated both spatialdata and spatialdata-io trying to read a generic xenium dataset with the following line, I get the error bellow:

sdata = spatialdata_io.xenium(
        'Xenium_V1_FFPE_Human_Breast_IDC', 
        morphology_mip=False, 
        morphology_focus=False, 
        cell_boundaries=False,
        cells_as_circles=False,
        cell_labels=False,
        nucleus_labels=False
    )
    if cell_labels_indices_mapping is not None:
UnboundLocalError: local variable 'cell_labels_indices_mapping' referenced before assignment

EliHei2 avatar Mar 29 '24 17:03 EliHei2

Hola! Well spotted 🥸 Fixed with https://github.com/scverse/spatialdata-io/releases/tag/v0.1.2, which also adds the parameter aligned_images: bool, to skip some extra H&E or IF images sometimes present in more recent datasets.

LucaMarconato avatar Mar 30 '24 03:03 LucaMarconato

Thanks Luca! Sorry for opening again, there's another error still, which I can guess where's it from (i.e., not reading cell boundaries) but leave it here:

line 344, in _get_polygons
    assert index.equals(idx)
AssertionError

EliHei2 avatar Apr 01 '24 09:04 EliHei2

Got back to this today. I have tried to replicate with the same argument but that line doesn't give me an error. I think the bug is now solved.

If you encounter it please feel free to reopen; in such a case please detail a link to a public dataset that can be used to replicate the bug, and to the code used to call the xenium() function.

LucaMarconato avatar May 28 '24 12:05 LucaMarconato

Hi, I keep getting this error :

---------------------------------------------------------------------------TypeError Traceback (most recent call last) Cell In[14], line 3 1 # Parse Xenium data 2 print("parsing the data... ", end="")----> 3 sdata = xenium( 4 path=str(path_read), 5 n_jobs=8, 6 cell_boundaries=True, 7 nucleus_boundaries=True, 8 morphology_focus=True, 9 ) 10 print("done")

File /opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/spatialdata_io/_utils.py:46, in deprecation_alias..deprecation_decorator..wrapper(*args, **kwargs) 44 class_name = f.qualname 45 rename_kwargs(f.name, kwargs, aliases, class_name)---> 46 return f(*args, **kwargs)

File /opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/spatialdata_io/readers/xenium.py:334, in xenium(path, cells_boundaries, nucleus_boundaries, cells_as_circles, cells_labels, nucleus_labels, transcripts, morphology_mip, morphology_focus, aligned_images, cells_table, n_jobs, imread_kwargs, image_models_kwargs, labels_models_kwargs) 330 assert ( 331 "c_coords" not in image_models_kwargs 332 ), "The channel names for the morphology focus images are handled internally" 333 image_models_kwargs["c_coords"] = list(channel_names.values())--> 334 images["morphology_focus"] = _get_images( 335 morphology_focus_dir, 336 XeniumKeys.MORPHOLOGY_FOCUS_CHANNEL_IMAGE.format(0), 337 imread_kwargs, 338 image_models_kwargs, 339 ) 340 del image_models_kwargs["c_coords"] 341 logger.removeFilter(IgnoreSpecificMessage())

File /opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/spatialdata_io/readers/xenium.py:564, in _get_images(path, file, imread_kwargs, image_models_kwargs) 558 if "c_coords" in image_models_kwargs and "dummy" in image_models_kwargs["c_coords"]: 559 # Napari currently interprets 4 channel images as RGB; a series of PRs to fix this is almost ready but they will 560 # not be merged soon. 561 # Here, since the new data from the xenium analyzer version 2.0.0 gives 4-channel images that are not RGBA, 562 # let's add a dummy channel as a temporary workaround. 563 image = da.concatenate([image, da.zeros_like(image[0:1])], axis=0)--> 564 return Image2DModel.parse( 565 image, transformations={"global": Identity()}, dims=("c", "y", "x"), rgb=None, **image_models_kwargs 566 )

File /opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/spatialdata/models/models.py:189, in RasterSchema.parse(cls, data, dims, transformations, scale_factors, method, chunks, **kwargs) 183 raise ValueError( 184 f"Cannot transpose arrays to match dims: {dims}.", 185 "Try to reshape data or dims.", 186 ) from e 188 # finally convert to spatial image--> 189 data = to_spatial_image(array_like=data, dims=cls.dims.dims, **kwargs) 190 # parse transformations 191 _parse_transformations(data, transformations)

TypeError: to_spatial_image() got an unexpected keyword argument 'rgb'

when I try to run this command :

Parse Xenium data

print("parsing the data... ", end="") sdata = xenium( path=str(path_read), n_jobs=8, cell_boundaries=True, nucleus_boundaries=True, morphology_focus=True, ) print("done")

Link to public dataset to reproduce this : I use the full bundle from that link:

https://www.10xgenomics.com/datasets/preview-data-ffpe-human-lung-cancer-with-xenium-multimodal-cell-segmentation-1-standard

asmitaL99 avatar Oct 16 '24 19:10 asmitaL99

Hi @asmitaL99, please install the latest version of spatial-image from pip to fix this. You can find more details here: https://github.com/scverse/spatialdata-io/issues/217.

LucaMarconato avatar Jan 05 '25 14:01 LucaMarconato