Baysor
Baysor copied to clipboard
Errors about boundary_polygons
Hi, I'm using the Julia-1.7.0 on ubuntu and successfully ran the Baysor for the first few steps.
However, when I want to analyze the boundary using the following codes:
grid_step = 1.0
@time polygons = B.boundary_polygons(df_spatial, df_spatial.cell, grid_step=grid_step);
length(polygons)
I got:
MethodError: no method matching kruskal_mst(::SimpleWeightedGraph{Int64, Float64}) Closest candidates are: kruskal_mst(::AG) where {U, AG<:LightGraphs.AbstractGraph{U}} at ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:338 kruskal_mst(::AG, ::AbstractMatrix{T}; kwargs...) where {T<:Real, U, AG<:LightGraphs.AbstractGraph{U}} at ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:338 kruskal_mst(::Type{SimpleTraits.Not{LightGraphs.IsDirected{AG}}}, ::AG, ::AbstractMatrix{T}; minimize) where {T<:Real, U, AG<:LightGraphs.AbstractGraph{U}} at ~/.julia/packages/LightGraphs/IgJif/src/spanningtrees/kruskal.jl:12
Stacktrace: [1] border_mst(border_points::Vector{Vector{UInt32}}; min_edge_length::Float64, max_edge_length::Float64) @ Baysor ~/.julia/packages/Baysor/Kag1d/src/data_processing/boundary_estimation.jl:65 [2] border_mst(border_points::Vector{Vector{UInt32}}) @ Baysor ~/.julia/packages/Baysor/Kag1d/src/data_processing/boundary_estimation.jl:42 [3] _broadcast_getindex_evalf @ ./broadcast.jl:670 [inlined] [4] _broadcast_getindex @ ./broadcast.jl:643 [inlined] [5] getindex @ ./broadcast.jl:597 [inlined] [6] copy @ ./broadcast.jl:899 [inlined] [7] materialize @ ./broadcast.jl:860 [inlined] [8] extract_polygons_from_label_grid(grid_labels::Matrix{UInt32}; min_border_length::Int64, shape_method::Symbol, max_dev::Float64, exclude_labels::Vector{Int64}, offset::Vector{Float64}, grid_step::Float64) @ Baysor ~/.julia/packages/Baysor/Kag1d/src/data_processing/boundary_estimation.jl:231 [9] boundary_polygons(pos_data::Matrix{Float64}, cell_labels::Vector{Int64}; min_x::Nothing, max_x::Nothing, grid_step::Float64, min_border_length::Int64, shape_method::Symbol, max_dev::Float64, bandwidth::Float64, exclude_labels::Vector{Int64}, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Baysor ~/.julia/packages/Baysor/Kag1d/src/data_processing/boundary_estimation.jl:270 [10] #boundary_polygons#214 @ ~/.julia/packages/Baysor/Kag1d/src/data_processing/boundary_estimation.jl:248 [inlined] [11] top-level scope @ ./timing.jl:220 [inlined] [12] top-level scope @ ./In[89]:0 [13] eval @ ./boot.jl:373 [inlined] [14] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String) @ Base ./loading.jl:1196
Is that because I'm using the wrong versions of dependency packages?
Thank you in advance! :)
Hi,
I read about the source codes and find out that this is caused by the conflicts among the current versions of Graph, LightGraphs, and SimpleWeightedGraphs.
The following is my codes for two specific functions:
function find_longest_paths(g_inc::SimpleWeightedGraph{Int64, Float64})::Array{Vector{Int}, 1}
mtx_after_simple = SimpleGraph(g_inc)
edges = collect(Graphs.edges(mtx_after_simple))
if length(edges) == 0
return []
end
vert_counts = StatsBase.countmap(vcat(map(x -> [x.src, x.dst], edges)...));
n_verts = maximum(keys(vert_counts));
leafs = collect(keys(vert_counts))[collect(values(vert_counts)) .== 1];
conn_comps = SimpleWeightedGraphs.connected_components(g_inc);
longest_paths = Array{Int, 1}[]
for vert_inds in conn_comps
if size(vert_inds, 1) < 3
continue
end
comp_leafs = intersect(vert_inds, leafs)
max_dist, max_source, max_target = -1, -1, -1
paths = []
for src_id in comp_leafs
paths = Graphs.dijkstra_shortest_paths(g_inc, src_id);
cur_target = comp_leafs[findmax(paths.dists[comp_leafs])[2]];
if isinf(paths.dists[cur_target])
@warn "Infinite distance for verteces $src_id and $cur_target"
continue
end
if paths.dists[cur_target] > max_dist
max_dist = paths.dists[cur_target]
max_target = cur_target
max_source = src_id
end
end
if max_source < 0 | max_target < 0
@warn "Source/target vertex id is 0"
continue
end
cur_target = max_target
path = Int[cur_target]
paths = Graphs.dijkstra_shortest_paths(g_inc, max_source);
if isinf(paths.dists[max_target])
@warn "Infinite distance for verteces $src_id and $cur_target"
continue
end
while cur_target != max_source
cur_target = paths.parents[cur_target]
push!(path, cur_target)
if size(path, 1) > 2 * paths.dists[max_target]
@warn "Can't build path"
break
end
end
push!(longest_paths, path)
end
return longest_paths
end
function border_mst(border_points::Array{<:Vector{<:Real},1}; min_edge_length::Float64=0.1, max_edge_length::Float64=1.5)
leafsize = min(size(border_points, 1), 10) # Some performance feature?
tree = KDTree(Matrix{Float64}(hcat(border_points...)), leafsize=leafsize);
src_verts, dst_verts, weights = Int[], Int[], Float64[]
edges = Set{Tuple{Int, Int}}()
n_neighbs = min(length(border_points), 5)
for (i, p) in enumerate(border_points)
inds, dists = knn(tree, p, n_neighbs, true) # 5 to get border for sure
filt_mask = (dists .> min_edge_length) .& (dists .< max_edge_length)
for (ind, dist) in zip(inds[filt_mask], dists[filt_mask])
edge = sort([i, ind])
edge = (edge...,)
if !(edge in edges)
push!(src_verts, edge[1])
push!(dst_verts, edge[2])
push!(weights, dist)
push!(edges, edge)
end
end
end
adj_mtx = sparse(src_verts, dst_verts, weights, size(border_points, 1), size(border_points, 1));
edges_after = SimpleWeightedGraphs.kruskal_mst(SimpleWeightedGraph(adj_mtx + adj_mtx'));
mtx_after_a = SimpleWeightedGraph(Int(sqrt(length(adj_mtx))));
for i in edges_after
add_edge!(mtx_after_a,i.src,i.dst,i.weight);
end
return mtx_after_a;
end
Here are my versions for all the packages:
[cc9f9468] Baysor v0.5.1 https://github.com/kharchenkolab/Baysor.git#master
[336ed68f] CSV v0.10.1
[13f3f980] CairoMakie v0.7.0
[5ae59095] Colors v0.12.8
[a93c6f00] DataFrames v1.3.1
[1313f7d8] DataFramesMeta v0.10.0
[31c24e10] Distributions v0.25.40
[7a1cc6ca] FFTW v1.4.5
[86223c79] Graphs v1.5.1
[7073ff75] IJulia v1.23.2
[787d08f9] ImageMorphology v0.3.0
[916415d5] Images v0.25.1
[4138dd39] JLD v0.12.5
[033835bb] JLD2 v0.4.17
[682c06a0] JSON v0.21.2
[5ab0869b] KernelDensity v0.6.3
[093fc24a] LightGraphs v1.3.5
[23992714] MAT v0.10.2
[ee78f7c6] Makie v0.16.1
[6f286f6a] MultivariateStats v0.8.0
[b8a86587] NearestNeighbors v0.4.9
[ccf2f8ad] PlotThemes v2.0.1
[91a5bcdd] Plots v1.25.6
[92933f4c] ProgressMeter v1.7.1
[438e738f] PyCall v1.93.0 https://github.com/JuliaPy/PyCall.jl.git#master
[d330b81b] PyPlot v2.10.0
[55797a34] SimpleGraphs v0.7.15
[47aef6b3] SimpleWeightedGraphs v1.2.1
[90137ffa] StaticArrays v1.3.2
[2913bbd2] StatsBase v0.33.14
[c4f8c510] UMAP v0.1.9 https://github.com/dillondaudert/UMAP.jl.git#master
and I'm running on Julia 1.7.0 (2021-11-30) for Ubuntu.
Hope this would help
Thanks for the input, @JuanruMaryGuo ! Indeed, LightGraphs.jl were archived and now should be replaced with Graphs.jl. So I did that in the dev (https://github.com/kharchenkolab/Baysor/commit/ada8a77b4cdf0b91b5fefd2cd25ed987b695ed30) and now it seems to work. I also fixed some dependencies, so hopefully there will be fewer problems in the future.