kharchenkolab / Baysor

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

ERROR: BoundsError: attempt to access 0-element Vector{GeometryBasics.Point2{Float64}} at index [1] #98

Closed mzj0418 closed 10 months ago

mzj0418 commented 10 months ago

Dear support,

When I tried to run the iss example data using the default config file provided (iss.toml), I ran into this error:

baysor run -p -c ./configs/iss.toml -o ./iss_output_no_dapi -p ./data/pciSeq_3-3.csv
[14:55:10] Info: Run Rc99f3a6a7 [14:55:10] Info: (2023-09-12) Run Baysor v0.6.2 [14:55:10] Info: Loading data... [14:55:13] Info: Loaded 1228540 transcripts [14:55:15] Info: Estimating noise level [14:55:46] Info: Done [14:56:04] Info: Clustering molecules... Progress: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| Time: 0:02:46 Iteration: 570 Max. difference: 0.00147 Fraction of probs changed: 0.223 [14:58:58] Info: Algorithm stopped after 570 iterations. Error: 0.00147. Converged: true. [14:58:58] Info: Done [14:58:58] Info: Initializing algorithm. Scale: 14.0, scale std: 3.5, initial #components: 307134, #molecules: 1228540. [14:59:10] Info: Using the following additional information about molecules: [:confidence, :cluster] [14:59:10] Info: Using 2D coordinates Progress: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| Time: 0:25:38 Iteration: 500 Noise level, %: 50.7 Num. components: 35186 [15:27:13] Info: Processing complete. [15:27:57] Info: Estimating local colors [15:34:59] Info: Estimating boundary polygons [15:35:21] Warning: Can't find border for cell 35480 └ Baysor.Processing /home/viktor_petukhov/.julia/dev/Baysor/src/processing/data_processing/boundary_estimation.jl:123 [15:36:22] Warning: Can't build border for a polygon of size 0 └ Baysor.Processing /home/viktor_petukhov/.julia/dev/Baysor/src/processing/data_processing/boundary_estimation.jl:63 [15:36:22] Info: Saving results to ./iss_output_no_dapi/segmentation.csv Progress: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| Time: 0:00:02 [15:36:37] Info: Plotting results [15:36:44] Info: Plot diagnostics [15:36:51] Info: Plot transcript assignment ERROR: BoundsError: attempt to access 0-element Vector{GeometryBasics.Point2{Float64}} at index [1] Stacktrace: [1] getindex @ ./essentials.jl:13 [inlined] [2] to_lines(polygon::Vector{GeometryBasics.Point2{Float64}}) @ Makie /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/basic_recipes/poly.jl:82 [3] to_lines(meshes::Vector{Vector{GeometryBasics.Point2{Float64}}}) @ Makie /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/basic_recipes/poly.jl:69 [4] #map#111 @ /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/scenes.jl:185 [inlined] [5] map(::typeof(Makie.to_lines), ::MakieCore.Poly{Tuple{Vector{Vector{GeometryBasics.Point2{Float64}}}}}, ::Observables.Observable{Vector{Vector{GeometryBasics.Point2{Float64}}}}) @ Makie /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/scenes.jl:182 [6] plot!(plot::MakieCore.Poly{Tuple{Vector{Vector{GeometryBasics.Point2{Float64}}}}}) @ Makie /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/basic_recipes/poly.jl:105 [7] plot!(scene::Makie.Scene, P::Type{MakieCore.Poly{Tuple{Vector{Vector{GeometryBasics.Point2{Float64}}}}}}, attributes::MakieCore.Attributes, input::Tuple{Observables.Observable{Vector{Vector{GeometryBasics.Point2{Float64}}}}}, args::Observables.Observable{Tuple{Vector{Vector{GeometryBasics.Point2{Float64}}}}}) @ Makie /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/interfaces.jl:432 [8] plot!(scene::Makie.Scene, P::Type{MakieCore.Poly}, attributes::MakieCore.Attributes, args::Vector{Vector{GeometryBasics.Point2{Float64}}}; kw_attributes::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Makie /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/interfaces.jl:344 [9] plot! @ /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/interfaces.jl:311 [inlined] [10] plot!(la::Makie.Axis, P::Type{MakieCore.Poly}, attributes::MakieCore.Attributes, args::Vector{Vector{GeometryBasics.Point2{Float64}}}; kw_attributes::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Makie /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/makielayout/blocks/axis.jl:792 [11] plot! @ /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/makielayout/blocks/axis.jl:779 [inlined] [12] #plot!#1405 @ /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/makielayout/blocks/axis.jl:809 [inlined] [13] plot!(P::Type{MakieCore.Poly}, args::Vector{Vector{GeometryBasics.Point2{Float64}}}; kw_attributes::Base.Pairs{Symbol, Any, NTuple{4, Symbol}, NamedTuple{(:strokecolor, :color, :strokewidth, :label), Tuple{String, String, Int64, String}}}) @ Makie /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/figureplotting.jl:69 [14] plot! @ /home/viktor_petukhov/.julia/packages/Makie/iECbF/src/figureplotting.jl:64 [inlined] [15] #poly!#56 @ /home/viktor_petukhov/.julia/packages/MakieCore/6sckc/src/recipes.jl:38 [inlined] [16] poly! @ /home/viktor_petukhov/.julia/packages/MakieCore/6sckc/src/recipes.jl:37 [inlined] [17] plot_molecules(df_spatial::DataFrames.DataFrame, polygons::Vector{Matrix{Float64}}; markersize::Float64, color::Vector{ColorTypes.ARGB{FixedPointNumbers.N0f8}}, size::Tuple{Int64, Int64}, poly_strokewidth::Int64, xlims::Nothing, ylims::Nothing, offset::Tuple{Int64, Int64}, is_noise::Nothing, annotation::Nothing, ann_colors::Nothing, legend::Bool, fontsize::Int64, ticksvisible::Bool, noise_ann::Nothing, shuffle_colors::Bool, append::Bool, polygon_kwargs::Nothing, axis_kwargs::Nothing, noise_kwargs::Nothing, legend_kwargs::Nothing, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:alpha, :title), Tuple{Float64, String}}}) @ Baysor.Reporting /home/viktor_petukhov/.julia/dev/Baysor/src/reporting/plots.jl:101 [18] plot_molecules @ /home/viktor_petukhov/.julia/dev/Baysor/src/reporting/plots.jl:14 [inlined] [19] #plot_molecules!#6 @ /home/viktor_petukhov/.julia/dev/Baysor/src/reporting/plots.jl:9 [inlined] [20] plot_molecules! @ /home/viktor_petukhov/.julia/dev/Baysor/src/reporting/plots.jl:9 [inlined] [21] plot_dataset_colors(df_spatial::DataFrames.DataFrame, color::Vector{ColorTypes.ARGB{FixedPointNumbers.N0f8}}; min_molecules_per_cell::Int64, min_pixels_per_cell::Int64, markersize::Float64, alpha::Float64, prior_polygons::Vector{Matrix{Float64}}, polygons::Vector{Matrix{Float64}}, ticks::Bool, axis_kwargs::Nothing, kwargs::Base.Pairs{Symbol, String, Tuple{Symbol}, NamedTuple{(:title,), Tuple{String}}}) @ Baysor.Reporting /home/viktor_petukhov/.julia/dev/Baysor/src/reporting/diagnostic_plots.jl:85 [22] plot_dataset_colors @ /home/viktor_petukhov/.julia/dev/Baysor/src/reporting/diagnostic_plots.jl:65 [inlined] [23] plot_transcript_assignment_panel(df_res::DataFrames.DataFrame; clusters::Vector{Int64}, gene_colors::Vector{ColorTypes.RGB{FixedPointNumbers.N0f8}}, file::String, kwargs::Base.Pairs{Symbol, Any, NTuple{4, Symbol}, NamedTuple{(:prior_polygons, :polygons, :min_molecules_per_cell, :min_pixels_per_cell), Tuple{Vector{Matrix{Float64}}, Vector{Matrix{Float64}}, Int64, Int64}}}) @ Baysor.Reporting /home/viktor_petukhov/.julia/dev/Baysor/src/reporting/cell_segmentation.jl:100 [24] plot_segmentation_report(segmented_df::DataFrames.DataFrame; tracer::Dict{Symbol, Any}, gene_colors::Symbol, clust_res::NamedTuple{(:exprs, :assignment, :diffs, :assignment_probs, :change_fracs), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Float64}, Matrix{Float64}, Vector{Float64}}}, comp_segs::Nothing, plot_transcripts::Bool, diagnostic_file::String, molecule_file::String, kwargs::Base.Pairs{Symbol, Any, NTuple{4, Symbol}, NamedTuple{(:prior_polygons, :polygons, :min_molecules_per_cell, :min_pixels_per_cell), Tuple{Vector{Matrix{Float64}}, Vector{Matrix{Float64}}, Int64, Int64}}}) @ Baysor.Reporting /home/viktor_petukhov/.julia/dev/Baysor/src/reporting/cell_segmentation.jl:128 [25] 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 /home/viktor_petukhov/.julia/dev/Baysor/src/cli/main.jl:141 [26] run @ /home/viktor_petukhov/.julia/dev/Baysor/src/cli/main.jl:51 [inlined] [27] command_main(ARGS::Vector{String}) @ Baysor.CommandLine /home/viktor_petukhov/.julia/packages/Comonicon/HDhA6/src/codegen/julia.jl:343 [28] command_main @ /home/viktor_petukhov/.julia/packages/Comonicon/HDhA6/src/codegen/julia.jl:90 [inlined] [29] julia_main() @ Baysor.CommandLine /home/viktor_petukhov/.julia/packages/Comonicon/HDhA6/src/frontend/cast.jl:481 [30] julia_main(; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Baysor /home/viktor_petukhov/.julia/dev/Baysor/src/Baysor.jl:42 [31] julia_main() @ Baysor /home/viktor_petukhov/.julia/dev/Baysor/src/Baysor.jl:42 [32] top-level scope @ none:1

(process:1907523): GLib-CRITICAL **: 15:36:55.982: g_datalist_id_set_data_full: assertion 'key_id > 0' failed

What is the cause of that error?

Best, Jun

mzj0418 commented 10 months ago

I also tried to run the starmap example data using the default config file provided (starmap.toml) and got an error with the following message.

baysor run -p -c ./configs/starmap.toml -o ./output_dapi -p ./data/molecules.csv ./data/segmentation.tiff

[18:24:35] Info: Run Reb7658cf6 [18:24:35] Info: (2023-09-12) Run Baysor v0.6.2 [18:24:35] Info: Loading data... [18:24:38] Info: Loaded 949459 transcripts [18:24:43] Info: Loading segmentation mask... [18:24:46] Warning: Minimum transcript coordinates are < 1: (8, 0). Filling it with 0. └ Baysor.DataLoading /home/viktor_petukhov/.julia/dev/Baysor/src/data_loading/prior_segmentation.jl:30 [18:24:47] Info: Done [18:24:47] Info: Estimating prior segmentation polygons... [18:25:11] Info: Done [18:25:11] Info: Estimating noise level [18:25:28] Info: Done [18:25:44] Info: Clustering molecules... [18:25:49] Warning: ICA did not converge, fall back to random initialization └ Baysor.Processing /home/viktor_petukhov/.julia/dev/Baysor/src/processing/bmm_algorithm/molecule_clustering.jl:147 Progress: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| Time: 0:02:09 Iteration: 490 Max. difference: 0.00589 Fraction of probs changed: 0.372 [18:28:01] Info: Algorithm stopped after 490 iterations. Error: 0.00589. Converged: true. [18:28:01] Info: Done [18:28:01] Info: Initializing algorithm. Scale: 100.0, scale std: 25.0, initial #components: 27126, #molecules: 949459. [18:28:04] Info: Using the following additional information about molecules: [:confidence, :cluster, :prior_segmentation] [18:28:04] Info: Using 3D coordinates Progress: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| Time: 0:15:13 Iteration: 500 Noise level, %: 33.13 Num. components: 1259 [18:43:22] Info: Processing complete. [18:43:25] Info: Estimating local colors [18:44:38] Warning: n=10000, which is > length(high_conf_ids) (0) └ Baysor.Processing /home/viktor_petukhov/.julia/dev/Baysor/src/processing/data_processing/initialization.jl:180 ERROR: ArgumentError: size(X, 2) must be greater than n_neighbors and nneighbors must be greater than 0 Stacktrace: [1] UMAP.UMAP(X::Matrix{Float32}, n_components::Int64; n_neighbors::Int64, metric::Distances.Euclidean, n_epochs::Int64, learning_rate::Int64, init::Symbol, min_dist::Float64, spread::Float64, set_operation_ratio::Int64, local_connectivity::Int64, repulsion_strength::Int64, neg_sample_rate::Int64, a::Nothing, b::Nothing) @ UMAP /home/viktorpetukhov/.julia/packages/UMAP/oqkOM/src/umap.jl:94 [2] UMAP_ @ /home/viktorpetukhov/.julia/packages/UMAP/oqkOM/src/umap.jl:77 [inlined] [3] #umap#7 @ /home/viktorpetukhov/.julia/packages/UMAP/oqkOM/src/umap.jl:45 [inlined] [4] umap @ /home/viktorpetukhov/.julia/packages/UMAP/oqkOM/src/umap.jl:43 [inlined] [5] fit(::Type{Baysor.Processing.UmapFit}, x::Matrix{Float32}; n_components::Int64, nn_interpolate::Int64, spread::Float64, min_dist::Float64, metric::Distances.Euclidean, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Baysor.Processing /home/viktor_petukhov/.julia/dev/Baysor/src/processing/data_processing/umap_wrappers.jl:22 [6] fit @ /home/viktor_petukhov/.julia/dev/Baysor/src/processing/data_processing/umap_wrappers.jl:17 [inlined] [7] gene_composition_color_embedding(pca::Matrix{Float32}, confidence::Vector{Float64}; normalize::Bool, sample_size::Int64, seed::Int64, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Baysor.Processing /home/viktor_petukhov/.julia/dev/Baysor/src/processing/data_processing/neighborhood_composition.jl:128 [8] gene_composition_color_embedding(pca::Matrix{Float32}, confidence::Vector{Float64}) @ Baysor.Processing /home/viktor_petukhov/.julia/dev/Baysor/src/processing/data_processing/neighborhood_composition.jl:116 [9] gene_composition_colors(df_spatial::DataFrames.DataFrame, k::Int64; method::Symbol, n_pcs::Int64, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Baysor.Processing /home/viktor_petukhov/.julia/dev/Baysor/src/processing/data_processing/neighborhood_composition.jl:165 [10] gene_composition_colors @ /home/viktor_petukhov/.julia/dev/Baysor/src/processing/data_processing/neighborhood_composition.jl:160 [inlined] [11] run_segmentation(df_spatial::DataFrames.DataFrame, gene_names::Vector{String}, opts::Baysor.Utils.SegmentationOptions; plot_opts::Baysor.Utils.PlottingOptions, min_molecules_per_cell::Int64, estimate_ncvs::Bool, plot::Bool, save_polygons::Bool, run_id::String) @ Baysor.Processing /home/viktor_petukhov/.julia/dev/Baysor/src/processing/utils/cli_wrappers.jl:72 [12] 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 /home/viktor_petukhov/.julia/dev/Baysor/src/cli/main.jl:123 [13] command_main(ARGS::Vector{String}) @ Baysor.CommandLine /home/viktor_petukhov/.julia/packages/Comonicon/HDhA6/src/codegen/julia.jl:343 [14] command_main @ /home/viktor_petukhov/.julia/packages/Comonicon/HDhA6/src/codegen/julia.jl:90 [inlined] [15] julia_main() @ Baysor.CommandLine /home/viktor_petukhov/.julia/packages/Comonicon/HDhA6/src/frontend/cast.jl:481 [16] julia_main(; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Baysor /home/viktor_petukhov/.julia/dev/Baysor/src/Baysor.jl:42 [17] julia_main() @ Baysor /home/viktor_petukhov/.julia/dev/Baysor/src/Baysor.jl:42 [18] top-level scope @ none:1

What is the cause of this error?

Best, Jun

andynkili commented 10 months ago

@mzj0418 ,

I have the same error "ERROR: ArgumentError: size(X, 2) must be greater than n_neighbors and n_neighbors must be greater than 0" (v.0.6.2). Were you successful in solving that issue?

Best, Andy

mzj0418 commented 10 months ago

@andynkili ,

I tried running Baysor with a lower version(v0.5.0) and it worked.

andynkili commented 10 months ago

@mzj0418,

Thank you for your response. Same here, I had to downgrade to v0.5.0. However, I would like to have the latest version up and running as it is faster (I had only one complete run on MERFISH data with low min_molecules_per_gene/min_molecules_per_cell), has loom output and more QC metrics (lifespan, max_cluster_frac and avg_assignment_confidence). I am not proficient in julia but still trying to figure out that error related to the umap function. If you have any clues or find a fix, please feel free to share it.

Best, Andy