GML

GML is a simple text format that is easily read and written by both machines and humans. GML is used by a number of different graph drawing programs and libraries, including Graphlet, yEd, and LEDA.

Main Page

A description with examples is here.

Short Example


graph [
  node [
    id 7
    label "5"
    edgeAnchor "corners"
    labelAnchor "n"
    graphics [
      center [ x 82.0000 y 42.0000 ]
      w 16.0000
      h 16.0000
      type "rectangle"
      fill "#000000"
    ]
  ]
  node [
    id 15
    label "13"
    edgeAnchor "corners"
    labelAnchor "c"
    graphics [
      center [ x 73.0000 y 160.000 ]
      w 16.0000
      h 16.0000
      type "rectangle"
      fill "#FF0000"
    ]
  ]
  edge [
    label "24"
    labelAnchor "first"
    source 7
    target 15
    graphics [
      type "line"
      arrow "last"
      Line [
        point [ x 82.0000 y 42.0000 ]
        point [ x 10.0000 y 10.0000 ]
        point [ x 100.000 y 100.000 ]
        point [ x 80.0000 y 30.0000 ]
        point [ x 120.000 y 230.000 ]
        point [ x 73.0000 y 160.000 ]
      ]
    ]
  ]
]

2nd Short Example for De-Coding in MATLAB Example


...

 ]
  node
  [
    id 26
  ]
  node
  [
    id 27
  ]
  node
  [
    id 28
  ]
  node

...

edge

  [
    source 187
    target 169
  ]
  edge
  [
    source 187
    target 185
  ]
  edge
  [
    source 188
    target 61
  ]

etc...


For the data posted on Newman's site that I've looked at, the format is as above: a node assignment portion at the beginning (this one is boring since it's for power; generally there are names instead of numbers..) followed by the description of edges (this one is also boring in that respect, for it it both undirected and unweighted, though the terms 'source' and 'target' imply directedness.) Files with this pattern are rather simple to decode using a a modified example file from the MATLAB help called 'litcount.m':

Litcount.m (modified)


function y = litcount(filename, literal) % Search for number of string matches per line.

fid = fopen(filename, 'rt'); y = 0; while feof(fid) == 0

   tline = fgetl(fid);
   matches = findstr(tline, literal);
   num = length(matches);
   if num > 0
      y = y + num;

      new_ent = str2num(tline(##:end))+1;
      finders(y) = new_ent;
      %pause
   end

end fclose(fid); y = finders;


The only part needing modification is after the 'if num > 0', which is entered upon a positive match of your desired search term (literal, i.e. 'source' or 'target' in this case.) Specifically, the value of ## needs to be entered to match the point at which the number begins (in the case of 'source' and 'value' in these files, it's 12) which is just the 'column' index of the first digit of the referenced number. One (or I did, rather) creates a 1xn vector of 'sources' and a 1xn vector of 'targets' and places '1's (or the indicated weight) at those coordinates in a sparse matrix and like magic, one has built a MATLAB readable matrix from a .gml file. (Warning: Results may vary. Use as directed. Check with you doctor to see if litcount.m is right for you.)