-
Notifications
You must be signed in to change notification settings - Fork 0
/
rankNewO.perl
65 lines (61 loc) · 1.3 KB
/
rankNewO.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
63
64
65
use warnings;
use strict;
open A, "gunzip -c $ARGV[0].names|";
my (@num2f);
while(<A>){
chop();
my $n = $_;
push @num2f, $n;
}
close (A);
my $cn = "";
my %cluster = ();
my $off = 0;
my (@rank, %tr, %best);
open A, "gunzip -c $ARGV[1]|";
while(<A>){
chop();
my ($cl, $scr) = split(/;/);
push @rank, $scr;
}
my %map;
while(<STDIN>){
chop($_);
next if $_ =~ /^#/;
$_ =~ s/\s+$//;
$_ =~ s/^\s+//;
$_ =~ s/\s+/ /g;
my @n = split(/ /, $_, -1);
if (!defined $rank[$n[0]] || $rank[$n[0]] eq "" || $n[0] > $#rank){
print STDERR "$_;@n:\n";
exit();
}
my $mrank = $rank[$n[0]];
my $ctr = $n[0];
for my $i (@n){
if ($rank[$i] >= $mrank && $num2f[$i] !~ /^cl[0-9]+$/){
$mrank = $rank[$i];
$ctr = $i;
}
}
my $cln = $num2f[$ctr];
for my $i (@n){
my $cln = $num2f[$ctr];
if ($num2f[$i] !~ /^cl[0-9]+$/){
if (defined $map{$num2f[$i]}){
if ($rank[$map{$num2f[$i]}] < $mrank){
# replace with new center
$map{$num2f[$i]} = $ctr;
print "$num2f[$i];$cln\n";
}else{
# ignore new center
print "$num2f[$i];$num2f[$map{$num2f[$i]}]\n";
}
#print STDERR "$num2f[$i];$map{$num2f[$i]};$cln\n";
}else{
$map{$num2f[$i]} = $ctr;
print "$num2f[$i];$cln\n";
}
}
}
}