make_residue_books.pl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/usr/bin/perl
  2. # quick, very dirty little script so that we can put all the
  3. # information for building a residue book set (except the original
  4. # partitioning) in one spec file.
  5. #eg:
  6. # >res0_128_128 interleaved
  7. # haux 44c0_s/resaux_0.vqd res0_96_128aux 0,4,2 9
  8. # :1 res0_128_128_1.vqd, 4, nonseq cull, 0 +- 1
  9. # :2 res0_128_128_2.vqd, 4, nonseq, 0 +- 1(.7) 2
  10. # :3 res0_128_128_3.vqd, 4, nonseq, 0 +- 1(.7) 3 5
  11. # :4 res0_128_128_4.vqd, 2, nonseq, 0 +- 1(.7) 3 5 8 11
  12. # :5 res0_128_128_5.vqd, 1, nonseq, 0 +- 1 3 5 8 11 14 17 20 24 28 31 35 39
  13. die "Could not open $ARGV[0]: $!" unless open (F,$ARGV[0]);
  14. $goflag=0;
  15. while($line=<F>){
  16. print "#### $line";
  17. if($line=~m/^GO/){
  18. $goflag=1;
  19. next;
  20. }
  21. if($goflag==0){
  22. if($line=~m/\S+/ && !($line=~m/^\#/) ){
  23. my $command=$line;
  24. print ">>> $command";
  25. die "Couldn't shell command.\n\tcommand:$command\n"
  26. if syst($command);
  27. }
  28. next;
  29. }
  30. # >res0_128_128
  31. if($line=~m/^>(\S+)\s+(\S*)/){
  32. # set the output name
  33. $globalname=$1;
  34. $interleave=$2;
  35. next;
  36. }
  37. # haux 44c0_s/resaux_0.vqd res0_96_128aux 0,4,2 9
  38. if($line=~m/^h(.*)/){
  39. # build a huffman book (no mapping)
  40. my($name,$datafile,$bookname,$interval,$range)=split(' ',$1);
  41. # check the desired subdir to see if the data file exists
  42. if(-e $datafile){
  43. my $command="cp $datafile $bookname.tmp";
  44. print ">>> $command\n";
  45. die "Couldn't access partition data file.\n\tcommand:$command\n"
  46. if syst($command);
  47. my $command="huffbuild $bookname.tmp $interval";
  48. print ">>> $command\n";
  49. die "Couldn't build huffbook.\n\tcommand:$command\n"
  50. if syst($command);
  51. my $command="rm $bookname.tmp";
  52. print ">>> $command\n";
  53. die "Couldn't remove temporary file.\n\tcommand:$command\n"
  54. if syst($command);
  55. }else{
  56. my $command="huffbuild $bookname.tmp 0-$range";
  57. print ">>> $command\n";
  58. die "Couldn't build huffbook.\n\tcommand:$command\n"
  59. if syst($command);
  60. }
  61. next;
  62. }
  63. # :1 res0_128_128_1.vqd, 4, nonseq, 0 +- 1
  64. if($line=~m/^:(.*)/){
  65. my($namedata,$dim,$seqp,$vals)=split(',',$1);
  66. my($name,$datafile)=split(' ',$namedata);
  67. # build value list
  68. my$plusminus="+";
  69. my$list;
  70. my$thlist;
  71. my$count=0;
  72. foreach my$val (split(' ',$vals)){
  73. if($val=~/\-?\+?\d+/){
  74. my$th;
  75. # got an explicit threshhint?
  76. if($val=~/([0-9\.]+)\(([^\)]+)/){
  77. $val=$1;
  78. $th=$2;
  79. }
  80. if($plusminus=~/-/){
  81. $list.="-$val ";
  82. if(defined($th)){
  83. $thlist.="," if(defined($thlist));
  84. $thlist.="-$th";
  85. }
  86. $count++;
  87. }
  88. if($plusminus=~/\+/){
  89. $list.="$val ";
  90. if(defined($th)){
  91. $thlist.="," if(defined($thlist));
  92. $thlist.="$th";
  93. }
  94. $count++;
  95. }
  96. }else{
  97. $plusminus=$val;
  98. }
  99. }
  100. die "Couldn't open temp file $globalname$name.vql: $!" unless
  101. open(G,">$globalname$name.vql");
  102. print G "$count $dim 0 ";
  103. if($seqp=~/non/){
  104. print G "0\n$list\n";
  105. }else{
  106. print G "1\n$list\n";
  107. }
  108. close(G);
  109. my $command="latticebuild $globalname$name.vql > $globalname$name.vqh";
  110. print ">>> $command\n";
  111. die "Couldn't build latticebook.\n\tcommand:$command\n"
  112. if syst($command);
  113. if(-e $datafile){
  114. if($interleave=~/non/){
  115. $restune="res1tune";
  116. }else{
  117. $restune="res0tune";
  118. }
  119. if($seqp=~/cull/){
  120. my $command="$restune $globalname$name.vqh $datafile 1 > temp$$.vqh";
  121. print ">>> $command\n";
  122. die "Couldn't tune latticebook.\n\tcommand:$command\n"
  123. if syst($command);
  124. }else{
  125. my $command="$restune $globalname$name.vqh $datafile > temp$$.vqh";
  126. print ">>> $command\n";
  127. die "Couldn't tune latticebook.\n\tcommand:$command\n"
  128. if syst($command);
  129. }
  130. my $command="mv temp$$.vqh $globalname$name.vqh";
  131. print ">>> $command\n";
  132. die "Couldn't rename latticebook.\n\tcommand:$command\n"
  133. if syst($command);
  134. }else{
  135. print "No matching training file; leaving this codebook untrained.\n";
  136. }
  137. my $command="rm $globalname$name.vql";
  138. print ">>> $command\n";
  139. die "Couldn't remove temp files.\n\tcommand:$command\n"
  140. if syst($command);
  141. next;
  142. }
  143. }
  144. $command="rm -f temp$$.vqd";
  145. print ">>> $command\n";
  146. die "Couldn't remove temp files.\n\tcommand:$command\n"
  147. if syst($command);
  148. sub syst{
  149. system(@_)/256;
  150. }