#!/usr/local/bin/perl # al_to_brk.p # reads in a file full of alphas. # reads in HBB_H # reads in .brk file for same protein # # deletes the alphas that are "." in HBB_H # otherwise writes the alphas onto the temperature column of a new .brk file. # does this for all rows of the alpha file, writing .brk files labelled by # row $ntail = 1 ; # number of alphas at end of line that do not map onto residues $hfile ="/home/mackay/BRK/HBB_H"; # the aligned protein string $afile =_a; # the alpha file $bfile ="/home/mackay/BRK/1dxtb.brk"; # brk protein read from here $bofile =_b; # .brk files are written to bofile-1.brk - bofile-h.brk $cofile =_c; # list of commands for rasmol is written to here $hmax =20; # number of rows of alphas $s =209; # number of alphas per row $afunc = 0 ; # how to turn alpha in to "temperature" $addbrk = 0 ; # whether to append .brk on all .brk files $numadiff = 2 ; # number of alphas that must be different from the first # for us to bother printing out. eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; $s-- ; %throne = ('ALA','A','MET','M','LEU','L','GLU','E','LYS','K', 'PHE','F','SER','S','ARG','R','ILE','I','ASP','D', 'CYS','C','VAL','V','GLN','Q','ASN','N','GLY','G', 'TYR','Y','PRO','P','THR','T','HIS','H','TRP','W',); open(H,"< $hfile") ; open (G,"< $afile") ; $_ = ; @hbb = split (' ',$_) ; $c = $hbb[1] ; print STDERR $c, "\n" ; open(COMMANDS,">$cofile"); $h=0; printf STDERR "Note: For each row `h', if a message `different alpha number' is printed,\nthat is a good thing, not an error.\n"; # while (($_ = ) && ( $h<$hmax)) { # read in a row of alphas @fields = split(' ',$_); if ( $#fields < $s ) { print STDERR "warning, too few fields " , $#fields , " " , $s , "\n" ; } else { $h++; # OK, $fields[$i] for $i from 0 to $s-1 contains all the alphas # check that some alphas are different: for ( $i = 0 , $done= 0 , $firstalpha = 0 ; $done < $numadiff ; $i++ ) { while ( ($seq=substr($c,$i,1)) eq "." ) { $i ++ ; } if ( $firstalpha == 0 ) { $firstalpha = $fields[$i] ; } elsif ( $i > $s - 1 ) { $done = 300 ; } elsif ( $fields[$i] ne $firstalpha ) { $done++ ; } } if ( $done == 300 ) { # there are no different alphas ! printf STDERR " All or nearly all alphas same in %d\n", $h ; } else { printf STDERR "%d : different alpha number %d at i = %d\n",$h,$done,$i; # $rc=0; # rc points to character in HBB_HUMAN string, and to alphas. $rn='init'; open(IN,"$bfile"); if ( $addbrk ) { $this_bofile = "$bofile-$h.brk"; } else { $this_bofile = "$bofile-$h"; } open(OUT,">$this_bofile"); print COMMANDS "zap\n" ; print COMMANDS "load $this_bofile\n" ; print COMMANDS "script brk/S\n" ; $nhit=0; while(){ if(/(ATOM +\d+ +\w+ +\w+ +.{6} +[\d.-]+ +[\d.-]+ +[\d.-]+ +.{4})/){ $line=$1; $line =~ /ATOM +\d+ +\w+ +(\w+) +(.{6})/; if($2 ne $rn){ $rn=$2; $char=$throne{$1}; while ( ($seq=substr($c,$rc,1)) eq "." ) { $rc ++ ; } if($char ne $seq){ print "ERROR: $rc,$char,$seq\n"; exit 0; } $x= &alpha_to_temp($fields[$rc], $afunc); $rc++; } printf OUT "%s %6.2f\n",$line,$x; }else{ print OUT; } } } printf IND "%5d %4d %6d\n",$n,$i,$nhit; close(OUT); close(IN); } } close(COMMANDS); sub alpha_to_temp { # usage ( $alpha , $afunc ) local ( $al , $afunc ) = @_ ; local ( $ans ) = ( $afunc == 1 ) ? $al : ($afunc == 0 ) ? log ( $al ) : ($afunc == 2 ) ? log ( 1000.0 ) - log ( $al ) : ( $afunc == 3 ) ? 1000.0 - $al : $al ; return $ans ; }