|
1 | 1 | use v6;
|
2 | 2 |
|
3 | 3 | # The Computer Language Benchmarks Game
|
4 |
| -# |
| 4 | +# |
5 | 5 | # Based on the submission for Perl 5.
|
6 | 6 | # contributed by Daniel carrera
|
7 | 7 | #
|
|
11 | 11 | my $sequence = '';
|
12 | 12 | my $lines;
|
13 | 13 | while $*IN.get -> $line {
|
14 |
| - last if ($line.substr(0,6) eq '>THREE'); |
| 14 | + last if ($line.substr(0,6) eq '>THREE'); |
15 | 15 | }
|
16 | 16 | while $*IN.get -> $line {
|
17 |
| - last if ($line.substr(0,1) eq '>'); |
18 |
| - $sequence = $sequence ~ lc $line.subst(/\n/,''); |
| 17 | + last if ($line.substr(0,1) eq '>'); |
| 18 | + $sequence = $sequence ~ lc $line.subst(/\n/,''); |
19 | 19 | }
|
20 | 20 |
|
21 | 21 | # Count nucleotide sequences
|
22 | 22 | my $len = $sequence.chars;
|
23 | 23 | my (@keys,%table,$sum,$frame_size);
|
24 | 24 | for 1..2 -> $frame_size {
|
25 |
| - %table = (); |
26 |
| - update_hash($frame_size); |
| 25 | + %table = (); |
| 26 | + update_hash($frame_size); |
27 | 27 |
|
28 |
| - # Print. |
29 |
| - $sum = $len - $frame_size + 1; |
30 |
| - for %table.sort: {$^b.value <=> $^a.value||$^a.key leg $^b.key} { |
31 |
| - printf "%s %.3f\n", .key, .value*100/$sum; |
32 |
| - } |
33 |
| - print "\n"; |
| 28 | + # Print. |
| 29 | + $sum = $len - $frame_size + 1; |
| 30 | + for %table.sort: {$^b.value <=> $^a.value||$^a.key leg $^b.key} { |
| 31 | + printf "%s %.3f\n", .key, .value*100/$sum; |
| 32 | + } |
| 33 | + print "\n"; |
34 | 34 | }
|
35 | 35 |
|
36 | 36 | for <ggt ggta ggtatt ggtattttaatt ggtattttaatttatagt> -> $seq {
|
37 |
| - %table = (); |
38 |
| - update_hash($seq.chars); |
39 |
| - printf "%3d\t$seq\n", (%table{$seq} || 0); |
| 37 | + %table = (); |
| 38 | + update_hash($seq.chars); |
| 39 | + printf "%3d\t$seq\n", (%table{$seq} || 0); |
40 | 40 | }
|
41 | 41 |
|
42 | 42 | # Procedure to update a hashtable of k-nucleotide keys and count values
|
43 | 43 | # for a particular reading-frame.
|
44 | 44 | sub update_hash($frame_size) {
|
45 |
| - for 0..($len - $frame_size) -> $i { |
46 |
| - %table{$sequence.substr($i,$frame_size)}++; |
47 |
| - } |
| 45 | + for 0..($len - $frame_size) -> $i { |
| 46 | + %table{$sequence.substr($i,$frame_size)}++; |
| 47 | + } |
48 | 48 | }
|
49 | 49 |
|
50 | 50 | # vim: expandtab shiftwidth=4 ft=perl6
|
0 commit comments