-
Notifications
You must be signed in to change notification settings - Fork 0
/
toPajekCmt.perl
62 lines (60 loc) · 1.04 KB
/
toPajekCmt.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
58
59
60
61
62
use strict;
use warnings;
my %rank;
open A, "zcat P2AFullS.nA2Aw.2000.crank.map|";
while (<A>){
chop();
my ($f, $t)=split(/;/, $_);
$rank{$f}=$t;
};
open A, "zcat P2AFullS.nA2A.2000.names|";
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);
$i=0;
open A, "P2AFullS.nA2A.2000.csv";
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;
my %no2i;
print "*Vertices ".($#ns+1)."\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 "$i ".'"'."$no:$cnn".'"'." ".$n{$no}."\n";
$no2i{$no}=$i;
$i++;
}
print "*Edges\n";
for my $ed (keys %e){
my ($f, $t) = split (/,/,$ed,-1);
print "$no2i{$f} $no2i{$t} $e{$ed}\n";
}