squidpy icon indicating copy to clipboard operation
squidpy copied to clipboard

Sliding window

Open FrancescaDr opened this issue 1 year ago • 5 comments

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

FrancescaDr avatar Jul 25 '24 12:07 FrancescaDr

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%> (ø)

... and 10 files with indirect coverage changes

---- 🚨 Try these New Features:

codecov-commenter avatar Oct 14 '24 19:10 codecov-commenter

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

LLehner avatar Oct 14 '24 22:10 LLehner

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.

FrancescaDr avatar Oct 16 '24 16:10 FrancescaDr

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!

LLehner avatar Oct 16 '24 21:10 LLehner

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.

FrancescaDr avatar Oct 17 '24 10:10 FrancescaDr