#!/usr/bin/perl -w
##############################################################################
#
# Author:Jack Min, 
# Name: GO2slim.pl  to convert a file one one line have multiple GO terms into each line contains only one GO term
############################################# Body of the code ################################

if ($#ARGV != 1)
{
	print "Usage: GO2slim.pl input output\n\n";
	exit;
}

print "In progress ...\n";

$fin = $ARGV[0];
$fout= $ARGV[1];
open (IN, $fin);
while (<IN>)
{
	$line = $_;
	chomp ($line);
	if ($line =~ /GO/ )
	{
		$id = ''; $go = '';
		@tmp = split (/\t/, $line);
		$id = $tmp[0];
		$go = $tmp[1];  
		@tmp1 = split(/\s+/, $go);
		foreach $goId (@tmp1)
		{
			$goId =~ s/\s//g;
			$goId =~ s/\;//;
			push (@outA, $id."\t".$goId."\n");
		}
	}	
}
close (IN);
 
open (OUT, ">$fout");
print OUT (@outA);
close OUT;

print "The job is done!!\n\n";
exit;

