Skip to content
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

Issue when running Baysor with prior segmentation #133

Open
lguerard opened this issue Aug 28, 2024 · 8 comments
Open

Issue when running Baysor with prior segmentation #133

lguerard opened this issue Aug 28, 2024 · 8 comments
Labels
question Further information is requested

Comments

@lguerard
Copy link

lguerard commented Aug 28, 2024

Hi,

I want to improve the results I'm getting from Baysor by using prior segmentation. I have run CellPose on the DAPI channel and got both a label image as well as a CSV with the X, Y and Z position of my cells. However, they both produces errors :

When running with CSV:

Error encountered while load FileIO.File{FileIO.DataFormat{:CSV}, String}("data/Result/spots.csv").

Fatal error:
ERROR: ArgumentError: Package CSVFiles [5d742f6a-9f54-50ce-8119-2520741973ca] is required but does not seem to be installed:
 - Run `Pkg.instantiate()` to install all recorded dependencies.

When running with label image:

Errors encountered while load FileIO.File{FileIO.DataFormat{:TIFF}, String}("data/Result/hyb001ch1_stitched_ds4_rescale_rotate_flip_label_16bit.tif").
All errors:
===========================================
DimensionMismatch: supplied axes do not agree with the size of the array (got size (256,) for the array and (65536,) for the indices
===========================================
ArgumentError: Package ImageMagick [6218d12a-5da1-5696-b52f-db25d2ecc6d1] is required but does not seem to be installed:
 - Run `Pkg.instantiate()` to install all recorded dependencies.

There seem to be some errors with Julia but unsure how to fix this.

Any ideas ?

@VPetukhov
Copy link
Collaborator

VPetukhov commented Sep 4, 2024

Hi @lguerard , which way of installing Baysor did you use? And for CSV input, which command did you use?

@lguerard
Copy link
Author

lguerard commented Sep 4, 2024

Hi !

I downloaded the binaries directly for GitHub as this is on Linux. Everything's running fine without the prior_segmentation but if I use it, I get these error messages...

For the CSV, I just added the path to the CSV, but for that one, it might be normal as I was just passing a CSV with the X,Y,Z centroids of the cells that I got from CellPose...

@VPetukhov
Copy link
Collaborator

Then I'd suggest trying native julia installation. As for the CSV, you can't pass a new CSV, it should be a column in the old CSV. Please, see the docs here.

@VPetukhov
Copy link
Collaborator

As for the image prior, can you check if it still persists in v0.7.0?

@lguerard
Copy link
Author

Hi @VPetukhov,

I'm still testing and haven't yet looked at the results but at least it doesn't crash anymore, thanks a lot !

[16:33:15] Warning: Maximum transcript coordinates are (351, 12712), which is larger than the prior image size: (12712, 376). Filling it with 0.
└ Baysor.DataLoading /home/viktor_petukhov/.julia/dev/Baysor/src/data_loading/prior_segmentation.jl:26
[16:33:15] Warning: Minimum transcript coordinates are < 1: (-23, 0). Filling it with 0.
└ Baysor.DataLoading /home/viktor_petukhov/.julia/dev/Baysor/src/data_loading/prior_segmentation.jl:30
[16:33:15] Warning: Maximum transcript coordinates are (351, 12712), which is much smaller than the prior image size: (12712, 376). May be result of an error.
└ Baysor.DataLoading /home/viktor_petukhov/.julia/dev/Baysor/src/data_loading/prior_segmentation.jl:34

Just a question, is there an issue with the shape being opposite between the image and my transcript coordinates ? I'm guess yes, but the first warning seems to still understand it no ?

@VPetukhov
Copy link
Collaborator

Hi @lguerard ,
Yes, that means that coordinates in the image are transposed, you should rotate it to match with your molecules. Getting a proper transformation requires some care, as sometimes the images are also mirrored by some coordinates. Wihtout that, the prior segmentation is mostly ignored.

@lguerard
Copy link
Author

lguerard commented Oct 8, 2024

Hi @VPetukhov,

Thanks for the anwer. I transformed my image to match the molecules and could run the segmentation with prior cellpose segmentation and it went through.

However, the results look weird.

Here is my cellpose segmentation :
image

Here is the result of Baysor with prior segmentation and prior_segmentation_confidence at 1:
image

And here is the result of Baysor with prior segmentation and prior_segmentation_confidence at 0:
image

Multiple comments/questions:

  • Shouldn't Baysor constrain the transcripts segmentation to the cellpose cells ?
  • Shouldn't I get less cells segmentation with prior_segmentation_confidence at 1 instead of more ?

Thanks again for your very helpful help !

@VPetukhov
Copy link
Collaborator

VPetukhov commented Oct 16, 2024

The way Baysor handles the prior segmentation is that

  1. it prevents transcripts assigned to different prior cells to be assigned to the same cell
  2. it prevents transcripts assigned to the same prior cell to be assigned to different cells

It deliberately doesn't work on transcripts, which weren't assigned to any prior cell. It's done because stainings can often work well in some cell types but not the other, so those regions not covered by stains should be segmented de-novo. Another reason is that if you only used DAPI for a prior segmentation, we'd want to expand them to cytoplasm molecules. So "constraining the transcripts segmentation to the cellpose cells" wouldn't provide good results.

If you only want to analyze cells from CellPose, you may filter the segmentation results to only those cells. With prior confidence = 1 each cell pose cell with transcripts should have exactly one Baysor cell.

P.S. Answering this I realized that this part is only explained in the paper, but not in the docs. I'll update them with the next release.

@VPetukhov VPetukhov added the question Further information is requested label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants