#!/usr/bin/perl -Wall

use strict;
use Data::Dumper;

# LOAD SIF
my $E; # edges as a hash of hash
#~ open(F,'grn.simple.sif');
while (<>) {
	chomp;
	my ($from, $to) = $_ =~ /^(\S+)\s\S+\s(\S+)$/;
	$E->{$from}->{$to} = 1;
	$E->{$to}->{$from} = 1; # if undirected
}
close(F);

# OUTPUT MATRIX
#~ open G, '>grn.simple.mat';
# header of output (sorted list of vertices labels)
print "\t".join("\t", sort keys %$E);

# rows
foreach my $i (sort keys %$E) {
	my $line = $i; # vertex label
	foreach my $j (sort keys %$E) { # output 1 or 0 depending on edge
		if (defined $E->{$i} && defined $E->{$i}->{$j}) {
			$line.="\t1";
		}
		else {
			$line.="\t0";
		}
	}
	print $line;
}
