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

Alignment image with xenium

Open Yifan-debug opened this issue 1 year ago • 24 comments

Sorry for the continuous questions, and I'm really at the beginning stage of spatial transcriptomics. I aligned my confocal image (Z-stack OME TIFF file) with the Xenium dataset in Xenium Explorer. I downloaded the matrix.csv from Xenium Explorer.

Please let me know if I need provide more information

I use this tutorial for alignment. https://github.com/quentinblampey/spatialdata_xenium_explorer/blob/master/docs/10x_tutorials/xenium/xenium_tuto.ipynb However, I got the issue at this step. alignment_matrix_path = "../C1-blank-section1-ant2-SOAR40x_alignment_files/matrix.csv" confocal_path = "../C1-blank-section1-ant2-SORA40x.ome.tif" image = xenium_aligned_image(confocal_path, alignment_matrix_path)


AssertionError Traceback (most recent call last) Cell In[14], line 6 3 alignment_matrix_path = "../C1-blank-section1-ant2-SOAR40x_alignment_files/matrix.csv" 4 confocal_path = "../C1-blank-section1-ant2-SORA40x.ome.tif" ----> 6 image = xenium_aligned_image(confocal_path, alignment_matrix_path) 7 sdata.add_image(image_name, image) 8 sdata

File d:\Yifan_Wang\Software\envs\SP\lib\site-packages\spatialdata_io\readers\xenium.py:595, in xenium_aligned_image(image_path, alignment_file, imread_kwargs, image_models_kwargs) 593 else: 594 assert len(image.shape) == 3 --> 595 assert image.shape[0] in [3, 4] 596 if image.shape[0] == 4: 597 # as explained before in _get_images(), we need to add a dummy channel until we support 4-channel images as 598 # non-RGBA images in napari 599 image = da.concatenate([image, da.zeros_like(image[0:1])], axis=0)

AssertionError:--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) Cell In[14], line 6 3 alignment_matrix_path = "../C1-blank-section1-ant2-SOAR40x_alignment_files/matrix.csv" 4 confocal_path = "../C1-blank-section1-ant2-SORA40x.ome.tif" ----> 6 image = xenium_aligned_image(confocal_path, alignment_matrix_path) 7 sdata.add_image(image_name, image) 8 sdata

File d:\Yifan_Wang\Software\envs\SP\lib\site-packages\spatialdata_io\readers\xenium.py:595, in xenium_aligned_image(image_path, alignment_file, imread_kwargs, image_models_kwargs) 593 else: 594 assert len(image.shape) == 3 --> 595 assert image.shape[0] in [3, 4] 596 if image.shape[0] == 4: 597 # as explained before in _get_images(), we need to add a dummy channel until we support 4-channel images as 598 # non-RGBA images in napari 599 image = da.concatenate([image, da.zeros_like(image[0:1])], axis=0)

AssertionError:

Yifan-debug avatar Jul 02 '24 18:07 Yifan-debug

Your usage seems correct, we can correct it from our side by adding a parameter axes= to xenium_aligned_image() to allow users to specify the axis of the data, and keep the current behavior (axes automatically inferred using an heuristic) when axis is not specified. I'll try to make a fix in the next days.

LucaMarconato avatar Jul 02 '24 23:07 LucaMarconato

Thank you so much! I'm not sure if this helps, but I tried the example Xenium data and HE picture, and it worked. However, it didn't work for my pictures. Please let me know if it would help you better if I upload my pictures.

Yifan-debug avatar Jul 03 '24 01:07 Yifan-debug

We need to make a fix to the function xenium_aligned_image(), I will let you know when it's ready.

LucaMarconato avatar Jul 03 '24 10:07 LucaMarconato

Wondering if there is new information about this issue

Yifan-debug avatar Aug 11 '24 18:08 Yifan-debug

I just implemented a solution in https://github.com/scverse/spatialdata-io/pull/196. To try it please install the latest main from the spatialdata repository and the spatialdata-io from the linked PR.

LucaMarconato avatar Aug 12 '24 14:08 LucaMarconato

Thank you! I will try it and let you know if it working.

Yifan-debug avatar Aug 12 '24 14:08 Yifan-debug

Hi I got new error for this. I install the spatialdata, spatialdata-io from github. It seems like not working with spatial-plot . And I install the spatial-plot again from github. It give me a this error code.


TypeError Traceback (most recent call last) Cell In[8], line 2 1 import spatialdata_plot ----> 2 query_sdata.pl.render_shapes("nucleus_boundaries").pl.show()

File d:\Yifan_Wang\Software\envs\SpatialData\Lib\site-packages\spatialdata_utils.py:261, in _deprecation_alias..deprecation_decorator..wrapper(*args, **kwargs) 259 raise ValueError("version for deprecation must be specified") 260 rename_kwargs(f.name, kwargs, alias_copy, class_name, library, version) --> 261 return f(*args, **kwargs)

File d:\Yifan_Wang\Software\envs\SpatialData\Lib\site-packages\spatialdata_plot\pl\basic.py:276, in PlotAccessor.render_shapes(self, element, color, fill_alpha, groups, palette, na_color, outline, outline_width, outline_color, outline_alpha, cmap, norm, scale, method, table_name, **kwargs) 273 outline_params = _set_outline(outline, outline_width, outline_color) 275 for element, param_values in params_dict.items(): --> 276 sdata.plotting_tree[f"{n_steps+1}_render_shapes"] = ShapesRenderParams( 277 element=element, 278 color=param_values["color"], 279 col_for_color=param_values["col_for_color"], 280 groups=param_values["groups"], 281 scale=param_values["scale"], 282 outline_params=outline_params, 283 cmap_params=cmap_params, 284 palette=param_values["palette"], 285 outline_alpha=param_values["outline_alpha"], 286 fill_alpha=param_values["fill_alpha"], ... 291 ) 292 n_steps += 1 294 return sdata

TypeError: ShapesRenderParams.init() got an unexpected keyword argument 'element'

Yifan-debug avatar Aug 12 '24 15:08 Yifan-debug

@timtreis any idea?

@Yifan-debug thanks for reporting, I'd suggest using this PR from spatialdata-plot: https://github.com/scverse/spatialdata-plot/pull/309 which fixes many recent bugs (but which is not merged yet).

We do a complete check of the interactions between the various repositories before each release so unfortunately using freshly dev code may lead to these kind of problems sometimes.

LucaMarconato avatar Aug 12 '24 15:08 LucaMarconato

Sure, I totally understand. And thank you so much for developing this useful tools.

Yifan-debug avatar Aug 12 '24 15:08 Yifan-debug

In alternative, if the above doesn't work, you can reinstall the latest stable code and manually fix the above by copy-pasting the code in xenium_aligned_image(). The code is very short and in general the users are invited to enrich and manipulate the SpatialData objects after they are created. So you could use xenium(aligned_images=False) and manually parse them.

LucaMarconato avatar Aug 12 '24 15:08 LucaMarconato

I think I may haven't downloaded the right version of spatialdata. Here is the version I tried. And it not working. (basically, it said there is no dims) spatialdata 0.2.3.dev2+gcf16027 pypi_0 pypi spatialdata-io 0.1.4 pypi_0 pypi

Yifan-debug avatar Aug 12 '24 16:08 Yifan-debug

pip install git+https://github.com/scverse/spatialdata-io.git@main pip install git+https://github.com/scverse/spatialdata.git@main

Here are the codes I used to download

Yifan-debug avatar Aug 12 '24 16:08 Yifan-debug

