#!/usr/bin/perl -w
#Copyright Western Pennsylvania Mushroom Club
#Richard Jacob
#Wed Aug 28 00:09:31 2013
#Edited by RJJ Wed Aug 28 15:04:29 2013
#Version 1.0

use strict;
 
 my (
     $filename,
     $out,
     @species_split,
     $species,
     %species_hash,
     $key
     );
 
$filename = "Fungi ITS sequences 20130828.gb";
open (INPUT, "$filename") or die "could not open $filename: $!";

#input line 
#  ORGANISM  uncultured Thelephoraceae
while (<INPUT>){
    if (/ORGANISM/){
        (@species_split) = split (/ORGANISM  /);
        $species = $species_split[1];
        chomp ($species);
        # print the species   
        #print "$species\n";
        if ($species_hash{$species}){
            $species_hash{$species} ++;
        }
        else {
            $species_hash{$species} = 1;        
        }
        next;
    } 

}
close INPUT;

$out = "FungiITS_species.txt";
open (OUTPUT, ">$out") or die "could not open $out: $!";

foreach $key (sort keys %species_hash) {
    print OUTPUT "$key\t$species_hash{$key}\n";
}
close OUTPUT;

