#!/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:01 2013
#Version 1.0

use strict;

 my (
    $ClubListFileName,
    $filename,
    $outputFile,
    @species_split,
    $species,
    %clublist_hash,
    %species_hash,
    $key
    );
 
#read in list clublist into a hash
$ClubListFileName = "ClubList.txt";
open (INPUT, "$ClubListFileName") or die "could not open $ClubListFileName: $!";
while (<INPUT>){
    chomp;
    (@species_split) = split (/\t/);
    $clublist_hash{$species_split[1]} = $species_split[0];
}
close INPUT;

#read in ITSlist into a hash
$filename = "FungiITS_species.txt";
open (INPUT, "$filename") or die "could not open $filename: $!";
while (<INPUT>){
    chomp;
    (@species_split) = split (/\t/);
    $species_hash{$species_split[0]} = $species_split[1];
}
close INPUT;

$outputFile = ">WPMC_wanted_list.txt";
open (OUT, "$outputFile") or die "could not open $outputFile: $!";
print OUT "Species\tPercentage of walks found on\tNumber of public ITS entries\n";
#compare keys of clublist to keys of ITSlist
foreach $species (sort keys %clublist_hash){
    if ($species_hash{$species}){
        print OUT "$species\t$clublist_hash{$species}\t$species_hash{$species}\n";
    }
    else {
        print OUT "$species\t$clublist_hash{$species}\t0\n";
    }
}
close OUT;