#!/usr/bin/perl
#SCRIPT: Put facta dictionary files into the OntoGene ID<tab>TERM
#
use strict;

my $DEBUG=0;
if ($DEBUG){ print @ARGV ."\n"; }

#MAIN
my $CHEBI = "ChEBI";

if (! scalar @ARGV){
	print 'USAGE ([satre@furu ~/public_html/dictionary]$):'."\n\t";
	print 'perl chebi2dict.pl names_3star.tsv.sorted  > ../facta/molecules.dic'."\n\n";
}else{
	print "#Generated by chebi2dict.pl: ";
	print `date`;
	
	my $file = shift @ARGV;
	chomp $file;
	my $filename = $file;
	$file =~ s/(.*).dic/$1/;
	print "\n#Filename: $filename\n";
	open (FILE, "$filename");
	my $header = <FILE>;
	#open (OUTFILE, ">$file.onto");
	foreach my $line (<FILE>){
		chomp $line;
		my ($id, $molId, $type, $src, $term, $adpt, $lang) = split (/\t/, $line);
		$src =~ s/ /_/g;
		print "$CHEBI:$molId\t$term\t$src\n";
		#print OUTFILE "$molId\t$term\tmolecule:$src\n";
	}#foreach line
	close (FILE);
	#close (OUTFILE);
}#if filename is given


#END MAIN

