Skip to content

Discussion: multiple tables in a SpatialData object #43

Closed

Description

@kevinyamauchi

This issue is to discuss the possibility of allowing multiple tables per SpatialData object. The implementation may be a list of tables, a dictionary of tables, or a MuData object containing multiple tables. Below are the notes from the Oct 28, 2022 hackathon in Munich. cc @giovp , @LucaMarconato , @ivirshup .

Single-table

Pro

  • Intuitive compounds statements for queries on tables
idx = (sdata.tables['expression'].obs.cell_type == "Neuron") & (sdata.obs.n_counts > 100)
sdata = sdata[idx, :]

Cons

  • We 100% need a SpatialDataContainer
sc = SpatialContainer('...')
sdata = sc.to_spatialdata(elements=['/images/...', '...'])

everyting = SpatialData('...')
sdata = everyhing.query.elements(elements=['/images/...', '...'])
subsdata = sdata.query.elements(elements=['/images/...'])
  • Points can't be annotated with a table -> For Points (but not for Circles), you can store expression inside the Points.

Multi-table

Pro

  • No need for SpatialDataContainer
  • Points and Circles are unified, because both can be annotated by a Table
sdata0 = sdata.query.coordinate_system('coordinate_system_name', filter_rows=False)
sdata1 = sdata.query.bounding_box()
sdata1 = sdata.query.polygon('/polygons/annotations')
sdata1 = sdata.query.table(table_key=..., attr: ["obs", "var"], query="""""")

see https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html

import squidpy as sq

adata = sq.datasets.mibitof()
df = adata.obs
out1 = df.query("(point == 23) & (cell_size > 200)")
out2 = df.loc[(df.point == 23) & (df.cell_size > 200)]
pd.testing.assert_frame_equal(out1, out2)

Cons

  • Complex selection of multiple tables
idx = (sdata.table.obs.cell_type == "Neuron") & (sdata.table.obs.n_counts > 100)
sdata = sdata.query.table(key='expression', index=idx)

class SpatialData
    @property
    def table(self) -> AnnData:
        if len(self.tables) == 1:
            k = list(self.tables.keys())[0]
            return self.tables[k]
        else:
            raise ValueError("...")

('A > B' & 'cell_type == "Neuron"')

Activity

  1. linked a pull request that will close this issuemulti table support #455on Feb 22, 2024
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

    APIAbout the API/ UX

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions