sagar87 / spatialproteomics

Spatialproteomics is a light weight wrapper around xarray with the intention to facilitate the data exploration and analysis of highly multiplexed immunohistochemistry data. Docs available here: https://sagar87.github.io/spatialproteomics/ .
https://sagar87.github.io/spatialproteomics/
MIT License
13 stars 0 forks source link

Add possibility to crop out regions of interest #86

Closed MeyerBender closed 2 months ago

MeyerBender commented 2 months ago

In some samples, certain regions might be unusable, e. g. due to sample degradation or artifacts. It would be very useful if we could just exclude such regions from the analysis, e. g. by dropping all cells which are contained in the problematic region. There are several packages that already implement such a functionality, such as TissueTag or ipyannotations. Alternatively, we could also probably implement that custom fairly easily, see here.

For syntax, I'm thinking something like:

# if you want a default bounding box, already implemented
img.pp[x_min:x_max, y_min:y_max]
# if you want a more complex polygon selection
img = img.pp.select_region(key='_region')  # this should open the interactive annotation tool and store the result of the annotation in a new layer
img = img.pp.drop_cells(key='_region')  # this would drop all cells that are not in the polygon
img = img.pp.mask_region(key='_region')  # this would set all pixels outside of the selected region to zero. Could be useful e. g. when looking at automated thresholding and wanting to exclude an artifact from the percentile calculation
MeyerBender commented 2 months ago

After trying the custom solutions and ipyannotations, all of them had different issues and did not fully work. TissueTag seems like it is working, however writing a wrapper around it seems nonsensical, since the whole point of it is interactivity. Instead, I will implement a method that can put a binary array into the spatprot object, and then perform all of the previous described steps. The example notebook for the docs should include the following steps:

MeyerBender commented 2 months ago

Addressed in #89