make_residue_books.pl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 temp$$.vql: $!" unless
  101. open(G,">temp$$.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 temp$$.vql > $globalname$name.vqh";
  110. print ">>> $command\n";
  111. die "Couldn't build latticebook.\n\tcommand:$command\n"
  112. if syst($command);
  113. my $command="latticehint $globalname$name.vqh $thlist > temp$$.vqh";
  114. print ">>> $command\n";
  115. die "Couldn't pre-hint latticebook.\n\tcommand:$command\n"
  116. if syst($command);
  117. if(-e $datafile){
  118. if($interleave=~/non/){
  119. $restune="res1tune";
  120. }else{
  121. $restune="res0tune";
  122. }
  123. if($seqp=~/cull/){
  124. my $command="$restune temp$$.vqh $datafile 1 > $globalname$name.vqh";
  125. print ">>> $command\n";
  126. die "Couldn't tune latticebook.\n\tcommand:$command\n"
  127. if syst($command);
  128. }else{
  129. my $command="$restune temp$$.vqh $datafile > $globalname$name.vqh";
  130. print ">>> $command\n";
  131. die "Couldn't tune latticebook.\n\tcommand:$command\n"
  132. if syst($command);
  133. }
  134. my $command="latticehint $globalname$name.vqh $thlist > temp$$.vqh";
  135. print ">>> $command\n";
  136. die "Couldn't post-hint latticebook.\n\tcommand:$command\n"
  137. if syst($command);
  138. }else{
  139. print "No matching training file; leaving this codebook untrained.\n";
  140. }
  141. my $command="mv temp$$.vqh $globalname$name.vqh";
  142. print ">>> $command\n";
  143. die "Couldn't rename latticebook.\n\tcommand:$command\n"
  144. if syst($command);
  145. my $command="rm temp$$.vql";
  146. print ">>> $command\n";
  147. die "Couldn't remove temp files.\n\tcommand:$command\n"
  148. if syst($command);
  149. next;
  150. }
  151. }
  152. $command="rm -f temp$$.vqd";
  153. print ">>> $command\n";
  154. die "Couldn't remove temp files.\n\tcommand:$command\n"
  155. if syst($command);
  156. sub syst{
  157. system(@_)/256;
  158. }