The Q6600
Benchmarks Game

k-nucleotide Perl #4 program

source code

# The Computer Language Benchmarks Game
#  https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
#
#  contributed by Mykola Zubach

use strict;
use integer;
use threads;

my($sequence, $seq_len, $thr, @threads, %h);

sub count_frame {
   my $len = shift;
   for (0 .. $seq_len - $len) {
      $h{substr($sequence, $_, $len)} ++;
   }
}

sub count_len {
   my $len = shift;
   my $out;
   count_frame($len);

   no integer;
   if(@_) {
      $out = join '', map sprintf("%d\t%s\n", $h{$_}, $_), @_;
   } else {
      my $sum = $seq_len - $len + 1;
      for (sort { $h{$b} <=> $h{$a} || $a cmp $b } keys %h) {
         $out .= sprintf "%s %.3f\n", $_, $h{$_} * 100 / $sum;
      }
      $out .= "\n";
   }
   return $out;
}

## MAIN()

while(<STDIN>) {
   last if /^>THREE /;
}
while(<STDIN>) {
   last if /^>/;
   chomp;
   $sequence .= uc;
}
$seq_len = length($sequence);

for (1,2) {
   push @threads, threads->create(\&count_len, $_);
}

for (qw(GGT GGTA GGTATT GGTATTTTAATT GGTATTTTAATTTATAGT)) {
   push @threads, threads->create(\&count_len, length, $_);
}

foreach $thr (@threads) {
   print $thr->join();
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
This is perl 5, version 30, subversion 0 (v5.30.0)
built for x86_64-linux-thread-multi


Sun, 10 May 2020 19:26:19 GMT

COMMAND LINE:
/opt/src/perl-5.30.0/bin/perl knucleotide.perl-4.perl 0 < knucleotide-input25000000.txt

PROGRAM OUTPUT:
A 30.295
T 30.151
C 19.800
G 19.754

AA 9.177
TA 9.132
AT 9.131
TT 9.091
CA 6.002
AC 6.001
AG 5.987
GA 5.984
CT 5.971
TC 5.971
GT 5.957
TG 5.956
CC 3.917
GC 3.911
CG 3.909
GG 3.902

1471758	GGT
446535	GGTA
47336	GGTATT
893	GGTATTTTAATT
893	GGTATTTTAATTTATAGT