Skip to content

Conversation

@LucaMarconato
Copy link
Member

@LucaMarconato LucaMarconato commented Feb 22, 2024

Depends on #111 (should be merged first).

Closes #110

  • reading the labels for nuclei and cells
  • reading the columns of cells_summary and adding it to the table

@codecov-commenter
Copy link

codecov-commenter commented Feb 22, 2024

Codecov Report

Attention: Patch coverage is 25.53191% with 70 lines in your changes are missing coverage. Please review.

Project coverage is 35.94%. Comparing base (f0d1f45) to head (a2e49fc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #112      +/-   ##
==========================================
- Coverage   36.33%   35.94%   -0.39%     
==========================================
  Files          18       18              
  Lines        1434     1516      +82     
==========================================
+ Hits          521      545      +24     
- Misses        913      971      +58     
Files Coverage Δ
src/spatialdata_io/_constants/_constants.py 100.00% <100.00%> (ø)
src/spatialdata_io/readers/xenium.py 22.68% <23.07%> (+0.98%) ⬆️

... and 1 file with indirect coverage changes

@LucaMarconato LucaMarconato marked this pull request as ready for review February 22, 2024 15:22
@LucaMarconato LucaMarconato requested a review from giovp February 22, 2024 15:22
@LucaMarconato
Copy link
Member Author

Tested on all the public Xenium versions using this https://github.com/giovp/spatialdata-sandbox/blob/main/tests/test_to_zarr_xenium.py

if morphology_focus:
morphology_focus_dir = path / XeniumKeys.MORPHOLOGY_FOCUS_DIR
files = {f for f in os.listdir(morphology_focus_dir) if f.endswith(".ome.tif")}
assert files == {XeniumKeys.MORPHOLOGY_FOCUS_CHANNEL_IMAGE.format(i) for i in range(4)} # type: ignore[str-format]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all v2.0.0 data has 4 channels. Xenium customers can run samples without the cell segmentation kit, in which case they will only have 1 ome.tif file in the morphology_focus_dir.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification, I will change the code to expect either the single DAPI channel either all the 4 channels.

If in the future also other cases are supported, such as an intermediate number of channels, I will adapt the code and make it general.

@LucaMarconato
Copy link
Member Author

LucaMarconato commented Mar 24, 2024

I applied the code suggestions and performed some additional cleanup. Also, I realized that the link between the labels indices for the cell segmentation and the instances of the rows required to parse additional data from cells.zarr.zip. Now this is included.

I tested the code on the Xenium Analyzer versions 1.0.1, 1.0.2, 1.3.0, 1.4.0, 1.5.0, 1.6.0, 1.7.0, 2.0.0.

One note on the new labels: the table is still mapped to the circles/shapes but the user can change the annotation target of the table to the labels using the new set_table_annotates_spatialelement() method. I plan to show this in an example notebook.

Using the multiscale labels instead of the shapes for visualizing the data not only improves the quality of the visualization over circles and polygons, but also doesn't compromise performance. Here is an example of the new (labels) vs old (circles) napari view.

CleanShot 2024-03-24 at 20 35 55
CleanShot 2024-03-24 at 20 43 45

Full code to load the data, change the table and view the data.

##
import spatialdata as sd
from napari_spatialdata import Interactive

sdata = sd.read_zarr('data.zarr')

sdata['table'].obs['region'] = 'cell_labels'
sdata.set_table_annotates_spatialelement(
    table_name='table', 
    region='cell_labels', 
    instance_key='cell_labels'
)

Interactive(sdata)

@LucaMarconato LucaMarconato merged commit 9eee2ae into main Mar 24, 2024
@LucaMarconato LucaMarconato deleted the xenium-cells.zarr.zip branch March 24, 2024 19:53
lucas-diedrich pushed a commit to lucas-diedrich/spatialdata-io that referenced this pull request Nov 26, 2024
Support for `cells.zarr.zip` for Xenium
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 this pull request may close these issues.

Support cells.zarr.zip for Xenium data

4 participants