# Compute emission probability matrix given a input file containing KNOWN homogeneous state sequences

$file=shift;
open in,$file;

my $obspairscount=0;
my $sequences=0;
my %obspairs=();
my %beginpair=();

while(<in>){
chop $_;
@obs=split(//,$_);
$beginpair{"B".$obs[0]}++;
$sequences ++;
 for($i=1;$i<=$#obs;$i++){
		$obspairs{$obs[$i-1].$obs[$i]}++;
		$obspairscount++;
 }
}
close in;

print "Num. seen sequences:\t$sequences\n";
print "Num. observed pairs:\t$obspairscount\n\n";
foreach $k (sort(keys(%obspairs))){
	print "$k\t".($obspairs{$k}/$obspairscount)."\t$obspairs{$k}\n";
}
print "BS\t".($beginpair{"BS"}/$sequences)."\t$beginpair{\"BS\"}\n";
print "BT\t".($beginpair{"BT"}/$sequences)."\t$beginpair{\"BT\"}\n";