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

Missing concrete examples on how to get a graph from each file format #37

Closed
empet opened this issue Sep 21, 2021 · 11 comments
Closed

Missing concrete examples on how to get a graph from each file format #37

empet opened this issue Sep 21, 2021 · 11 comments

Comments

@empet
Copy link

empet commented Sep 21, 2021

I migrated this year from Python to Julia and after working for 7 years with python igraph and networkx, yesterday I started testing LightGraphs.jl and GraphIO.jl. I've been searching the web more than 1 hour to find out how to read a graph from a GML file. Unfortunately there is no documentation for GraphIO :(

?GML.loadgml
No documentation found.

GraphIO.GML.loadgml is a Function.

# 1 method for generic function "loadgml":
[1] loadgml(io::IO, gname::String) in GraphIO.GML at ....path to GML.jl

I couldn't find any (working) example on julia discourse or SO. To be more precise, I want to load and parse this gml file: https://github.com/empet/Datasets/blob/master/gstrang_descendants.gml.
with the following code (suggested by deprecation.jl):

using LightGraphs
using ParserCombinator               
using GraphIO: GML
f = open("gstrang_descendants.gml")
GML.loadgml(f, "graph")

What string should be passed as gname? I also tried "digraph" but got the same error:

KeyError: key :graph not found

Please give at least in the README file an example to see concretely how we can define a graph loaded from each file format.

@sbromberger
Copy link
Contributor

sbromberger commented Sep 21, 2021

The README has an example at the bottom:

graph = loadgraph("path_to_graph/my_edgelist.txt", "graph_key", EdgeListFormat())

For GML, you'd replace EdgeListFormat() with GMLFormat().

To your specific problem, since you can store multiple graphs in a GML file, you need to specify the graph name. If you don't know it, you can use loadgraphs() to get a dictionary containing all the graphs (keyed by graph name).

@sbromberger
Copy link
Contributor

Also, the docstring for loadgraph is defined in LightGraphs:

help?> loadgraph
search: loadgraph loadgraphs

  loadgraph(file, gname="graph", format=LGFormat())

  Read a graph named gname from file in the format format.

  Implementation Notes
  ––––––––––––––––––––––

  gname is graph-format dependent and is only used if the file contains
  multiple graphs; if the file format does not support multiple graphs, this
  value is ignored. The default value may change in the future.

@empet
Copy link
Author

empet commented Sep 21, 2021

I'm sorry, but this approach (with loadgraph) has been the first one I used, but I got the error displayed in deprecation.jl:
https://github.com/JuliaGraphs/GraphIO.jl/blob/master/src/deprecations.jl#L33.
That's why I installed ParserCombinator and called GML.loadgml() suggested by this line:
https://github.com/JuliaGraphs/GraphIO.jl/blob/master/src/GML/Gml.jl#L32
Please, check whether I'm right or no, running your posted code with a real gml file.

@sbromberger
Copy link
Contributor

The depwarn is just that - a warning. It will still execute the proper code, but it will also tell you what needs to be done to avoid such warnings in the future.

Please show the exact steps you used (with loadgraph) along with the warnings/errors you experienced. Please also post a link to the GML file so we can try to reproduce your errors.

@empet
Copy link
Author

empet commented Sep 21, 2021

Here is the GML file: https://github.com/empet/Datasets/blob/master/gstrang_descendants.gml.
I downloaded it in the working directory and

  • the first trial was:
using LightGraphs, GraphIO
graph = loadgraph("gstrang_descendants.gml",  "graph", GMLFormat())

error:

UndefVarError: GML not defined

Stacktrace:
 [1] GMLFormat()
   @ GraphIO C:\Users\empet\.julia\packages\GraphIO\IgxnP\src\deprecations.jl:39

I installed ParserCombinator.jl and performed:

  • the second trial
using LightGraphs, ParserCombinator, GraphIO 
G = loadgraph("gstrang_descendants.gml",  GMLFormat())
#G = loadgraph("gstrang_descendants.gml", "graph", GMLFormat())

and both cases (with "graph" or without it) give the same error:

Graph graph not found
  • the third one was already pasted in my initial post

@sbromberger
Copy link
Contributor

I'm getting a 404 error trying to access that gml file....

@empet
Copy link
Author

empet commented Sep 22, 2021

It's strange that it displays error 404, because the same link in my initial post works.
Here is a new link: https://raw.githubusercontent.com/empet/Datasets/master/gstrang_descendants.gml

@sbromberger
Copy link
Contributor

That linked worked.
Using loadgraphs, we can see the name of the graph in the file is called digraph:

julia> z = loadgraphs("g.gml", GraphIO.GML.GMLFormat())
Dict{String, AbstractGraph} with 1 entry:
  "digraph" => {195, 195} directed simple Int64 graph

Then you can just reference z["digraph"], or load the graph directly:

julia> g = loadgraph("g.gml", "digraph", GraphIO.GML.GMLFormat())
{195, 195} directed simple Int64 graph

@empet
Copy link
Author

empet commented Sep 22, 2021

Thank you very much. I close this issue, but please, update the docstrings and the README file with new form of graph format, GraphIO.GML.GMLFormat(), and correspondingly for other formats. Also, the attribute gname (the graph name) is not suggestive, because "graph" or "digraph" is the graph type, not its name.

@empet empet closed this as completed Sep 22, 2021
@sbromberger
Copy link
Contributor

but please, update the docstrings and the README file with new form of graph format, GraphIO.GML.GMLFormat(), and correspondingly for other formats.

PRs welcome. We're all volunteers, after all.

@empet
Copy link
Author

empet commented Sep 22, 2021

After getting acquainted with Julia Graphs I'll do it. This was my first attempt to define a graph, and its layout, using Julia packages, and I'm absolutely thrilled how simple it is to generate a tree, read from a file, compared to Python network libraries. This is the tree involved in my question above, with node positions returned by Buchheim layout, and then those at the same level are mapped to circles, while edges are drawn as Bezier curves (via PlotlyJS.jl):
Gstrang

Thank you again, for these great packages!

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