#!/usr/bin/perl -w
use strict;

#script written by Mykhaylo Berynskyy on Feb 19 2009
#reads in the PIPSA log file and a file with kinetic parameters for the proteins in the sims*.log file
#start:
#	perl createPlot.pl sims.log kineticData.txt
#kineticData.txt must have following format:
#Value\tName_Of_Protein_Without_addH
#for example:
#
#1.120	TPIS_TRYBB
#1.000	TPIS_TRYCR
#0.721	TPIS_RABIT
#0.915	TPIS_CHICK
#1.080	TPIS_YEAST
#1.020	TPIS_LEIME
#1.280	TPIS_PLAFA
#0.368	TPIS_VIBMA
#0.874	TPIS_ECOLI
#0.918	TPIS_HUMAN
#0.912	TPI1_GIALA
#0.662	TPIC_SPIOL
#

if($#ARGV < 1){
	print "\nscript reads in the PIPSA log file and a file with kinetic parameters for the proteins in the sims*.log file
	start:
		perl createPlot.pl sims.log kineticData.txt
		kineticData.txt must have following format:
		Value\tName_Of_Protein_Without_addH
		
		see comment in the code for further information
		\n";
	exit;
}

my $file2 = $ARGV[1];

open(FH2,"<$file2") || die("$file2 not found\n");
my %hash;
while(<FH2>){
	my $line2 = $_;
	my @temp2 = split("\t",$line2);
	if($#temp2 >= 1){
#		print $temp2[1]."\n";
		chomp($temp2[0]);
		chomp($temp2[1]);
		$temp2[0] =~ s/ //g;
		$temp2[1] =~ s/ //g;
#		print $temp2[0]."\n";	
		$hash{$temp2[1]}=$temp2[0];
	}
}
close(FH2);
my $file = $ARGV[0];
my @temp;
open(FH,"<$file") || die("$file not found\n");
while(<FH>){
	my $line = $_;
	if($line =~ /addH/){
		@temp = split(" ",$line);
		$temp[0] =~ s/^addH//g;
		$temp[0] =~ s/ //g;
		$temp[1] =~ s/^addH//g;
		$temp[1] =~ s/ //g;
	}else{
		if($#temp >= 1){
			my @arr = split("",$line);
			my $val="";
#			print $temp[0]."---$line--".$temp[1];
			for(my $i=125;$i <= 139;$i++){
				$val=$val.$arr[$i]
			}
			my $diff = log($hash{$temp[0]}) - log($hash{$temp[1]});
			print $val."\t".$diff."\n";
			$val = $val * -1;
			$diff = $diff * -1;
			print $val."\t".$diff."\n";
		}
	}

}
close(FH);
