Skip to content

Ability to add Table(s) to Coordinate Systems #443

Closed

Description

@srivarra

Thanks for working on multi table support! I've been using the recent multi_table branch and it's been working pretty well so far. One nice feature would be the ability to add a table to coordinate system with a transformation.

For my particular use case, the purpose of this would be to group all related components of a particular field of view together for easy iteration / accession.

For example, being able to do the following:

import spatialdata as sd

sd.transformations.set_transformation(
		element=sdata.tables["fov0_whole_cell_table"],
		transformation=sd.transformations.Identity(),
		to_coordinate_system="fov0"
)

Where the coordinate system "fov0" now would have:

▸ 'fov0', with elements:
        fov0 (Images), fov0_nuclear (Labels), fov0_whole_cell (Labels), fov0_whole_cell_table (Tables)

I think the SpatialElement union type would need to be extended to support AnnData tables as well, amongst other changes.

Perhaps TableModel.parse method could have the coordinate transformation arguments as well.

class TableModel:
	...
		@classmethod
		def parse(
			  cls,
			  adata: AnnData,
			  region: str | list[str] | None = None,
			  region_key: str | None = None,
			  instance_key: str | None = None,
			  # New parameter
			  transformations: MappingToCoordinateSystem_t | None = None,

And the usage of parse could be:

sd.models.TableModel.parse(
		adata=fov0_adata,
		region="fov0_whole_cell",
		region_key="region",
		instance_key="instance",
		transformations={"fov0": sd.transformations.Identity()
}

Is this particular feature within scope for how tables should operate in SpatialData?

Activity

  1. LucaMarconato commented on Jan 29, 2024

    @LucaMarconato
    Member

    Hi @srivarra, great to hear that you tried already the multi_table branch and that you found it useful 😊

    Regarding allowing tables to have an associated coordinate system, this would clash with the case in which a table is annotating multiple elements, each belonging to a different coordinate system.

    Anyway, I can see two approaches to handle your use cases:

    1. if you filter the SpatialData object with SpatialData.filter_by_coordinate_system(), the new object will subset the table to match the geometries in the coordinate system. The function was not in the docs, I will update this with a PR I am currently working on.
    2. we plan to support NGFF files with arbitrary hierarchies Support for nested hierarchies in NGFF stores #398; the user will then be able for instance to create zarr group "sample0", "sample1" and to group all the elements and annotations belonging to a sample. This would not change how the SpatialData object and elements operate in-memory, and the use of coordinate systems would also not change.

    Would any of these work for your case?

  2. srivarra commented on Jan 29, 2024

    @srivarra
    ContributorAuthor

    @LucaMarconato

    Regarding allowing tables to have an associated coordinate system, this would clash with the case in which a table is annotating multiple elements, each belonging to a different coordinate system.

    Yup, makes perfect sense to me.

    I think the first approach sounds good for now, but the arbitrary hierarchy NGFF sounds perfect!

    Thank you!

  3. LucaMarconato commented on Jan 29, 2024

    @LucaMarconato
    Member

    Happy to hear this and looking forward to enable nested hierarchies! 😊 Closing this issue now as the progress will be tracked in #398.

  4. LucaMarconato commented on Feb 1, 2024

    @LucaMarconato
    Member

    The function was not in the docs, I will update this with a PR I am currently working on.

    Actually it was already in the docs but a bit hidden, since it's a method of the SpatialData class. We can make it more discoverable, tracking this in #225.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions