#!/usr/bin/perl

use strict;
use warnings;

# use this to get filename, without the rest of the directory structure
use File::Basename;

##########################################################################
#   po_obsolete_check.pl                                                 #
#    Version 0.1                                                         #
#                                                                        #
#  Written by Justin Elser, Dept. of BPP, OSU 2011                       #
#                                                                        #
#  Program will check the current po obo file for terms that have        #
#    been obsoleted.  It will then check all association files for       #
#    annotations linked with those terms and create output files for     #
#    used for manual intervention by annotation curators.                #
#                                                                        #
#  Program should be made part of the SOP when loading new DBs           #
#                                                                        #
##########################################################################

#  Use Chris Mungall's GO::Parser to do the searching for is_obsoletes
use GO::Parser;


my $obo_file = $ARGV[0];

# init GO parser
my $parser = GO::Parser->new({handler=>'obj'});
$parser->parse($obo_file);

my $ont = $parser->handler->graph;


my $obo_terms = $ont->get_all_nodes;

# hash to store obsolete terms
my %obs_terms_hash;
my $good_terms_count = 0;
my $bad_terms_count =0;
my $total_terms_count = 0;


foreach my $term (@$obo_terms) {
	if ($term->is_obsolete){
		my $id = $term->acc;
		my $name = $term->name;
		$obs_terms_hash{$id} = $name;
		$bad_terms_count++;
	}else{
			$good_terms_count++;
	}
	$total_terms_count++;
}

print "Good terms count = $good_terms_count\n";
print "Obsolete terms count = $bad_terms_count\n";
print "Total number of terms = $total_terms_count\n";
