-
Notifications
You must be signed in to change notification settings - Fork 129
/
clstr_sort_prot_by.pl
executable file
·59 lines (53 loc) · 1.26 KB
/
clstr_sort_prot_by.pl
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
#!/usr/bin/env perl
my $sort_by = shift;
$sort_by = "len" unless ($sort_by);
my @clstr = ();
my $readin = 0;
my $head = "";
while($ll=<>) {
if ($ll =~ /^>/) {
if ($readin) {
print $head;
if ($sort_by eq "len") {
@clstr = sort { $b->[1]<=>$a->[1] } @clstr;
}
elsif ($sort_by eq "id") {
@clstr = sort {$a->[2] cmp $b->[2] or $b->[1]<=>$a->[1]} @clstr;
}
else {
@clstr = sort {$b->[1]<=>$a->[1] or $a->[2] cmp $b->[2]} @clstr;
}
for ($i=0; $i<@clstr; $i++) {
print "$i\t$clstr[$i]->[0]\n";
}
}
@clstr = ();
$head = $ll;
}
else {
$readin=1;
chop($ll);
if ($ll =~ /(\d+)(aa|nt), >(.+)\.\.\./) {
$len = $1;
$id = $3;
$len = 99999999 if ($ll =~ /\*/);
$ll =~ s/^\d+\t//;
push(@clstr, [$ll, $len, $id]);
}
}
}
if ($readin) {
print $head;
if ($sort_by eq "len") {
@clstr = sort { $b->[1]<=>$a->[1] } @clstr;
}
elsif ($sort_by eq "id") {
@clstr = sort {$a->[2] cmp $b->[2] or $b->[1]<=>$a->[1]} @clstr;
}
else {
@clstr = sort {$b->[1]<=>$a->[1] or $a->[2] cmp $b->[2]} @clstr;
}
for ($i=0; $i<@clstr; $i++) {
print "$i\t$clstr[$i]->[0]\n";
}
}