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

Alignment image with xenium #168

Open
Yifan-debug opened this issue Jul 2, 2024 · 24 comments · Fixed by #196
Open

Alignment image with xenium #168

Yifan-debug opened this issue Jul 2, 2024 · 24 comments · Fixed by #196

Comments

@Yifan-debug
Copy link

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:

@LucaMarconato
Copy link
Member

LucaMarconato commented Jul 2, 2024

@LucaMarconato
Copy link
Member

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.

@Yifan-debug
Copy link
Author

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.

@LucaMarconato
Copy link
Member

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

@Yifan-debug
Copy link
Author

Wondering if there is new information about this issue

@LucaMarconato
Copy link
Member

I just implemented a solution in #196. To try it please install the latest main from the spatialdata repository and the spatialdata-io from the linked PR.

@Yifan-debug
Copy link
Author

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

@Yifan-debug
Copy link
Author

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'

@LucaMarconato
Copy link
Member

LucaMarconato commented Aug 12, 2024

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

@Yifan-debug
Copy link
Author

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

@LucaMarconato
Copy link
Member

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.

@Yifan-debug
Copy link
Author

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
Copy link
Author

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

@LucaMarconato
Copy link
Member

Please you should install spatialdata-io from the PR linked to this issue (#196), not from main.

@LucaMarconato
Copy link
Member

LucaMarconato commented Aug 12, 2024

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

@Yifan-debug
Copy link
Author

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

@LucaMarconato
Copy link
Member

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

@Yifan-debug
Copy link
Author

Yifan-debug commented Aug 12, 2024 via email

@timtreis
Copy link
Member

@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

@Yifan-debug
Copy link
Author

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
Copy link
Author

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

@LucaMarconato
Copy link
Member

@Yifan-debug for the traceback it seems that the dims parameter is not being used (please check the documentation here:

).

Is this the case?

@LucaMarconato LucaMarconato reopened this Sep 8, 2024
@Yifan-debug
Copy link
Author

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

@LucaMarconato
Copy link
Member

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 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants