#!usr/bin/perl -w
#	
#	By Jennifer Deegan, July 2008.
#
#   Converts file of format:
#
#   [Term]
#   id: GO:0001744
#   name: optic lobe placode formation
#   relationship: only_in_taxon NCBITaxon:33392 ! Endopterygota
#
#    [Term]
#
#   to tab-delimited
#
#   GO:0001744    optic lobe placode formation    only_in_taxon   NCBITaxon:33392   Endopterygota
 
 

use strict;
my $line;
my $GOTerm; 
my $GOid;
my $SpeciesID; 
my $SpeciesName; 
my $Rel;

 
$/ = "[Term]";

open (FILE, "TaxonGOLinksFile.obo") || die "Can’t open TaxonGOLinksFile.obo.\n";
open (OUTPUT, ">TaxonGOLinksTabDelimited.txt") || die "Can’t open TaxonGOLinksTabDelimited.txt.\n";

while (my $line=<FILE>){
        
        if ( $line =~ m/(GO:.*)/) {
             $GOid = $1;
             print OUTPUT $GOid;
             print OUTPUT "\t";
             }
        
        if ($line =~ m/name: (.*)/) {
            $GOTerm = $1;
            print OUTPUT $GOTerm;
            print OUTPUT "\t";
            }
            
         if ($line =~ m/relationship: (.*) NCBI/) {
            $Rel = $1;
            print OUTPUT $Rel;
            print OUTPUT "\t";
            }

         if ($line =~ m/relationship: (.*) JD/) {
            $Rel = $1;
            print OUTPUT $Rel;
            print OUTPUT "\t";
            }

         if ($line =~ m/ ! (.*)/) {
            $SpeciesID = $1;
            print OUTPUT $SpeciesID;
            print OUTPUT "\t";
            }

         if ($line =~ m/taxon (NCBITaxon:.*) ! /) {
            $SpeciesName = $1;
            print OUTPUT $SpeciesName;
            print OUTPUT "\t";
            }

         if ($line =~ m/taxon (JD:.*) ! /) {
            $SpeciesName = $1;
            print OUTPUT $SpeciesName;
            }
 

 
 print OUTPUT "\n";
 }



close FILE;
close OUTPUT;


