-
Notifications
You must be signed in to change notification settings - Fork 0
/
toGdf.perl
57 lines (55 loc) · 1006 Bytes
/
toGdf.perl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;
my %rank;
open A, "zcat $ARGV[0]|";
while (<A>){
chop();
my ($f, $t)=split(/;/, $_);
$rank{$f}=$t;
};
open A, "zcat $ARGV[1] |";
my $i=0;
my %l;
while(<A>){
chop();
$l{$i} = $rank{$_} if defined $rank{$_};
$i++;
};
$i=0;
my %cl;
my %cn;
while(<STDIN>){
chop();
my ($c,$w) = split(/;/);
$cl{$i} = $c;
$cn{$c}{$i}++;
$i++;
};
my (%n, %e);
open A, "$ARGV[2]";
while(<A>){
chop();
my ($a, $b, $w) = split(/ /);
my ($f,$t) = sort ($cl{$a}, $cl{$b});
$n{$f}++;
$n{$t}++;
$e{"$f,$t"} += $w if $f ne $t;
}
my @ns = keys %n;
print "nodedef> name VARCHAR,label VARCHAR,height DOUBLE\n";
for my $no (@ns){
my @nns = keys %{$cn{$no}};
my $cnn = "unknown";
for my $na (@nns){
if (defined $l{$na}) {
$cnn = $l{$na};
last;
}
}
$cnn =~ s/["']/ /g;
print "$no,".'"'.$cnn.'"'.",".log($n{$no})."\n";
}
print "edgedef> node1,node2,weight DOUBLE,directed BOOLEAN\n";
for my $ed (keys %e){
print "$ed,$e{$ed},false\n";
}