I first tried using R
library(igraph) setwd("C:/Users/batagelj/data/icon/astro") g <- read_graph("astro-ph.gml",format="gml") write_graph(g,"astro-ph.net",format="pajek")
The problem is that the labels are lost in conversion.
Then I tried with python
import networkx as nx import os os.chdir("C:/Users/batagelj/data/icon/astro") G = nx.read_gml('astro-phX.gml') nx.write_pajek(G,"astro-phX.net")
There were problems with the original file astro-ph.gml
. It turned out that [
shouldn't be in a separate line. Using Textpad I replaced
node [
into
node [
read_gml
was now “happy” with the input file and I obtained a Pajek file - but with lines such as
27 "KLEIN, U" 0.0 0.0 ellipse
for nodes, and
52 4416 1.0 value 0.642857 value 0.642857
for edges.
Again using Textpad I replaced everywhere the string “0.0 0.0 ellipse”
with the empty string, the string “1.0 value ”
with the empty string. Afterward I replaced everywhere the string “value”
with the string ” ”
to move the unwanted information right. Finally I marked it in the Block Select Mode and deleted.