cannam@86: #!/usr/bin/perl cannam@86: cannam@86: # quick, very dirty little script so that we can put all the cannam@86: # information for building a residue book set (except the original cannam@86: # partitioning) in one spec file. cannam@86: cannam@86: #eg: cannam@86: cannam@86: # >res0_128_128 interleaved cannam@86: # haux 44c0_s/resaux_0.vqd res0_96_128aux 0,4,2 9 cannam@86: # :1 res0_128_128_1.vqd, 4, nonseq cull, 0 +- 1 cannam@86: # :2 res0_128_128_2.vqd, 4, nonseq, 0 +- 1(.7) 2 cannam@86: # :3 res0_128_128_3.vqd, 4, nonseq, 0 +- 1(.7) 3 5 cannam@86: # :4 res0_128_128_4.vqd, 2, nonseq, 0 +- 1(.7) 3 5 8 11 cannam@86: # :5 res0_128_128_5.vqd, 1, nonseq, 0 +- 1 3 5 8 11 14 17 20 24 28 31 35 39 cannam@86: cannam@86: cannam@86: die "Could not open $ARGV[0]: $!" unless open (F,$ARGV[0]); cannam@86: cannam@86: $goflag=0; cannam@86: while($line=){ cannam@86: cannam@86: print "#### $line"; cannam@86: if($line=~m/^GO/){ cannam@86: $goflag=1; cannam@86: next; cannam@86: } cannam@86: cannam@86: if($goflag==0){ cannam@86: if($line=~m/\S+/ && !($line=~m/^\#/) ){ cannam@86: my $command=$line; cannam@86: print ">>> $command"; cannam@86: die "Couldn't shell command.\n\tcommand:$command\n" cannam@86: if syst($command); cannam@86: } cannam@86: next; cannam@86: } cannam@86: cannam@86: # >res0_128_128 cannam@86: if($line=~m/^>(\S+)\s+(\S*)/){ cannam@86: # set the output name cannam@86: $globalname=$1; cannam@86: $interleave=$2; cannam@86: next; cannam@86: } cannam@86: cannam@86: # haux 44c0_s/resaux_0.vqd res0_96_128aux 0,4,2 9 cannam@86: if($line=~m/^h(.*)/){ cannam@86: # build a huffman book (no mapping) cannam@86: my($name,$datafile,$bookname,$interval,$range)=split(' ',$1); cannam@86: cannam@86: # check the desired subdir to see if the data file exists cannam@86: if(-e $datafile){ cannam@86: my $command="cp $datafile $bookname.tmp"; cannam@86: print ">>> $command\n"; cannam@86: die "Couldn't access partition data file.\n\tcommand:$command\n" cannam@86: if syst($command); cannam@86: cannam@86: my $command="huffbuild $bookname.tmp $interval"; cannam@86: print ">>> $command\n"; cannam@86: die "Couldn't build huffbook.\n\tcommand:$command\n" cannam@86: if syst($command); cannam@86: cannam@86: my $command="rm $bookname.tmp"; cannam@86: print ">>> $command\n"; cannam@86: die "Couldn't remove temporary file.\n\tcommand:$command\n" cannam@86: if syst($command); cannam@86: }else{ cannam@86: my $command="huffbuild $bookname.tmp 0-$range"; cannam@86: print ">>> $command\n"; cannam@86: die "Couldn't build huffbook.\n\tcommand:$command\n" cannam@86: if syst($command); cannam@86: cannam@86: } cannam@86: next; cannam@86: } cannam@86: cannam@86: # :1 res0_128_128_1.vqd, 4, nonseq, 0 +- 1 cannam@86: if($line=~m/^:(.*)/){ cannam@86: my($namedata,$dim,$seqp,$vals)=split(',',$1); cannam@86: my($name,$datafile)=split(' ',$namedata); cannam@86: # build value list cannam@86: my$plusminus="+"; cannam@86: my$list; cannam@86: my$thlist; cannam@86: my$count=0; cannam@86: foreach my$val (split(' ',$vals)){ cannam@86: if($val=~/\-?\+?\d+/){ cannam@86: my$th; cannam@86: cannam@86: # got an explicit threshhint? cannam@86: if($val=~/([0-9\.]+)\(([^\)]+)/){ cannam@86: $val=$1; cannam@86: $th=$2; cannam@86: } cannam@86: cannam@86: if($plusminus=~/-/){ cannam@86: $list.="-$val "; cannam@86: if(defined($th)){ cannam@86: $thlist.="," if(defined($thlist)); cannam@86: $thlist.="-$th"; cannam@86: } cannam@86: $count++; cannam@86: } cannam@86: if($plusminus=~/\+/){ cannam@86: $list.="$val "; cannam@86: if(defined($th)){ cannam@86: $thlist.="," if(defined($thlist)); cannam@86: $thlist.="$th"; cannam@86: } cannam@86: $count++; cannam@86: } cannam@86: }else{ cannam@86: $plusminus=$val; cannam@86: } cannam@86: } cannam@86: die "Couldn't open temp file $globalname$name.vql: $!" unless cannam@86: open(G,">$globalname$name.vql"); cannam@86: print G "$count $dim 0 "; cannam@86: if($seqp=~/non/){ cannam@86: print G "0\n$list\n"; cannam@86: }else{ cannam@86: print G "1\n$list\n"; cannam@86: } cannam@86: close(G); cannam@86: cannam@86: my $command="latticebuild $globalname$name.vql > $globalname$name.vqh"; cannam@86: print ">>> $command\n"; cannam@86: die "Couldn't build latticebook.\n\tcommand:$command\n" cannam@86: if syst($command); cannam@86: cannam@86: if(-e $datafile){ cannam@86: cannam@86: if($interleave=~/non/){ cannam@86: $restune="res1tune"; cannam@86: }else{ cannam@86: $restune="res0tune"; cannam@86: } cannam@86: cannam@86: if($seqp=~/cull/){ cannam@86: my $command="$restune $globalname$name.vqh $datafile 1 > temp$$.vqh"; cannam@86: print ">>> $command\n"; cannam@86: die "Couldn't tune latticebook.\n\tcommand:$command\n" cannam@86: if syst($command); cannam@86: }else{ cannam@86: my $command="$restune $globalname$name.vqh $datafile > temp$$.vqh"; cannam@86: print ">>> $command\n"; cannam@86: die "Couldn't tune latticebook.\n\tcommand:$command\n" cannam@86: if syst($command); cannam@86: } cannam@86: cannam@86: my $command="mv temp$$.vqh $globalname$name.vqh"; cannam@86: print ">>> $command\n"; cannam@86: die "Couldn't rename latticebook.\n\tcommand:$command\n" cannam@86: if syst($command); cannam@86: cannam@86: }else{ cannam@86: print "No matching training file; leaving this codebook untrained.\n"; cannam@86: } cannam@86: cannam@86: my $command="rm $globalname$name.vql"; cannam@86: print ">>> $command\n"; cannam@86: die "Couldn't remove temp files.\n\tcommand:$command\n" cannam@86: if syst($command); cannam@86: cannam@86: next; cannam@86: } cannam@86: } cannam@86: cannam@86: $command="rm -f temp$$.vqd"; cannam@86: print ">>> $command\n"; cannam@86: die "Couldn't remove temp files.\n\tcommand:$command\n" cannam@86: if syst($command); cannam@86: cannam@86: sub syst{ cannam@86: system(@_)/256; cannam@86: }