#!/usr/local/bin/perl -w
# take .shell reports calculate p hydrophobicity for each shell 
# for each pdb file and put in shellreport.txt
# known bug: there is a extra zero entry at front of each line bc shells
#files currently have hard return at top for no good reason. 

#open (HYDRO, "scale.txt")||die "couldnt open scale";
#while (<HYDRO>){
#	
#	/(.*)\s+(-?\d+\.\d+).*/;
#	print "stored ".$1." with ".$2."\n";
#	$phobicityhash{$1}=$2;
#}

#close HYDRO;

open (REPORT, ">shellpercentreport.txt")||die "could not create report file";

@files=qw(`ls *.shells`);

#compute average for each shell in each file
while (<@files>){
	
	print $_ ."\n";
	(/(.*)\.shells/);
	#print name of this pdb file

	print REPORT $1."\t";

	open (RESULT, $_);

	while(<RESULT>){

	#    print "initial string is ".$_."\n";
		#the individual shell files have on each line
		#file name folowwed by list of amino acids removed
		
	#        /\S+\s(.*)/;
	#	$_=$1;
	
#	s/HOH//g;
	#	s/CA//g;
	#	print "after culling string is ".$_."\n";
	#	@aminoacids=split(/\s/,$_);
	#	$phobic=0;
	#	$phylic=0;
	#	$currentacid=0;
	#	while (<@aminoacids>){
	#	    print "individual value is ".$_."\n";
	#	    $currentacid=$phobicityhash{$_};
	#	    if($currentacid!=undef){
	#		if ($currentacid>.1) {$phobic++;}
	#		if ($currentacid<-.51){$phylic++;}
	#	    } 
			
	#	} #whileone acids on one line
	#	if ($phylic+$phobic!=0){
	#	    print REPORT $phobic/($phylic+$phobic)."\t";
	#	}
	#	else {
	#	    print REPORT "-1"."\t";
	#	}

		system("./calcpercent.prl ".$_);
		open (TEMPRESULT,"tempres.txt");
		while (<TEMPRESULT>){print REPORT $_;
		#print $_;	
		}



	} # end while lines in one file
	close RESULT;
	print REPORT "\n";
	print "\n";
} #end for each shells file

close REPORT;

