#!/usr/bin/perl -w

our $READFILE = shift;
$READFILE ||= "At_intron_20060221";
my $frag = $READFILE;
$frag =~ s/\..*$//;
our $WRITEFILE = "${frag}_count.txt";
use strict;
open(RF, $READFILE) or die("Can't open file I need: $READFILE");
open(WF, ">$WRITEFILE") or die("Can't open write-file: $WRITEFILE");
$| = 1;

my %agi2count;
print "\nReading $READFILE and building hash";

while(<RF>){
	if(/^>/){
		my ($agi) = /^>(AT[1-5MC]G\d{5}\.\d+)/i;
		$agi = uc($agi);
		$agi2count{$agi}++;
	}
}

print "\nWriting Hash to Out File";

while (my ($key, $value) = each %agi2count){
	print WF "$key\t$value\n";
}

print "\nFinished.\n";

