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