squidpy icon indicating copy to clipboard operation
squidpy copied to clipboard

fix the bug of relative coordinates

Open JiaShun-Xiao opened this issue 3 years ago • 8 comments

Description

I have changed the relative coordinate to exact coordinate in the feature_segmentation function. There are two reasons:

  1. because of the normalization of "np.max(y) - np.min(y)" in denominator, current relative coordinate will return nan if there is only one cell in spot.
  2. exact coordinate looks more reasonable than the relative coordinate when visualizing the segmentation result with spatial image as background.

How has this been tested?

I have tested the revised code in two Visium data, it works very well.

JiaShun-Xiao avatar Jun 17 '22 12:06 JiaShun-Xiao

Codecov Report

Merging #572 (06964fc) into main (2cf664f) will decrease coverage by 0.01%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #572      +/-   ##
==========================================
- Coverage   72.33%   72.32%   -0.02%     
==========================================
  Files          37       37              
  Lines        5177     5175       -2     
  Branches      982      982              
==========================================
- Hits         3745     3743       -2     
  Misses       1181     1181              
  Partials      251      251              
Impacted Files Coverage Δ
squidpy/im/_feature_mixin.py 87.17% <100.00%> (-0.17%) :arrow_down:

codecov-commenter avatar Jun 17 '22 12:06 codecov-commenter

hi @JiaShun-Xiao thanks for the cotnribution, can you elaborate a bit more and provide code snippets about this PR? I don't think I fully understand teh settigns in which this fails. Also, can you check out the contributing guide for pre-commit checks (currently failing).

Thank you!

giovp avatar Jun 18 '22 08:06 giovp

hi @JiaShun-Xiao ,

could you please elaborate on the purpose of this PR and provide a minimal reproducible example?

Thank you! GIovanni

giovp avatar Aug 09 '22 20:08 giovp

Hi, @giovp

Thanks for your patience! Current relative coordinates are fine in most cases. However, I think it could be improved by using exact coordinates as I mentioned in the first comment. The nuclei segmentation example (https://squidpy.readthedocs.io/en/latest/external_tutorials/tutorial_tangram.html) provided in squidpy document can demonstrate this.

Thank you! Jiashun

JiaShun-Xiao avatar Aug 10 '22 08:08 JiaShun-Xiao

interesting ok, the tests seem to pass, could you add a small test with this specific edge case? Otherwise a minimal reproducible example here and I'd be happy to add it myself, thank you!

giovp avatar Aug 10 '22 10:08 giovp

Sorry I am not familiar with tests in programming, I need some time to learn how to add tests for edge cases

JiaShun-Xiao avatar Aug 10 '22 11:08 JiaShun-Xiao

hi @JiaShun-Xiao , no problem. Could you please then post here few lines of code that explain what is the problem you are trying to solve? ideally something that can be run directly, with minimal dependency (e.g. squidpy, numpy etc)

giovp avatar Aug 10 '22 15:08 giovp

Sure, the problem I am trying to solve is retriving exact cell coordinates/locations after nuclei segmentation with spatial histological images. To demonstrate this, I add an example in the following Jupiter notebook to illustrate why we need exact nuclei coordinates instead of relative coordinates.

squidpy-mouce-brain-MOp-demo.ipynb.zip

squidpy-mouce-brain-MOp-demo.pdf

JiaShun-Xiao avatar Aug 11 '22 07:08 JiaShun-Xiao