#ParseCompare.pm #===============================================================# # Jenny Draper (learithe@cats.ucsc.edu) 6/65/02 # Parses a .compare file, and returns a hash of probailities # # USEAGE: perl parse_compare.pl compareFileName # INPUT: # ....4 lines of some stuff # E H L total # stride-mixed.alpha---------------------- # A 72963 572 40776 114311 # B 50309 5501 100326 156136 # C 15273 1783 57674 74730 # # OUPUT: # $alphatype = "alpha" # %output_hash = # "A" -> [0.638285029437237, 0.00500389288869838, 0.356711077674065] # "B" -> [0.32221268637598, 0.035232105344059, 0.642555208279961] # "C" -> [0.204375752709755, 0.0238592265489094, 0.771765020741335] # #===============================================================# package ParseCompare; require Exporter; @ISA = qw(Exporter); @EXPORT = qw( ParseCompareFile ); sub ParseCompareFile( $ ) { my $compFile = $_[0]; %output_hash = (); my $alphaType = ""; my $mutualInfo = ""; my $goToEnd = 0; my @temp_ar = (); @temp2_ar = (); @splitCurrLine = (); my $key = ""; #open the .compare file open (COMPARE_FILE, $compFile) or die "ERROR: couldn't open $compFile\n\n"; #get alphabet type @temp_ar = split(/\./, $compFile); @temp2_ar = split(/-/, $temp_ar[1]); $alphaType = $temp2_ar[0]; #get hash of probabilities while() { $currLine = $_; if(($. < 7)) #skip the first 6 lines ($. counts input line#s) { next; } @splitCurrLine = split(/\s+/, $currLine); if( !(defined($splitCurrLine[1])) ) #skip blank lines { next; }else { if($splitCurrLine[1] eq "total") { $goToEnd = 1; next; }elsif( ($goToEnd) and ($splitCurrLine[0] eq "Mutual")) { $mutualInfo = $splitCurrLine[3]; next; }elsif($goToEnd) #skip all lines but the last line { next; } } $output_hash{$splitCurrLine[1]} = [ ($splitCurrLine[2]/$splitCurrLine[5]), #E-probability ($splitCurrLine[3]/$splitCurrLine[5]), #H-probability ($splitCurrLine[4]/$splitCurrLine[5])]; #L-probability } #code for debugging #foreach $key (keys %output_hash ) #{ print $key, " ", @{$output_hash{$key}}, "\n"; #} #print "\n"; close (COMPARE_FILE); return($alphaType, $mutualInfo, \%output_hash); }