#!/usr/local/bin/perl -w
# take .shell reports calculate average 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 (REPORT, ">shellreport.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>){


		#the individual shell files have on each line
		#file name folowwed by list of amino acids removed
		
		# calling subscript is simple pretty inneficient hack to turn string into array
		/\S+\s(.*)/;
		$_=$1;
		s/HOH//g;
		s/CA//g;
		system("./calcaverage.prl ".$_);
		open (TEMPRESULT,"tempres.txt");
		while (<TEMPRESULT>){print REPORT $_;
		#print $_;	
		}

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

close REPORT;
