Advertisement
ZaynerTech

Decay Rates Perl

Jan 17th, 2013
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 1.66 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. #
  4. # For calculating decay rates
  5. # tested using Hydrogen Exchange data
  6. #
  7. # Input file format should be:
  8. # <residue #> <value 1> <value 2> ...
  9. # One value for each time in @timeses
  10. #
  11. # Obvi needs Algorithm::CurveFit Module
  12. #
  13. # This is old code no hating
  14. #
  15. # ./hxrates <input file>
  16. #
  17.  
  18. use Algorithm::CurveFit;
  19.  
  20. @timeses = (0.01,0.02,0.04,0.075,0.1,0.15,0.175,0.2,0.25 );
  21.  
  22. $x = $z =0;
  23.  
  24. open(HXCH, $ARGV[0]);
  25.  
  26. @hx = <HXCH>;
  27.  
  28. #print $timeses[0]; die;
  29. foreach $line(@hx) {
  30.  
  31.    @vols = split(/ /,$line);
  32.    $res = $vols[0];
  33.    shift(@vols);
  34.    
  35.    foreach $val(@vols) {
  36.       if($val != -10) {
  37.       $val =~ s/\n//;
  38.       $hxvols{$res}->{$x} = $val;
  39.          
  40.       #print "$hxvols{ $res }{ $x } : $hxvols{ $res }{ $x }{ times }\n";
  41.       $x++;
  42.       $z++;
  43.       }
  44.       else{
  45.       $z++;
  46.       }
  47.    }
  48.  
  49.  $x=0;
  50.  $z=0;
  51. } #foreach
  52.  
  53. foreach $key (sort keys %hxvols) {
  54. $a=0;
  55. #for($y=0; $y <= $num; $y++){
  56. foreach $y (sort keys %{ $hxvols{$key} }){
  57.  
  58. $yval[$a] = $hxvols{$key}{$y};
  59. $xval[$a] = $timeses[$y];
  60. if($yval[$a] != -1){
  61. #print "Y: $yval[$a]\n";
  62. $a++;
  63. }
  64. else{
  65. pop(@yval);
  66. pop(@xval);
  67. }
  68.  
  69.  
  70. #print "$key :: $yval[$y] :: $xval[$y]\n";
  71. }
  72.  
  73. #initialize conditions
  74. @parameters = ( ['n',1,0.00001],['k',10,0.00001] );
  75. #print "$key   @yval :: @xval\n";
  76.  
  77. #exponential with offset
  78. my $formul = 'n *(1 - exp(-k * x))';
  79. $rate = Algorithm::CurveFit->curve_fit(
  80.     formula => $formul,
  81.         params  => \@parameters,
  82.         variable =>   'x',
  83.         xdata    => \@xval,
  84.         ydata    => \@yval,
  85.         max_iterations => '10000'
  86. );
  87.  
  88. print "$key $parameters[0][1] $parameters[1][1]\n\n";
  89. }
  90.  
  91.  
  92. close(HXCH);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement