Skip to content

Instantly share code, notes, and snippets.

@jboynyc
Created February 7, 2017 17:19
Show Gist options
  • Save jboynyc/d7cb5be34f05cc10e96579aa4b6cb3c5 to your computer and use it in GitHub Desktop.
Save jboynyc/d7cb5be34f05cc10e96579aa4b6cb3c5 to your computer and use it in GitHub Desktop.
Run SNAP RolX role extraction on an IGraph network graph.
import subprocess
from collections import defaultdict
from tempfile import NamedTemporaryFile
import igraph as ig
ROLX_BIN = 'Snap-3.0/examples/rolx/testrolx'
def extract_roles(input_graph, min_roles=2, max_roles=3):
results = defaultdict(list)
with NamedTemporaryFile() as input_file, NamedTemporaryFile() as output_file:
input_graph.write_edgelist(input_file.name)
subprocess.check_call([ROLX_BIN,
'-i:{}'.format(input_file.name),
'-o:{}'.format(output_file.name),
'-l:{}'.format(min_roles),
'-u:{}'.format(max_roles)])
output = output_file.readlines()
for node, role in (i.split() for i in output[2:]):
results[int(role)].append(int(node))
return ig.VertexCover(input_graph, results.values())
@jboynyc
Copy link
Author

jboynyc commented Feb 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment