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

Save Segmentation Results Error #150

Open
ccnawrocki opened this issue Dec 12, 2024 · 2 comments
Open

Save Segmentation Results Error #150

ccnawrocki opened this issue Dec 12, 2024 · 2 comments

Comments

@ccnawrocki
Copy link

Hi there,
When I am running Baysor on CosMx data, it seems to work great for many of my fields of view (FOVs). However, with a select few, I get the following error:

(base) ccn22@MGB033458 hcc_tma2 % 
~/.julia/bin/baysor run FOV022.csv :cell_ID -g "target" -m 10 -x "x_local_px" -y "y_local_px" -s 70                            
[11:25:24] Info: Run R671c70508
[11:25:24] Info: (2024-12-12) Run Baysor v0.7.1
[11:25:24] Info: Loading data...
[11:25:27] Info: Loaded 615297 transcripts, 1087 genes.
[11:25:27] Info: Estimating noise level
[11:25:31] Info: Done
[11:25:35] Info: Clustering molecules...
Progress: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████| Time: 0:00:23
  Iteration:                  483
  Max. difference:            0.0048
  Fraction of probs changed:  0.235
[11:26:01] Info: Algorithm stopped after 483 iterations. Max. probability difference: 0.0048. Converged: true.
[11:26:01] Info: Done
[11:26:01] Info: Initializing algorithm. Scale: 70.0, scale std: 17.5, initial #components: 123058, #molecules: 615297.
[11:26:03] Info: Using the following additional information about molecules: [:confidence, :cluster, :prior_segmentation]
[11:26:03] Info: Using 3D coordinates
Progress: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████| Time: 0:01:34
  Iteration:        500
  Noise level, %:   1.91
  Num. components:  1847
[11:27:38] Info: Processing complete.
[11:27:39] Info: Estimating local colors
[11:28:09] Info: Estimating boundary polygons
Progress: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████| Time: 0:00:01
[11:28:13] Info: Saving results to segmentation.csv
ERROR: LoadError: MethodError: no method matching save_segmentation_results(::DataFrames.DataFrame, ::DataFrames.DataFrame, ::SparseArrays.SparseMatrixCSC{Int64, Int64}, ::OrderedCollections.OrderedDict{String, Dict{K, Matrix{Float64}} where K}, ::Baysor.Utils.OutputPaths; matrix_format::Symbol, gene_names::Vector{String}, polygon_format::String)

Closest candidates are:
  save_segmentation_results(::DataFrames.DataFrame, ::DataFrames.DataFrame, ::SparseArrays.SparseMatrixCSC{<:Real, Int64}, ::Union{Nothing, AbstractDict{TI, Matrix{TV}} where {TV<:Real, TI<:Union{Integer, String}}, AbstractDict{String, <:AbstractDict{TI, Matrix{TV}}} where {TV<:Real, TI<:Union{Integer, String}}}, ::Baysor.Utils.OutputPaths; polygon_format, gene_names, matrix_format)
   @ Baysor ~/.julia/packages/Baysor/7LPmz/src/data_loading/cli_wrappers.jl:224

Stacktrace:
 [1] run(coordinates::String, prior_segmentation::String; config::Baysor.Utils.RunOptions, x_column::Symbol, y_column::Symbol, z_column::Symbol, gene_column::Symbol, min_molecules_per_cell::Int64, scale::Float64, scale_std::String, n_clusters::Int64, prior_segmentation_confidence::Float64, output::String, plot::Bool, polygon_format::String, count_matrix_format::String)
   @ Baysor.CommandLine ~/.julia/scratchspaces/cc9f9468-1fbe-11e9-0acf-e9460511877c/sysimg/libbaysor.dylib:-1
in expression starting at /Users/ccn22/.julia/bin/baysor:15

Everything seems to run fine, but there is a problem with saving.

I am using Baysor version 0.7.1 on MacOS 15.1.1
Julia version 1.10.7
I have an M3 MacBook Pro

Any help would be much appreciated.

@ccnawrocki
Copy link
Author

Update: I have identified the problem. I read the transcripts (tx) files into R for a few of the select FOVs that did not work. After grouping by z position and counting, I get a table like this for all of the FOVs:

       z      n
   <int>  <int>
 1    -1      2
 2     0   8407
 3     1  16210
 4     2  28503
 5     3  52166
 6     4  89855
 7     5 117445
 8     6 134940
 9     7 167761
10     8      8

In each FOV, one of the z positions has very few tx associated with it. In this example, after removing the two tx that had a z position of -1, Baysor worked. So, in the general case, if I simply exclude all tx that occur in a certain z plane that contains less than say 5 tx, then I am in business.

Is there an option or flag that I am missing that would resolve this problem?

@VPetukhov
Copy link
Collaborator

Thank you for debugging it, @ccnawrocki ! That's the first time I see negative z. That might be the problem. I will test it more for the next release. Currently there are no flags to deal with it, unless you want to convert it all to 2D (--config.data.force-2d=true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants