Skip to content

Subset sdata by list of elements #208

Closed

Description

@LucaMarconato

Simple solution but not high priority.

I need to implement a function that subsets an sdata object by passing a list of names of elements.

For instance

SpatialData object with:
├── Images
│     ├── 'morphology_focus': MultiscaleSpatialImage[cyx] (1, 25778, 35416), (1, 12889, 17708), (1, 6444, 8854), (1, 3222, 4427), (1, 1611, 2213)
│     └── 'morphology_mip': MultiscaleSpatialImage[cyx] (1, 25778, 35416), (1, 12889, 17708), (1, 6444, 8854), (1, 3222, 4427), (1, 1611, 2213)
├── Points
│     └── 'transcripts': DataFrame with shape: (42638083, 9) (3D points)
├── Shapes
│     ├── 'cell_boundaries': GeoDataFrame shape: (167780, 1) (2D shapes)
│     ├── 'cell_circles': GeoDataFrame shape: (167780, 2) (2D shapes)
│     └── 'nucleus_boundaries': GeoDataFrame shape: (167780, 1) (2D shapes)
└── Table
      └── AnnData object with n_obs × n_vars = 167780 × 313
    obs: 'cell_id', 'transcript_counts', 'control_probe_counts', 'control_codeword_counts', 'total_counts', 'cell_area', 'nucleus_area', 'region', 'dataset', 'celltype_major', 'celltype_minor'
    var: 'gene_ids', 'feature_types', 'genome'
    uns: 'spatialdata_attrs'
    obsm: 'spatial': AnnData (167780, 313)
with coordinate systems:
▸ 'aligned', with elements:
        morphology_focus (Images), morphology_mip (Images), transcripts (Points), cell_boundaries (Shapes), cell_circles (Shapes), nucleus_boundaries (Shapes)
▸ 'global', with elements:
        morphology_focus (Images), morphology_mip (Images), transcripts (Points), cell_boundaries (Shapes), cell_circles (Shapes), nucleus_boundaries (Shapes)

I want to be able to make a query like:

sdata.query.elements(['morphology_focus', 'cell_circles'], filter_table=True)

Notes:

  • names are unique so we don't need to say that the first is an image and the second is a shapes
  • filter_table is True by default, as in other parts of the code.

@timtreis do you also need this code/do you already have it?
For the moment I am doing this subsets manually.

Activity

  1. timtreis commented on Apr 4, 2023

    @timtreis
    Member
  2. LucaMarconato commented on Apr 4, 2023

    @LucaMarconato
    MemberAuthor

    Very nice! After the paper we can coordinate on this to move the functionality upstream.

  3. timtreis commented on Apr 5, 2023

    @timtreis
    Member

    Shall I open a PR?

  4. LucaMarconato commented on Apr 5, 2023

    @LucaMarconato
    MemberAuthor

    Yes please do it (at any time).

  5. LucaMarconato commented on Feb 22, 2024

    @LucaMarconato
    MemberAuthor

    Closed with #426.

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