From 8ec2ab3a4bbb4776927ab381a966391290badc67 Mon Sep 17 00:00:00 2001 From: Rachel Kurchin Date: Wed, 14 Feb 2024 22:34:32 -0500 Subject: [PATCH] LightGraphs -> Graphs and associated other compats Signed-off-by: Rachel Kurchin --- Project.toml | 11 +++++------ src/Nodariety.jl | 2 +- src/graph_analysis.jl | 8 ++++---- src/graph_vis.jl | 2 +- src/hyphengraph.jl | 37 +++++++++++++++++-------------------- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/Project.toml b/Project.toml index 8775a67..dda4d7d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Nodariety" uuid = "ffab58b1-199d-4bd9-83d9-8aaad2b4ff2e" authors = ["Rachel Kurchin "] -version = "0.1.0" +version = "0.1.1" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" @@ -13,7 +13,7 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Fontconfig = "186bb1d3-e1f7-5a2c-a377-96d770f13627" GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2" -LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" +Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" LongestPaths = "3a25c17e-307c-411a-a047-890a9a5fbb4d" MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5" NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a" @@ -30,9 +30,8 @@ DataFrames = "1" Fontconfig = "0.4" GLMakie = "0.4" GraphMakie = "0.2" -LightGraphs = "1.3" -LongestPaths = "0.1" -MetaGraphs = "0.6" -NetworkLayout = "0.4" +LongestPaths = "0.2.4" +MetaGraphs = "0.7" +NetworkLayout = "0.4.6" StatsBase = "0.33" julia = "1.6" diff --git a/src/Nodariety.jl b/src/Nodariety.jl index 914f0a9..4115fd6 100644 --- a/src/Nodariety.jl +++ b/src/Nodariety.jl @@ -1,7 +1,7 @@ module Nodariety using CSV, DataFrames -using LightGraphs +using Graphs include("hyphengraph.jl") hg = HyphenGraph() diff --git a/src/graph_analysis.jl b/src/graph_analysis.jl index b1582de..7131aa6 100644 --- a/src/graph_analysis.jl +++ b/src/graph_analysis.jl @@ -23,7 +23,7 @@ function longest_path(graph::HyphenGraph = hg) local longest_length = 0 local longest_start_inds = [1] for i = 1:nv(graph) - p = find_longest_path(graph, i, log_level = 0) + p = find_longest_path(graph.graph, i, log_level = 0) len = length(p.longest_path) - 1 if len > longest_length longest_length = len @@ -33,7 +33,7 @@ function longest_path(graph::HyphenGraph = hg) end end paths = [ - find_longest_path(graph, i, log_level = 0).longest_path for i in longest_start_inds + find_longest_path(graph.graph, i, log_level = 0).longest_path for i in longest_start_inds ] return paths end @@ -41,7 +41,7 @@ end """ most_central(centrality_fcn, g=hg) -Return the most central node in `g` according to the provided centrality measure. `centrality_fcn` can be any of the LightGraphs centrality measures: https://juliagraphs.org/LightGraphs.jl/stable/centrality/ e.g. betweenness_centrality, closeness_centrality, degree_centrality, and many others... +Return the most central node in `g` according to the provided centrality measure. `centrality_fcn` can be any of the Graphs centrality measures: https://juliagraphs.org/Graphs.jl/stable/algorithms/centrality/ e.g. betweenness_centrality, closeness_centrality, degree_centrality, and many others... See also: [`all_centrals`](@ref) """ @@ -64,7 +64,7 @@ const centrality_fcns = [ """ all_centrals(fcns=centrality_fcns, graph=hg) -Iterate through every centrality measure provided (defaults to the LightGraphs list) and find the most central node of it in `graph`. Print results. +Iterate through every centrality measure provided (defaults to the Graphs.jl list) and find the most central node of it in `graph`. Print results. See also: [`most_central`](@ref) diff --git a/src/graph_vis.jl b/src/graph_vis.jl index f6881d8..9728684 100644 --- a/src/graph_vis.jl +++ b/src/graph_vis.jl @@ -1,5 +1,5 @@ using Colors -using LightGraphs +using Graphs using DataFrames using Serialization using GLMakie diff --git a/src/hyphengraph.jl b/src/hyphengraph.jl index 30faffe..bd562cc 100644 --- a/src/hyphengraph.jl +++ b/src/hyphengraph.jl @@ -1,4 +1,4 @@ -using LightGraphs, MetaGraphs +using Graphs, MetaGraphs using DataFrames using Serialization @@ -82,26 +82,20 @@ function Base.show(io::IO, g::HyphenGraph) print(io, st) end -# implement LightGraphs API... -const lg = LightGraphs -# Base.reverse +# implement Graphs API... Base.zero(HyphenGraph) = HyphenGraph(MetaDiGraph(zero(SimpleDiGraph)), DataFrame(), DataFrame()) -lg.edges(g::HyphenGraph) = lg.edges(g.graph) -lg.edgetype(g::HyphenGraph) = lg.edgetype(g.graph) -lg.has_edge(g::HyphenGraph, i, j) = lg.has_edge(g.graph, i, j) -lg.has_vertex(g::HyphenGraph, v::Integer) = lg.has_vertex(g.graph, v) -lg.inneighbors(g::HyphenGraph, node) = lg.inneighbors(g.graph, node) -lg.ne(g::HyphenGraph) = lg.ne(g.graph) -lg.nv(g::HyphenGraph) = lg.nv(g.graph) -lg.outneighbors(g::HyphenGraph, node) = lg.outneighbors(g.graph, node) -lg.vertices(g::HyphenGraph) = lg.vertices(g.graph) -lg.eltype(g::HyphenGraph) = lg.eltype(g.graph) -lg.weights(g::HyphenGraph) = lg.weights(g.graph) -# I'm not sure which one of these I need, but even with all of them calling some of the centrality stuff directly on the HyphenGraph doesn't seem to work :/ -lg.is_directed(g::HyphenGraph) = true -lg.is_directed(::Type{HyphenGraph}) = true -#lg.is_directed(HyphenGraph) = true +Graphs.edges(g::HyphenGraph) = Graphs.edges(g.graph) +Graphs.edgetype(g::HyphenGraph) = Graphs.edgetype(g.graph) +Graphs.has_edge(g::HyphenGraph, i, j) = Graphs.has_edge(g.graph, i, j) +Graphs.has_vertex(g::HyphenGraph, v::Integer) = Graphs.has_vertex(g.graph, v) +Graphs.inneighbors(g::HyphenGraph, node) = Graphs.inneighbors(g.graph, node) +Graphs.ne(g::HyphenGraph) = Graphs.ne(g.graph) +Graphs.nv(g::HyphenGraph) = Graphs.nv(g.graph) +Graphs.outneighbors(g::HyphenGraph, node) = Graphs.outneighbors(g.graph, node) +Graphs.vertices(g::HyphenGraph) = Graphs.vertices(g.graph) +Graphs.is_directed(g::HyphenGraph) = true +Graphs.is_directed(::Type{HyphenGraph}) = true # helper fcn function edge_has_nodes(edge, new_edges, index_map) @@ -116,7 +110,10 @@ function edge_has_nodes(edge, new_edges, index_map) end end -function lg.induced_subgraph( +# NB that this implementation messes up the indices currently +# which is why in graph_analysis.jl, I have to call induced_subraph on graph.graph +# instead of just graph +function Graphs.induced_subgraph( g::HyphenGraph{T}, vlist::AbstractVector{U}, ) where {U<:Integer,T<:Integer}