Please you should install spatialdata-io from the PR linked to this issue (https://github.com/scverse/spatialdata-io/pull/196), not from main.

LucaMarconato avatar Aug 12 '24 16:08 LucaMarconato

But actually, I will merge it now, after that you can install from main (this will automatically close the issue, but feel free to continue the discussion here).

LucaMarconato avatar Aug 12 '24 16:08 LucaMarconato

Great! Thank you so much!! Appreciate for doing this. Just for curiously, Do you have any plan for next(new) stable version. That package will largely help my project

Yifan-debug avatar Aug 12 '24 16:08 Yifan-debug

Happy to help! 😊 We are fixing some PRs related to plotting, I think in 1-2 weeks we'll make a release.

LucaMarconato avatar Aug 12 '24 17:08 LucaMarconato

Perfect! Thank you so much!


From: LucaMarconato @.> Sent: Monday, August 12, 2024 01:41 PM To: scverse/spatialdata-io @.> Cc: Yifan Wang @.>; Mention @.> Subject: [EXT] Re: [scverse/spatialdata-io] Alignment image with xenium (Issue #168)

CAUTION: Email Originated Outside of Auburn.

Happy to help! 😊 We are fixing some PRs related to plotting, I think in 1-2 weeks we'll make a release.

— Reply to this email directly, view it on GitHubhttps://github.com/scverse/spatialdata-io/issues/168#issuecomment-2284579804, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANECHKMTECD2AUGRPAJS63DZRDXS7AVCNFSM6AAAAABKICQT26VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOBUGU3TSOBQGQ. You are receiving this because you were mentioned.Message ID: @.***>

Yifan-debug avatar Aug 12 '24 17:08 Yifan-debug

@timtreis any idea?

@Yifan-debug thanks for reporting, I'd suggest using this PR from spatialdata-plot: scverse/spatialdata-plot#309 which fixes many recent bugs (but which is not merged yet).

We do a complete check of the interactions between the various repositories before each release so unfortunately using freshly dev code may lead to these kind of problems sometimes.

Not super sure which version is now actually underlying your issue but at one point, @melonora and I refactored spatialdata-plot to have less nested calls during which elements got renamed to element. So this could be the issue - in case it still persists. That'd mean you have an old version installed

timtreis avatar Aug 12 '24 18:08 timtreis

Hi @LucaMarconato Sorry for the repeated question again. I downloaded the pip install git+https://github.com/scverse/spatialdata-io.git@main pip install git+https://github.com/scverse/spatialdata.git@main since you merge the issue in main. Here is my version of spatialdata. spatialdata 0.2.3.dev9+g774b492 pypi_0 pypi spatialdata-io 0.1.5.dev5+gc15dca9 pypi_0 pypi spatialdata-plot 0.2.4 pypi_0 pypi

But I still get the same error code as begin.

AssertionError Traceback (most recent call last) Cell In[23], line 1 ----> 1 image = xenium_aligned_image( 2 image_path=image_path, 3 alignment_file=alignment_matrix_path, 4 image_models_kwargs={"scale_factors": [2, 2, 2]}, 5 # dims=("k", "y", "x", "c"), 6 )

File d:\Yifan_Wang\Software\envs\sopa\lib\site-packages\spatialdata_io\readers\xenium.py:637, in xenium_aligned_image(image_path, alignment_file, imread_kwargs, image_models_kwargs) 635 else: 636 assert len(image.shape) == 3 --> 637 assert image.shape[0] in [3, 4] 638 if image.shape[0] == 4: 639 # as explained before in _get_images(), we need to add a dummy channel until we support 4-channel images as 640 # non-RGBA images in napari 641 image = da.concatenate([image, da.zeros_like(image[0:1])], axis=0)

AssertionError:

Would you mind let me know the correct code or version for download the spatialdata? I'm sorry for keep asking but this do confuse me for a while.

Yifan-debug avatar Sep 03 '24 14:09 Yifan-debug

Hi some updated information. I also updated spatialdata-plot. but I still have this error

spatialdata 0.2.3.dev9+g774b492 pypi_0 pypi spatialdata-io 0.1.5.dev5+gc15dca9 pypi_0 pypi spatialdata-plot 0.2.7.dev1+g41e66a8 pypi_0 pypi

Yifan-debug avatar Sep 05 '24 13:09 Yifan-debug

@Yifan-debug for the traceback it seems that the dims parameter is not being used (please check the documentation here: https://github.com/scverse/spatialdata-io/blob/80acf8070c9f3f2f029976c348f759021f05b605/src/spatialdata_io/readers/xenium.py#L617).

Is this the case?

LucaMarconato avatar Sep 08 '24 09:09 LucaMarconato

HI @LucaMarconato No, I tried with dims parameter. but it didi have this argument image

Yifan-debug avatar Sep 09 '24 12:09 Yifan-debug

The argument dims should be available from spatialdata-io==0.1.5, could you please check that you are using a recent version of spatialdata-io? Thanks 😊

LucaMarconato avatar Oct 03 '24 16:10 LucaMarconato