#!/usr/bin/perl

use strict;

my $FOFN = $ARGV[0];

main();

sub main {


    open(FOFN,"$FOFN") or die("Can't open: $FOFN\n");

    #I'll set the fasta ID as the hash key, and save the report string as the value
    my %report_hash;

    #open the fofn file and read the paths to the 3 fasta files
    while (<FOFN>) {
	my $line = $_;
	chomp($line);

	open(FILE,$line) or die("Can't open: $line\n");
	
	#initialize counters for each base to zero
	my $a_count = 0;
	my $c_count = 0;
	my $g_count = 0;
	my $t_count = 0;
	my $fasta_id;

	#loop thourhg the files in the FOFN
	while (<FILE>) {
	    my $line2 = $_;
	    chomp($line2);
	    
	    my $first_char = substr($line2,0,1);

	    #get the id line, otherwise the lines are sequence lines!
	    if ($first_char eq ">") {
		$fasta_id = substr($line2,1);
	    } else {
		my @seq_array = split(//,$line2);

		foreach my $base (@seq_array) {
		    if ($base eq "A" or $base eq "a" ) {
			++$a_count;
		    } elsif ($base eq "G" or $base eq "g") {
			++$g_count;
		    }elsif ($base eq "C"or $base eq "c") {
			++$c_count;
		    }elsif ($base eq "T"or $base eq "t") {
			++$t_count;
		    } else {
			die("This is an unrecognized base! $base\n");
		    }
		}
	    }
	}
	$report_hash{$fasta_id} = "$a_count,$c_count,$t_count,$g_count";

	close(FILE);
    }
    close(FOFN);

    print "\nFasta file report:\n";
    foreach my $key (keys(%report_hash)) {
	print "\t$key ... $report_hash{$key}\n";
    }
    print "\n\n";

}

