kharchenkolab / Baysor

Bayesian Segmentation of Spatial Transcriptomics Data
MIT License
142 stars 29 forks source link

Baysor v.0.6.2 Loaderror: No transcripts detected inside the segmented regions #96

Closed andynkili closed 9 months ago

andynkili commented 10 months ago

Dear support,

I am using baysor (last version) on a merfish experiment with DAPI. Here is the command and resulting error:

baysor run detected_transcripts.csv mosaic_DAPI_z5.tif -c output/config3/merfish.toml -p -o output/DAPI_config7
[01:46:45] Info: Run Red3f79de5
[01:46:45] Info: (2023-09-05) Run Baysor v0.6.2
[01:46:45] Info: Loading data...
[01:48:33] Info: Loaded 11448082 transcripts
[01:48:44] Info: Loading segmentation mask...
[01:50:35] Warning: Maximum transcript coordinates are (2428, 7840), which is much smaller than the DAPI size: (22312, 72552). May be result of an error.
└ Baysor.DataLoading /root/.julia/packages/Baysor/XOSVt/src/data_loading/prior_segmentation.jl:34
ERROR: LoadError: No transcripts detected inside the segmented regions. Please, check that transcript coordinates match those in the segmentation mask.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] estimate_scale_from_centers(seg_labels::SparseArrays.SparseMatrixCSC{UInt16, Int64})
    @ Baysor.DataLoading ~/.julia/packages/Baysor/XOSVt/src/data_loading/prior_segmentation.jl:84
  [3] load_prior_segmentation(file::String, pos_data::Matrix{Float64}; min_molecules_per_segment::Int64)
    @ Baysor.DataLoading ~/.julia/packages/Baysor/XOSVt/src/data_loading/cli_wrappers.jl:35
  [4] load_prior_segmentation
    @ ~/.julia/packages/Baysor/XOSVt/src/data_loading/cli_wrappers.jl:27 [inlined]
  [5] load_prior_segmentation!(path::String, df_spatial::DataFrames.DataFrame, pos_data::Matrix{Float64}; min_molecules_per_segment::Int64, min_mols_per_cell::Int64)
    @ Baysor.DataLoading ~/.julia/packages/Baysor/XOSVt/src/data_loading/cli_wrappers.jl:218
  [6] load_prior_segmentation!(df_spatial::DataFrames.DataFrame, prior_segmentation::String, opts::Baysor.Utils.SegmentationOptions; min_molecules_per_cell::Int64, min_molecules_per_segment::Int64, plot::Bool)
    @ Baysor.CommandLine ~/.julia/packages/Baysor/XOSVt/src/cli/main.jl:197
  [7] run(coordinates::String, prior_segmentation::String; config::Baysor.Utils.RunOptions, x_column::String, y_column::String, z_column::String, gene_column::String, min_molecules_per_cell::Int64, scale::Float64, scale_std::String, n_clusters::Int64, prior_segmentation_confidence::Float64, output::String, plot::Bool, save_polygons::String, no_ncv_estimation::Bool, count_matrix_format::String)
    @ Baysor.CommandLine ~/.julia/packages/Baysor/XOSVt/src/cli/main.jl:108
  [8] command_main(ARGS::Vector{String})
    @ Baysor.CommandLine ~/.julia/packages/Comonicon/HDhA6/src/codegen/julia.jl:343
  [9] command_main()
    @ Baysor.CommandLine ~/.julia/packages/Comonicon/HDhA6/src/codegen/julia.jl:90
 [10] command_main(; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Baysor ~/.julia/packages/Baysor/XOSVt/src/Baysor.jl:41
 [11] command_main()
    @ Baysor ~/.julia/packages/Baysor/XOSVt/src/Baysor.jl:41
 [12] top-level scope
    @ /usr/local/bin/baysor:15
in expression starting at /usr/local/bin/baysor:15

When I run the command without DAPI, it works and produce an image very similar to the DAPI image, so I ruled out me not using the correct DAPI image. Then I thought about the intensities in the DAPI image varying depending on the z-scale and tried all of them (from z0 to z6), however they all returned the same error. Do you have any clues about what could be the cause of that error?

Best, Andy

andynkili commented 10 months ago

@VPetukhov, Could it be related to the size of the DAPI tiff image? Baysor runs fine with the DAPI provided in the iss example (600MB tiff file), but when I run it on our data (tiff file is 3GB) or on Vizgen public data (mouse brain slice 1 with a 10GB tiff file), that error happens. Do you have any thoughts on this?

Best, Andy

andynkili commented 10 months ago

@VPetukhov, I tried to debug by first changing the size of the DAPI file (increase/decrease) but the error still occurred (only the warning about the DAPI size changed: "Warning: Maximum transcript coordinates are (19538, 19560), which is much smaller than the DAPI size: (22312, 72552). May be result of an error.".

Then I changed the transcripts coordinates (by a factor 10) and baysor runs until the end (with the same warning). Naturally It results in a truncated segmentation image (as some of the coordinates still don't match), but at least the error does not happen. This may be related to the way baysor interpret the tiff file. Regarding the latter, pardon the naïve question as I am not proficient in julia: why not using TiffImages.jl instead of ImageCore.jl?

Best, Andy