scverse / napari-spatialdata

Interactive visualization of spatial omics data
https://spatialdata.scverse.org/projects/napari/en/latest/
BSD 3-Clause "New" or "Revised" License
35 stars 13 forks source link

Issue of annotations of table #235

Open Nazim0001 opened 2 months ago

Nazim0001 commented 2 months ago

Hi, after following the tutorial part of https://spatialdata.scverse.org/en/latest/tutorials/notebooks/notebooks/examples/napari_rois.html#extracting-cells-under-the-regions, I tried to apply the 'Extracting cells under the regions'.

I used this script: categories = ["unassigned"] + list(filtered_tables.keys()) n = len(sdata["table"])

sdata["table"].obs["annotation"] = pd.Categorical( ["unassigned" for _ in range(n)], categories=categories)

for shape, subtable in filtered_tables.items(): in_shape = subtable.obs.index sdata["table"].obs["annotation"].loc[in_shape] = shape

My issue is about the lack of identification of annotations in sdata['table']: annotation myoepi 3935
unassigned 0 n 0 tubes 0 Name: count, dtype: int64

I tried to figure out the filtered : {'n': AnnData object with n_obs × n_vars = 3935 × 17943 obs: 'in_tissue', 'array_row', 'array_col', 'spot_id', 'region' var: 'gene_ids', 'feature_types', 'genome' uns: 'spatial', 'spatialdata_attrs' obsm: 'spatial', 'tubes': AnnData object with n_obs × n_vars = 3935 × 17943 obs: 'in_tissue', 'array_row', 'array_col', 'spot_id', 'region' var: 'gene_ids', 'feature_types', 'genome' uns: 'spatial', 'spatialdata_attrs' obsm: 'spatial', 'myoepi': AnnData object with n_obs × n_vars = 3935 × 17943 obs: 'in_tissue', 'array_row', 'array_col', 'spot_id', 'region' var: 'gene_ids', 'feature_types', 'genome' uns: 'spatial', 'spatialdata_attrs' obsm: 'spatial'}

But, I don't understand why? Could you please help to resolve it?

Thank you in advance Best Nazim

melonora commented 2 months ago

can you show an example of what the data looks like? As in what do the polygons look like in the coordinate system and what elements are contained within?

Nazim0001 commented 2 months ago

Yes for sure.

SpatialData object with: ├── Images │ ├── 'v1_hires_image': SpatialImage[cyx] (4, 1890, 2000) │ └── 'v1_lowres_image': SpatialImage[cyx] (4, 567, 600) ├── Shapes │ ├── 'myoepi': GeoDataFrame shape: (5, 1) (2D shapes) │ ├── 'n': GeoDataFrame shape: (5, 1) (2D shapes) │ ├── 'tubes': GeoDataFrame shape: (15, 1) (2D shapes) │ └── 'v1': GeoDataFrame shape: (3935, 2) (2D shapes) └── Tables └── 'table': AnnData (3935, 17943) with coordinate systems: ▸ 'aligned', with elements: myoepi (Shapes), n (Shapes), tubes (Shapes) ▸ 'downscaled_hires', with elements: v1_hires_image (Images), v1 (Shapes) ▸ 'downscaled_lowres', with elements: v1_lowres_image (Images), v1 (Shapes) ▸ 'global', with elements: v1 (Shapes)

After filtered table :

Screenshot from 2024-04-16 13-48-20

and here the localisation of shapes (myoepi, n, and tubes): Screenshot from 2024-04-16 13-50-51

Let me know if you need more information.

melonora commented 2 months ago

ok so I see element v1 in shapes does not live in the aligned coordinate space. Hence when you perform a query there is no alignment.

melonora commented 2 months ago

Would you need help with alignment?

Nazim0001 commented 2 months ago

Yes, please. How can I do that? Thank you in advance

Nazim0001 commented 2 months ago

Hello,

I saw a part of script for alignment on your site: https://spatialdata.scverse.org/en/latest/tutorials/notebooks/notebooks/examples/alignment_using_landmarks.html

If I change it like that, do you you think it will work for me: affine = align_elements_using_landmarks( references_coords=sdata["n"], moving_coords=sdata["v1"], reference_element=sdata["n"], moving_element=visium_sdata["v1_hires_imag"], reference_coordinate_system="global", moving_coordinate_system="global", new_coordinate_system="aligned", ) affine

Thank you in advance Best Nazim

Nazim0001 commented 2 months ago

Hello @melonora , sorry to bother you, have you been able to see how to do the alignment? best Nazim

melonora commented 2 months ago

Hi,

Sorry yes, if you follow the approach in the notebook it could work. Though always visually confirm whether the result is as expected. There are also other ways of achieving alignment but you could try this approach first.

Nazim0001 commented 2 months ago

Hi, I move v1 in aligned coordinate place: SpatialData object with: ├── Images │ ├── 'v1_hires_image': SpatialImage[cyx] (4, 1890, 2000) │ └── 'v1_lowres_image': SpatialImage[cyx] (4, 567, 600) ├── Shapes │ ├── 'myoepi': GeoDataFrame shape: (5, 1) (2D shapes) │ ├── 'n': GeoDataFrame shape: (5, 2) (2D shapes) │ ├── 'tubes': GeoDataFrame shape: (15, 2) (2D shapes) │ └── 'v1': GeoDataFrame shape: (15, 1) (2D shapes) └── Tables └── 'table': AnnData (3935, 17943) with coordinate systems: ▸ 'aligned', with elements: myoepi (Shapes), n (Shapes), tubes (Shapes), v1 (Shapes) ▸ 'downscaled_hires', with elements: v1_hires_image (Images) ▸ 'downscaled_lowres', with elements: v1_lowres_image (Images)

And tried to make an alignment of coordinates: from spatialdata.transformations import ( align_elements_using_landmarks, get_transformation_between_landmarks,)

affine = align_elements_using_landmarks( references_coords=sdata["n"], moving_coords=sdata["v1"], reference_element=sdata["n"], moving_element=sdata["v1_hires_image"], reference_coordinate_system="global", moving_coordinate_system="global", new_coordinate_system="aligned", affine

I had this error:ValueError: x attribute access only provided for Point geometries

But, it is weard because the coordinates are only point from np.array.

And I saw the data with the same number of data for each subset; n, tubes, myoepi, and v1

Screenshot from 2024-04-27 11-38-53

Could you please help me to align the different shapes living in align space to align with coordinates in order to extract RNA expression?

Best Nazim

Nazim0001 commented 1 month ago

Hi, sorry to bother you. Do you have any idea of how I could overcome this issue? Thank you in advance for help Best

melonora commented 1 month ago

It could be quicker to show you in a call perhaps. We do have community meetings, next one being next week thursday at 6pm CET, zoom link: https://embl-org.zoom.us/j/91981143644?pwd=M2NuRjlueVhqbmd4VDZFMktyWjAwdz09.

Or I would be happy to get into a call and then we can walk through the problem you have.

Nazim0001 commented 1 month ago

Hi, Thank you for your proposal. When you talk about next week, is it tomorrow or on Thursday, May 9th? because tomorrow I will be available, but May 9th, it would be ok. Thank you for your help. Nazim

On Wed, 1 May 2024 at 16:48, Wouter-Michiel Vierdag < @.***> wrote:

It could be quicker to show you in a call perhaps. We do have community meetings, next one being next week thursday at 6pm CET, zoom link: https://embl-org.zoom.us/j/91981143644?pwd=M2NuRjlueVhqbmd4VDZFMktyWjAwdz09 https://www.google.com/url?q=https://embl-org.zoom.us/j/91981143644?pwd%3DM2NuRjlueVhqbmd4VDZFMktyWjAwdz09&sa=D&source=calendar&ust=1715006728002067&usg=AOvVaw3LgD_a5T4EFgWibhzpkLEq .

Or I would be happy to get into a call and then we can walk through the problem you have.

— Reply to this email directly, view it on GitHub https://github.com/scverse/napari-spatialdata/issues/235#issuecomment-2088574416, or unsubscribe https://github.com/notifications/unsubscribe-auth/AY5TW4E7NRKJFWZUX445BOTZAD6CJAVCNFSM6AAAAABGGHIO4SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBYGU3TINBRGY . You are receiving this because you authored the thread.Message ID: @.***>

melonora commented 1 month ago

I mean next week. Or if you would like earlier we can schedule a call

Nazim0001 commented 1 month ago

Hi, I am waiting on Zoom, but maybe you are not available, is it possible to show my issues tomorrow or on the 16th at the same time (at 6pm CET)? Best

---

Nazim

On Thu, 2 May 2024 at 00:20, Wouter-Michiel Vierdag < @.***> wrote:

I mean next week. Or if you would like earlier we can schedule a call

— Reply to this email directly, view it on GitHub https://github.com/scverse/napari-spatialdata/issues/235#issuecomment-2089227710, or unsubscribe https://github.com/notifications/unsubscribe-auth/AY5TW4D6PXCN7HVCCZD3FITZAFTB3AVCNFSM6AAAAABGGHIO4SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBZGIZDONZRGA . You are receiving this because you authored the thread.Message ID: @.***>

melonora commented 1 month ago

My apologies, I had another meeting that took longer. I would be available tomorrow at 6pm CET. https://embl-org.zoom.us/j/96329127468?pwd=OCtYSzV1c2lxWVgyZmVDTEpRRkxHZz09

Nazim0001 commented 1 month ago

Thank you for your reply. See you tomorrow Best Nazin

On Thu, May 9, 2024, 19:07 Wouter-Michiel Vierdag, @.***> wrote:

My apologies, I had another meeting that took longer. I would be available tomorrow at 6pm CET. https://embl-org.zoom.us/j/96329127468?pwd=OCtYSzV1c2lxWVgyZmVDTEpRRkxHZz09 https://www.google.com/url?q=https://embl-org.zoom.us/j/96329127468?pwd%3DOCtYSzV1c2lxWVgyZmVDTEpRRkxHZz09&sa=D&source=calendar&ust=1715706413796410&usg=AOvVaw3Iv0iVSHdxFvoei6MrNE6a

— Reply to this email directly, view it on GitHub https://github.com/scverse/napari-spatialdata/issues/235#issuecomment-2103064057, or unsubscribe https://github.com/notifications/unsubscribe-auth/AY5TW4BIWLFNPVNR5DR5MHDZBOUO3AVCNFSM6AAAAABGGHIO4SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBTGA3DIMBVG4 . You are receiving this because you authored the thread.Message ID: @.***>