residue_entropy 900 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/perl
  2. use POSIX;
  3. my($groupn,$quant,$sink)=@ARGV;
  4. my%hash;
  5. my$count=0;
  6. my$lines=0;
  7. if(!defined($quant)){
  8. print "Usage: residue_entropy <groupsize> <quant>\n";
  9. exit(1);
  10. }
  11. $|=1;
  12. while (<STDIN>) {
  13. chop;
  14. my@nums = ();
  15. @nums = split(/,/);
  16. $lines++;
  17. my$step=$#nums/$groupn;
  18. for(my$i=0;$i<$step;$i++){
  19. my$key="";
  20. for(my$j=$i;$j<$#nums;$j+=$step){
  21. $num=$nums[$j];
  22. if($num!=0){
  23. if($num<0){
  24. $num= -POSIX::floor(log(-$num)*8.6858896/$quant+.5)-1;
  25. }else{
  26. $num= POSIX::floor(log($num)*8.6858896/$quant+.5)+1;
  27. }
  28. }else{
  29. $num=0;
  30. }
  31. $key.=":$num";
  32. }
  33. if(!defined($hash{$key})){
  34. $count++;
  35. $hash{$key}=1;
  36. }
  37. }
  38. if(($lines % 1000)==0){
  39. print "\rworking... $lines lines, found $count values so far";
  40. }
  41. }
  42. print "\r$count values total \n";
  43. print "Done.\n\n";