Sliding window
Description
This PR adds a new function, sliding_window, to the codebase. The sliding_window function divides a tissue slice into regularly shaped, spatially contiguous regions (windows). It allows for the analysis of spatial data by segmenting the tissue into smaller, manageable windows with optional overlap.
How has this been tested?
PyTest on sq.datasets.mibitof()
Closes
Closes #829
Codecov Report
Attention: Patch coverage is 76.13636% with 21 lines in your changes missing coverage. Please review.
Project coverage is 68.79%. Comparing base (
4a632d6) to head (b16e8d5). Report is 47 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/squidpy/tl/_sliding_window.py | 76.13% | 11 Missing and 10 partials :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #859 +/- ##
==========================================
- Coverage 69.99% 68.79% -1.20%
==========================================
Files 39 39
Lines 5532 5660 +128
Branches 1037 907 -130
==========================================
+ Hits 3872 3894 +22
- Misses 1367 1459 +92
- Partials 293 307 +14
| Files with missing lines | Coverage Δ | |
|---|---|---|
| src/squidpy/tl/_sliding_window.py | 76.13% <76.13%> (ø) |
- Flaky Tests Detection - Detect and resolve failed and flaky tests
Hi @FrancescaDr, i just tested your code on data with a single slide (so I didn't provide a library_key) and it seems like the sliding windows are only created when you provide a library key.
E.g. the following code does run but doesn't return multiple sliding windows:
adata = sq.datasets.seqfish()
sq.tl.sliding_window(adata, window_size = x) # here x can be any integer, doesn't change the result
Hi @FrancescaDr, i just tested your code on data with a single slide (so I didn't provide a library_key) and it seems like the sliding windows are only created when you provide a library key.
E.g. the following code does run but doesn't return multiple sliding windows:
adata = sq.datasets.seqfish()sq.tl.sliding_window(adata, window_size = x) # here x can be any integer, doesn't change the result
If I choose x = 1,2,3 I get a adata.obs['sliding_window'] with 'None_Z' where Z is the number of the sliding window.
If I choose x = 1,2,3 I get a adata.obs['sliding_window'] with 'None_Z' where Z is the number of the sliding window.
Ah right, for this dataset the coordinates are on a small scale, i initially tried it with window size 10, 100, 1000...ok i see that it works now!
Ah right, for this dataset the coordinates are on a small scale, i initially tried it with window size 10, 100, 1000...ok i see that it works now!
Yes the scale sliding window size variable always depends on the density and size of the FOV. It might be valuable to add a function that suggest appropriate sliding window sizes depending on e.i. number of average cells in a window.