-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incompatible coordinate transformation with cellpose segmentation result #96
Comments
Hello @mamyAndrianteranagna, thanks for referring to this issue. Can you list which versions of It's weird that the Last question: I saw you have an element called |
Hello Quentin, I actually used spatialdata.io to open the MERSCOPE output data before creating the spatial data object: import spatialdata_io as sdio
sdata = sdio.merscope("/path/to/MERSCOPE/output/region")
sdata.write("/path/to/zarr") Sorry about that, I didn't notice that there is a sopa module for it. However it works well with baysor. Many thanks! Best, |
Actually, the reader should be the same ( But, still, it's good to re-run it with the latest versions, since it appears that your versions are not up to date! |
Hi Quentin, Actually I have the same probleme even with sopa.io.merscope. Best, |
Sorry I forget, here are my current versions of Best, |
Hello Quentin, I have now these versions: but, unfortunately, I still get the same issue. Here is my code: # Import raw data and create spatialdata
import sopa.io
regionPath = '/path/to/merscope/output/region'
sdata = sopa.io.merscope(path=regionPath, backend=None, z_layers=3, region_name="region_0")
# Create patches
import spatialdata as sd
import sopa.segmentation
points_key = 'output_region_0_transcripts'
patches = sopa.segmentation.Patches2D(sdata=sdata, element_name=points_key, patch_width=4000, patch_overlap=30)
patches.write()
# Run cellpose nuclei segmentation
method = sopa.segmentation.methods.cellpose_patch(diameter=50, channels="DAPI", flow_threshold=2, cellprob_threshold=-6)
for patch_index in range(len(sdata['sopa_patches'])):
segmentation.write_patch_cells(tmpDir, patch_index)
# Resolve conflicts
nuclei = sopa.segmentation.StainingSegmentation.read_patches_cells(tmpDir)
nuclei = sopa.segmentation.shapes.solve_conflicts(nuclei)
shapes_key = 'cellpose_DAPI_diam_50_minarea_0_flow_2_cellprob_minus6'
image_key = 'output_region_0_z3'
sopa.segmentation.StainingSegmentation.add_shapes(sdta, nuclei, image_key, shapes_key)
# Aggregate
aggregator = sopa.segmentation.Aggregator(sdata=sdata, image_key=image_key, shapes_key=shapes_key)
aggregator.compute_table(gene_column='gene', average_intensities=False)
# Check spatialdata object
sdata
# Check coordinate system transformations for each layers
print(sdata.images['output_region_0_z3'].attrs)
print(sdata.points['output_region_0_transcripts'].attrs)
print(sdata.shapes['cellpose_DAPI_diam_50_minarea_0_flow_2_cellprob_minus6'].attrs)
print(sdata.shapes['sopa_patches'].attrs)
Let me know if you need more informations. Regards, |
Hello @mamyAndrianteranagna, Despite the weird "c" channel in the transformation, there is something weird happening before. For instance, using the same versions of >>> sopa.io.merscope("/path/to/region_0")
SpatialData object
├── Images
│ └── 'example_region_0_z3': DataTree[cyx] (2, 45030, 28250), (2, 22515, 14125), (2, 11257, 7062), (2, 5628, 3531), (2, 2814, 1765)
└── Points
└── 'example_region_0_transcripts': DataFrame with shape: (<Delayed>, 9) (2D points)
with coordinate systems:
▸ 'global', with elements:
example_region_0_z3 (Images), example_region_0_transcripts (Points) In your case, you have Can you confirm that you don't see the |
Hello Quentin, I agree, I suspect also something before, because I never get the 'global' coordinate system like seen everywhere in the exemple data from MERSCOPE. But I assumed that this can be aligned, transformed or corrected by the tool. With baysor results, there is no problem. So I confirm that I don't see coordinate named 'global' from the beginning. Thanks for your help! Best, |
Well, everything should work whatever the main coordinate system, for both Cellpose and Baysor. My guess is that there is nothing wrong with Sopa or SpatialData, but instead, there is an issue with your environment. import spatialdata
import spatialdata_io
import sopa
print(spatialdata.__version__, spatialdata_io.__version__, sopa.__version__) Somehow your environment seems to use old versions of these packages, and depending on how old they were, maybe you are experiencing a past bug. |
Hello Quentin, import spatialdata
import spatialdata_io
import sopa
print(spatialdata.__version__, spatialdata_io.__version__, sopa.__version__)
Maybe, a solution is to re-process the data using the new Vizgen Post-processing Tool? The data was generated last year and we do not have much informations about how it was pre-processed. But, in my understanding, they choose to use microns instead of pixels for the initial segmentation, etc. Best, |
I think the MERSCOPE data format has been the same since approximately early 2023, so everything should be good. Processing the data with VPT will not help (we read the raw images/transcripts, so this shouldn't affect your Indeed, the coordinate systems are created when reading the data with Sorry for not being very helpful here, I don't understand what is happening. Your version indicates a recent version of |
Hi Quentin, Thanks for these informations! Best, |
Hi Quentin, Sorry to come back again with this issue. Just to inform you that I created a new environment and now we have the 'global' coordinate (not micron) as before but, unfortunately, we still have the image and the cellpose result not aligned and look weird. Let me know if you need details. Best, |
Hi @mamyAndrianteranagna, it's good to see that now you can see the "global" coordinate system, but sorry to hear that the alignment is still wrong. |
Hello Quentin,
I have this problem that I posted in spatialdata github as an issue but we are wondering if it is not related to sopa:
Here is the issue:
scverse/spatialdata-io#166
Let me know if you need more details.
Regards,
Mamy
The text was updated successfully, but these errors were encountered: