make_residue_books.pl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 res0_96_128aux.vqd 0,4,2
  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 res0_96_128aux.vqd 0,4,2
  38. if($line=~m/^h(.*)/){
  39. # build a huffman book (no mapping)
  40. my($name,$datafile,$arg)=split(' ',$1);
  41. my $command="huffbuild $datafile $arg";
  42. print ">>> $command\n";
  43. die "Couldn't build huffbook.\n\tcommand:$command\n"
  44. if syst($command);
  45. next;
  46. }
  47. # :1 res0_128_128_1.vqd, 4, nonseq, 0 +- 1
  48. if($line=~m/^:(.*)/){
  49. my($namedata,$dim,$seqp,$vals)=split(',',$1);
  50. my($name,$datafile)=split(' ',$namedata);
  51. # build value list
  52. my$plusminus="+";
  53. my$list;
  54. my$thlist;
  55. my$count=0;
  56. foreach my$val (split(' ',$vals)){
  57. if($val=~/\-?\+?\d+/){
  58. my$th;
  59. # got an explicit threshhint?
  60. if($val=~/([0-9\.]+)\(([^\)]+)/){
  61. $val=$1;
  62. $th=$2;
  63. }
  64. if($plusminus=~/-/){
  65. $list.="-$val ";
  66. if(defined($th)){
  67. $thlist.="," if(defined($thlist));
  68. $thlist.="-$th";
  69. }
  70. $count++;
  71. }
  72. if($plusminus=~/\+/){
  73. $list.="$val ";
  74. if(defined($th)){
  75. $thlist.="," if(defined($thlist));
  76. $thlist.="$th";
  77. }
  78. $count++;
  79. }
  80. }else{
  81. $plusminus=$val;
  82. }
  83. }
  84. die "Couldn't open temp file temp$$.vql: $!" unless
  85. open(G,">temp$$.vql");
  86. print G "$count $dim 0 ";
  87. if($seqp=~/non/){
  88. print G "0\n$list\n";
  89. }else{
  90. print G "1\n$list\n";
  91. }
  92. close(G);
  93. my $command="latticebuild temp$$.vql > $globalname$name.vqh";
  94. print ">>> $command\n";
  95. die "Couldn't build latticebook.\n\tcommand:$command\n"
  96. if syst($command);
  97. my $command="latticehint $globalname$name.vqh $thlist > temp$$.vqh";
  98. print ">>> $command\n";
  99. die "Couldn't pre-hint latticebook.\n\tcommand:$command\n"
  100. if syst($command);
  101. if(-e $datafile){
  102. if($interleave=~/non/){
  103. $restune="res1tune";
  104. }else{
  105. $restune="res0tune";
  106. }
  107. if($seqp=~/cull/){
  108. my $command="$restune temp$$.vqh $datafile 1 > $globalname$name.vqh";
  109. print ">>> $command\n";
  110. die "Couldn't tune latticebook.\n\tcommand:$command\n"
  111. if syst($command);
  112. }else{
  113. my $command="$restune temp$$.vqh $datafile > $globalname$name.vqh";
  114. print ">>> $command\n";
  115. die "Couldn't tune latticebook.\n\tcommand:$command\n"
  116. if syst($command);
  117. }
  118. my $command="latticehint $globalname$name.vqh $thlist > temp$$.vqh";
  119. print ">>> $command\n";
  120. die "Couldn't post-hint latticebook.\n\tcommand:$command\n"
  121. if syst($command);
  122. }else{
  123. print "No matching training file; leaving this codebook untrained.\n";
  124. }
  125. my $command="mv temp$$.vqh $globalname$name.vqh";
  126. print ">>> $command\n";
  127. die "Couldn't rename latticebook.\n\tcommand:$command\n"
  128. if syst($command);
  129. my $command="rm temp$$.vql";
  130. print ">>> $command\n";
  131. die "Couldn't remove temp files.\n\tcommand:$command\n"
  132. if syst($command);
  133. next;
  134. }
  135. }
  136. $command="rm -f temp$$.vqd";
  137. print ">>> $command\n";
  138. die "Couldn't remove temp files.\n\tcommand:$command\n"
  139. if syst($command);
  140. sub syst{
  141. system(@_)/256;
  142. }