#!usr/bin/perl -w
#	
#	By Jennifer Deegan, May 2008.
#
# This script processes an obo file and prints to another file only those
# terms that include a relationship to a taxon term in the taxonomy slim. 
#	
# 

use strict;
my $line;
 my @GO_Term_array = ();  
 my @Union_term_array = ();  
 my $array;

open (FILE, "all_files_mid_edit.obo") || die "Can't open all_files_mid_edit.obo.\n";
open (GO_TERM_OUTPUT, ">TaxonLinkedTerms.obo") || die "Can't open TaxonLinksFile.obo.\n";
open (UNION_TERM_OUTPUT, ">UnionTerms.obo") || die "Can't open UnionTerms.obo.\n";


$/ = "\n\n";
    while(<FILE>){
                $line = $_;
    	        if ($line =~m/relationship: only_in_taxon.*/) {
    	        push(@GO_Term_array, $line);
	            }
    	        if ($line =~m/relationship: never_in_taxon.*/) {
    	        push(@GO_Term_array, $line);
	            }
	            if ($line =~m/id: JD.*/){
    	        push(@Union_term_array, $line);
	            }
}

print GO_TERM_OUTPUT @GO_Term_array;
print UNION_TERM_OUTPUT @Union_term_array;
close FILE;
close GO_TERM_OUTPUT;
close UNION_TERM_OUTPUT;


