Guest User

Untitled

a guest
Jun 8th, 2015
214
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2.  
  3. my $align = 0;
  4. my $window_size = 3;
  5. my $step_size = 1;
  6. my @window;
  7. my %histogram;
  8. use Data::Dumper;
  9.  
  10. my $first_window = 1;
  11. while(<>){
  12. chomp;
  13. push @window, $_;
  14.  
  15. if (scalar @window == $window_size && $first_window){
  16. my $win_tag = join("", @window);
  17. $histogram{$win_tag}++;
  18.  
  19. # print $win_tag . "\n";
  20. # print " "x ($align) . $win_tag . "\n";
  21. # $align = $align + $step_size;
  22. }
  23. elsif (scalar @window == ($window_size + $step_size)){
  24. for (my $i = 0; $i < $step_size; $i++){
  25. shift @window;
  26. }
  27. my $win_tag = join("", @window);
  28. $histogram{$win_tag}++;
  29. $first_window=0;
  30.  
  31. # print $win_tag . "\n";
  32. # print " "x ($align) . $win_tag . "\n";
  33. # $align = $align + $step_size;
  34. }
  35. }
  36.  
  37. &print_histogram(\%histogram);
  38.  
  39. sub print_histogram {
  40. my %histogram = %{$_[0]};
  41. foreach my $key (sort sort_binary_numbers keys %histogram){
  42. print $key . ": " . $histogram{$key} . "\n";
  43. }
  44. }
  45.  
  46.  
  47. sub sort_binary_numbers {
  48. my $a_dec = oct("0b".$a);
  49. my $b_dec = oct("0b".$b);
  50. return $a_dec <=> $b_dec;
  51. }
RAW Paste Data