scverse / scverse/squidpy

Function to subset the entire spatialdata object

Open
#1,007 6 comments 0 reactions 1 assignee View on GitHub

@selmanozleyen is already working on this.

Since May 26, 2025.

  • #967 by @timtreis — open
enhancement :sparkles: squidpy2.0
Dominant language
Python
Stars
598
Forks
121
Avg merge
3d 11h
Merged PRs (30d)
3

Description

A little bit I started on this PR https://github.com/scverse/squidpy/pull/967 which introduces a function that allows users to subset their entire SpatialData objects by certain criteria. The larger goal is to emulate this Scanpy notebook and to make Squidpy basically the biologist-friendly interface to SpatialData. Subsetting your object will be the first step in that journey.

For this, there are several considerations:

  • a given SpatialData object can contain 0-n AnnData objects
  • these AnnData objects can annotate 0-n other objects, f.e. segmentation masks, shapes (like for Visium), ROIs or even points
  • a given subsetting step on the AnnData object needs to find all instances that are annotated by these soon-to-be-gone observations in all other elements and deal with them accordingly:
    • segmentation masks -> set to 0 (background)
      • potentially: remove transcript locations falling into these segmentation masks
    • shapes -> remove
    • points -> remove
    • etc

However, there are additional constraints and open questions that are important for the implementation.

  • We can f.e. store segmentation masks as DataTrees with different scales - is it faster to subset the original resolution and to then regenerate the tree or subset all scales individually?
  • How do we handle inplace True vs False? Returning a copy can easily mean doubling a 500 GB object.

Some other edge cases might only really show up once there.

Generally, the goal should be to identify relevant subfunctions and push these upstream to SpatialData, some might already exist there and just need to be found (realistically by asking @LucaMarconato, there's quite a few functions only he really knows about), other might need to be written and pushed upstream. Ideally Squidpy then chains together these functions into something with good UX.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.