#!/usr/local/bin/perl

#######################
#  @rrays and %ashes  #
#######################
############ input gi_list.txt ##########

unless(@ARGV==1) {die "please provide name of the file in the command line!!\n";}

$filename=$ARGV[0];

#the file to be read contains a  list of GI numbers

open(IN, "< $filename") or die "cannot open $filename:$!";

#again, the program will exit, if it cannot open the file 
#(good against typos in the filename)

@gi=(); #initialized an array where I will store GI numbers

while(defined($line=<IN>)){

	chomp($line);
	push(@gi,$line); # push is a function that adds the $calar to the array.
	# the value of the function is the number of elements in the array
    
}
close(IN);


#how many gi numbers did I read in?
$number_gis=@gi;
print "I read in $number_gis GI numbers\n";

$number_gis=scalar(@gi);
print "I read in $number_gis GI numbers\n";

$number_gis=$#gi+1;
print "I read in $number_gis GI numbers\n";


#with list of GI numbers I could now send a request to NCBI to return me sequences
#corresponding to these GI numbers

#Now, suppose that not all GI numbers in my file are unique, i.e. the same GIs 
#occur more than once in the list. This often happens when GIs from several
#BLAST searches are combined.
#So, we want to get rid of duplicates.

%gi_hash=(); 
foreach $i (@gi){

	if(!(exists $gi_hash{$i})){
	 	$gi_hash{$i}=1; # if you use += 1 and skip the !(exist ) you have a counter 
	}
} 


#############################
#       task2: 
#HOW MANY DUPLICATES PER GI NUMBER?
##################################

#################################
#       YOUR CODE GOES HERE
#################################
 
## HINTS: to generate an array of all the keys:
#@gi_numbers=keys(%gi_hash);#or @gi_numbers=sort(keys(%gi_hash));
#foreach (@gi_numbers) {print "$_\n"};
#foreach (@gi_numbers) {print "$_ occurs $gi_hash{$_} times\n"};

################################
#       task3:
#count how many unique GI numbers are in the list, i.e. count number of elements 
#in our %gi_hash hash.
###############################

#################################
#       YOUR CODE GOES HERE
#################################






