-
Notifications
You must be signed in to change notification settings - Fork 28
Gexf #25
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
base: master
Are you sure you want to change the base?
Gexf #25
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
# This file is machine-generated - editing it directly is not advised | ||
|
||
[[ArnoldiMethod]] | ||
deps = ["DelimitedFiles", "LinearAlgebra", "Random", "SparseArrays", "StaticArrays", "Test"] | ||
git-tree-sha1 = "2b6845cea546604fb4dca4e31414a6a59d39ddcd" | ||
uuid = "ec485272-7323-5ecc-a04f-4719b315124d" | ||
version = "0.0.4" | ||
|
||
[[AutoHashEquals]] | ||
git-tree-sha1 = "45bb6705d93be619b81451bb2006b7ee5d4e4453" | ||
uuid = "15f4f7f2-30c1-5605-9d31-71845cf9641f" | ||
version = "0.2.0" | ||
|
||
[[Base64]] | ||
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" | ||
|
||
[[BinaryProvider]] | ||
deps = ["Libdl", "SHA"] | ||
git-tree-sha1 = "5b08ed6036d9d3f0ee6369410b830f8873d4024c" | ||
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" | ||
version = "0.5.8" | ||
|
||
[[CodecZlib]] | ||
deps = ["BinaryProvider", "Libdl", "TranscodingStreams"] | ||
git-tree-sha1 = "05916673a2627dd91b4969ff8ba6941bc85a960e" | ||
uuid = "944b1d66-785c-5afd-91f1-9de20f533193" | ||
version = "0.6.0" | ||
|
||
[[DataStructures]] | ||
deps = ["InteractiveUtils", "OrderedCollections"] | ||
git-tree-sha1 = "b7720de347734f4716d1815b00ce5664ed6bbfd4" | ||
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" | ||
version = "0.17.9" | ||
|
||
[[Dates]] | ||
deps = ["Printf"] | ||
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
|
||
[[DelimitedFiles]] | ||
deps = ["Mmap"] | ||
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" | ||
|
||
[[Distributed]] | ||
deps = ["Random", "Serialization", "Sockets"] | ||
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" | ||
|
||
[[EzXML]] | ||
deps = ["Printf", "XML2_jll"] | ||
git-tree-sha1 = "0fa3b52a04a4e210aeb1626def9c90df3ae65268" | ||
uuid = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615" | ||
version = "1.1.0" | ||
|
||
[[FileIO]] | ||
deps = ["Pkg"] | ||
git-tree-sha1 = "2c84c57aced468fa21763c66d3bef33adcd09ec7" | ||
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" | ||
version = "1.2.2" | ||
|
||
[[Inflate]] | ||
deps = ["Pkg", "Printf", "Random", "Test"] | ||
git-tree-sha1 = "b7ec91c153cf8bff9aff58b39497925d133ef7fd" | ||
uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9" | ||
version = "0.1.1" | ||
|
||
[[InteractiveUtils]] | ||
deps = ["Markdown"] | ||
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" | ||
|
||
[[JLD2]] | ||
deps = ["CodecZlib", "DataStructures", "FileIO", "Mmap", "Pkg", "Printf", "UUIDs"] | ||
git-tree-sha1 = "5deae9f0745ef505ed155a0029629cf08502ccab" | ||
uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819" | ||
version = "0.1.11" | ||
|
||
[[LibGit2]] | ||
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" | ||
|
||
[[Libdl]] | ||
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" | ||
|
||
[[Libiconv_jll]] | ||
deps = ["Libdl", "Pkg"] | ||
git-tree-sha1 = "802f5b23c846cb4ed568cae0bfb0ce0d2ba1926d" | ||
uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531" | ||
version = "1.16.0+1" | ||
|
||
[[LightGraphs]] | ||
deps = ["ArnoldiMethod", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"] | ||
git-tree-sha1 = "a0d4bcea4b9c056da143a5ded3c2b7f7740c2d41" | ||
uuid = "093fc24a-ae57-5d10-9952-331d41423f4d" | ||
version = "1.3.0" | ||
|
||
[[LinearAlgebra]] | ||
deps = ["Libdl"] | ||
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
|
||
[[Logging]] | ||
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" | ||
|
||
[[MacroTools]] | ||
deps = ["DataStructures", "Markdown", "Random"] | ||
git-tree-sha1 = "07ee65e03e28ca88bc9a338a3726ae0c3efaa94b" | ||
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" | ||
version = "0.5.4" | ||
|
||
[[Markdown]] | ||
deps = ["Base64"] | ||
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" | ||
|
||
[[MetaGraphs]] | ||
deps = ["JLD2", "LightGraphs", "Random"] | ||
git-tree-sha1 = "8900d368fa44bd61c7e598d6a0f577e347f3cf67" | ||
uuid = "626554b9-1ddb-594c-aa3c-2596fe9399a5" | ||
version = "0.6.5" | ||
|
||
[[Mmap]] | ||
uuid = "a63ad114-7e13-5084-954f-fe012c677804" | ||
|
||
[[Nullables]] | ||
git-tree-sha1 = "8f87854cc8f3685a60689d8edecaa29d2251979b" | ||
uuid = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd" | ||
version = "1.0.0" | ||
|
||
[[OrderedCollections]] | ||
deps = ["Random", "Serialization", "Test"] | ||
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1" | ||
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" | ||
version = "1.1.0" | ||
|
||
[[ParserCombinator]] | ||
deps = ["AutoHashEquals", "Nullables", "Printf", "Test"] | ||
git-tree-sha1 = "370b7fcf9ee754bf47b86389caded06a140fffcc" | ||
uuid = "fae87a5f-d1ad-5cf0-8f61-c941e1580b46" | ||
version = "2.0.0" | ||
|
||
[[Pkg]] | ||
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Test", "UUIDs"] | ||
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | ||
|
||
[[Printf]] | ||
deps = ["Unicode"] | ||
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" | ||
|
||
[[REPL]] | ||
deps = ["InteractiveUtils", "Markdown", "Sockets"] | ||
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" | ||
|
||
[[Random]] | ||
deps = ["Serialization"] | ||
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
|
||
[[Requires]] | ||
deps = ["UUIDs"] | ||
git-tree-sha1 = "d37400976e98018ee840e0ca4f9d20baa231dc6b" | ||
uuid = "ae029012-a4dd-5104-9daa-d747884805df" | ||
version = "1.0.1" | ||
|
||
[[SHA]] | ||
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" | ||
|
||
[[Serialization]] | ||
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" | ||
|
||
[[SharedArrays]] | ||
deps = ["Distributed", "Mmap", "Random", "Serialization"] | ||
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" | ||
|
||
[[SimpleTraits]] | ||
deps = ["InteractiveUtils", "MacroTools"] | ||
git-tree-sha1 = "2bdf3b6300a9d66fe29ee8bb51ba100c4df9ecbc" | ||
uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" | ||
version = "0.9.1" | ||
|
||
[[Sockets]] | ||
uuid = "6462fe0b-24de-5631-8697-dd941f90decc" | ||
|
||
[[SparseArrays]] | ||
deps = ["LinearAlgebra", "Random"] | ||
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" | ||
|
||
[[StaticArrays]] | ||
deps = ["LinearAlgebra", "Random", "Statistics"] | ||
git-tree-sha1 = "5a3bcb6233adabde68ebc97be66e95dcb787424c" | ||
uuid = "90137ffa-7385-5640-81b9-e52037218182" | ||
version = "0.12.1" | ||
|
||
[[Statistics]] | ||
deps = ["LinearAlgebra", "SparseArrays"] | ||
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | ||
|
||
[[Test]] | ||
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] | ||
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[[TranscodingStreams]] | ||
deps = ["Random", "Test"] | ||
git-tree-sha1 = "7c53c35547de1c5b9d46a4797cf6d8253807108c" | ||
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" | ||
version = "0.9.5" | ||
|
||
[[UUIDs]] | ||
deps = ["Random", "SHA"] | ||
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" | ||
|
||
[[Unicode]] | ||
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" | ||
|
||
[[XML2_jll]] | ||
deps = ["Libdl", "Libiconv_jll", "Pkg", "Zlib_jll"] | ||
git-tree-sha1 = "ed5603a695aefe3e9e404fc7b052e02cc72cfab6" | ||
uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a" | ||
version = "2.9.9+1" | ||
|
||
[[Zlib_jll]] | ||
deps = ["Libdl", "Pkg"] | ||
git-tree-sha1 = "fd36a6739e256527287c5444960d0266712cd49e" | ||
uuid = "83775a58-1f1d-513f-b197-d71354ab007a" | ||
version = "1.2.11+8" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name = "GraphIO" | ||
uuid = "2f0f772a-13f1-4a16-8943-390acdf9ae6b" | ||
authors = ["Seth Bromberger"] | ||
version = "0.4.0" | ||
|
||
[deps] | ||
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193" | ||
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" | ||
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615" | ||
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" | ||
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5" | ||
ParserCombinator = "fae87a5f-d1ad-5cf0-8f61-c941e1580b46" | ||
Requires = "ae029012-a4dd-5104-9daa-d747884805df" | ||
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" | ||
|
||
[compat] | ||
CodecZlib = "^0.6" | ||
EzXML = "^1.1" | ||
LightGraphs = "^1.3" | ||
MetaGraphs = "^0.6" | ||
ParserCombinator = "^2.0" | ||
Requires = "^1.0" | ||
SimpleTraits = "^0.9" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ module GEXF | |
|
||
using GraphIO.EzXML | ||
using LightGraphs | ||
using MetaGraphs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this here since you're including metagraphs.jl below, which has it. |
||
using LightGraphs: AbstractGraph, AbstractGraphFormat | ||
|
||
import LightGraphs: savegraph | ||
|
@@ -50,6 +51,7 @@ function savegexf(io::IO, g::LightGraphs.AbstractGraph, gname::String) | |
return 1 | ||
end | ||
|
||
savegraph(io::IO, g::AbstractGraph, gname::String, ::GEXFFormat) = savegexf(io, g, gname) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we still need this since without it we won't be able to save non-Metagraphs. |
||
|
||
|
||
include("metagraphs.jl") | ||
end #module |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using MetaGraphs | ||
|
||
function idandtypes(prs) | ||
k2id = Dict{Symbol,Int}() | ||
k2type = Dict{Symbol,Type}() | ||
i = 1 | ||
for vs in values(prs) | ||
for (k,v) in (vs) | ||
if haskey(k2id, k) | ||
if k2type[k] != typeof(v) | ||
k2type[k] = promote_type(k2type[k],typeof(v)) | ||
end | ||
else | ||
k2id[k] = i | ||
i += 1 | ||
k2type[k] = typeof(v) | ||
end | ||
end | ||
end | ||
return(k2id, k2type) | ||
end | ||
|
||
type2string(::Type{T}) where {T<:Integer} = "integer" | ||
type2string(::Type{T}) where {T<:AbstractFloat} = "double" | ||
type2string(::Type{T}) where {T<:Char} = "string" | ||
type2string(::Type{T}) where {T<:AbstractString} = "string" | ||
|
||
function exportattributes(xg, prs, element_type) | ||
(k2id, k2type) = idandtypes(prs) | ||
if !isempty(k2id) | ||
xattrs = addelement!(xg, "attributes") | ||
xattrs["class"] = element_type | ||
for (k,i) in k2id | ||
xat=addelement!(xattrs, "attribute") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggest spacing here |
||
xat["id"] = i | ||
xat["title"] = k | ||
xat["type"] = type2string(k2type[k]) | ||
end | ||
end | ||
k2id | ||
end | ||
|
||
function add_properties!(xv, ks, prs) | ||
isempty(prs) && return | ||
av = addelement!(xv, "attvalues") | ||
for (k,v) in prs | ||
av = addelement!(av, "attvalue") | ||
av["for"] = ks[k] | ||
av["value"] = v | ||
end | ||
end | ||
|
||
function savegexf(io::IO, g::MetaGraph, gname::String) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be |
||
xdoc = XMLDocument() | ||
xroot = setroot!(xdoc, ElementNode("gexf")) | ||
xroot["xmlns"] = "http://www.gexf.net/1.2draft" | ||
xroot["version"] = "1.2" | ||
xroot["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance" | ||
xroot["xsi:schemaLocation"] = "http://www.gexf.net/1.2draft/gexf.xsd" | ||
|
||
xmeta = addelement!(xroot, "meta") | ||
addelement!(xmeta, "description", gname) | ||
xg = addelement!(xroot, "graph") | ||
strdir = is_directed(g) ? "directed" : "undirected" | ||
xg["defaultedgetype"] = strdir | ||
|
||
|
||
vks = exportattributes(xg, g.vprops, "node") | ||
eks = exportattributes(xg, g.eprops, "edge") | ||
|
||
xnodes = addelement!(xg, "nodes") | ||
for v in vertices(g) | ||
xv = addelement!(xnodes, "node") | ||
xv["id"] = "$(v-1)" | ||
add_properties!(xv, vks, props(g, v)) | ||
end | ||
|
||
xedges = addelement!(xg, "edges") | ||
m = 0 | ||
for e in LightGraphs.edges(g) | ||
xe = addelement!(xedges, "edge") | ||
xe["id"] = "$m" | ||
xe["source"] = "$(src(e)-1)" | ||
xe["target"] = "$(dst(e)-1)" | ||
add_properties!(xe, eks, props(g, e)) | ||
m += 1 | ||
end | ||
|
||
prettyprint(io, xdoc) | ||
return 1 | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need Manifest.toml in the repo... you should add this to
.gitignore
.