Debian Codegraph @

hmmer/test-speed/speedA-list.pl

raw
1 #! /usr/bin/perl
2
3 # Usage: ./speedA-list.pl <Pfam.hmm.stats>
4 # Example: hmmstat Pfam-A.hmm | ./speedA-list.pl
5 #
6
7 # Read all the models and their lengths from hmmstat output
8 while (<>)
9 {
10 if (/^\d+\s+(\S+)\s+\S+\s+\d+\s+\S+\s+(\d+)/) { $lengths{$1} = $2; }
11 }
12
13 # sort
14 sub bylength { $lengths{$a} <=> $lengths{$b}; }
15 @sortedlist = sort bylength keys(%lengths);
16 $nmodels = $#sortedlist + 1;
17
18 # Construct the "ideal" set of 100 lengths,
19 # evenly spaced in log space
20 $nsteps = 100;
21 $min = $lengths{$sortedlist[0]};
22 $max = $lengths{$sortedlist[$#sortedlist]};
23 $logrange = log($max-$min+1);
24 $logstep = $logrange / ($nsteps - 1);
25 for ($step = 0; $step < $nsteps; $step++)
26 {
27 $targL[$step] = $min - 1 + exp($step * $logstep);
28 }
29
30 $step = 0;
31 $L = $min; # $L is the length we want to find
32 for ($i = 0; $i < $nmodels; $i++)
33 {
34 $diff = abs($L - $lengths{$sortedlist[$i]}); # $lengths{sortedlist[$i]} is the length of next model
35
36
37 if ($diff == $curr_diff) # as good as previous. add to equiv list
38 {
39 # printf("adding seq %d (%s) as equiv (length %d)\n", $i, $sortedlist[$i], $lengths{$sortedlist[$i]});
40 push(@equiv, $sortedlist[$i]);
41 }
42 elsif ($diff < $curr_diff) # better than previous. clear & reinit
43 {
44 @equiv = ();
45 $curr_model = $sortedlist[$i];
46 $curr_len = $lengths{$curr_model};
47 $curr_diff = $diff;
48 push(@equiv, $curr_model);
49 }
50 elsif ($diff > $curr_diff) # worse than previous. last was best
51 {
52 $choice = int(rand($#equiv+1));
53 printf("%6d %-20s\n", $lengths{$equiv[$choice]}, $equiv[$choice]);
54
55 @equiv = ();
56 $curr_model = $sortedlist[$i];
57 $curr_len = $lengths{$curr_model};
58 $curr_diff = abs($L - $curr_len);
59 push(@equiv, $curr_model);
60
61 # what's the next length we're aiming for?
62 do {
63 $step++;
64 # printf "step %d, checking: %d against %d\n", $step, int($targL[$step] + 0.5), $L;
65 } while ( int($targL[$step] + 0.5) <= $L );
66 $L = int($targL[$step] + 0.5);
67
68 while ($L < $curr_len) {
69 $step++;
70 $L = int($targL[$step] + 0.5);
71 }
72 # printf("next: looking for model near length %d\n", $L);
73
74
75
76
77 # printf("considering seq %d (%s) (length %d)\n", $i, $sortedlist[$i], $lengths{$sortedlist[$i]});
78 @equiv = ();
79 $curr_model = $sortedlist[$i];
80 $curr_len = $lengths{$curr_model};
81 $curr_diff = abs($L - $curr_len);
82 push(@equiv, $curr_model);
83
84
85 # printf("on to step $step: $L ($targL[$step])\n");
86 }
87 }
88 $choice = int(rand($#equiv+1));
89 printf("%6d %-20s\n", $lengths{$equiv[$choice]}, $equiv[$choice]);
90