#!/usr/local/bin/perl5.6.1 -w

use Bio::SeqIO;
use Bio::SeqFeatureI;

use strict;


#=========================================================
#This file prints out a tab delimited summary of the annnotation
#fractional position is a number between 0 and 1 which is start divided by length of
#chromosome and so gives an idea of the the location on the chromosome

#=============================================================

my $input_seqs = Bio::SeqIO->new ( '-format' => 'embl',
                                '-file'   =>"$ARGV[0]");
my $systematic;	
my $colour;
my $prevsystematic;
my $i;
my @sys_ids;
my $product;
my $sys_id;			
my %seen;
my $seq;
my $fractionpos;
#===============================
#print "Systematic_id [2]\tPrevious_systematic_id [3]\tGO_ID[5]\tDB_Xref[6]\tEvidence[7]\twith[8]\tP/F/C[9]\tProduct\tDateYYYYMMDD\n\n";
#print "Search by systematic_id\n";
#
#$confirm="";
#until ($confirm eq "y")
#
#{
#print "Enter systematic_id\n";
#$searchsys = <STDIN>;
#chomp $searchsys;
#print "Confirm [y/n]\t$searchsys\n";
#$confirm = <STDIN>;
#chomp $confirm;

#============================
while ( my $s = $input_seqs->next_seq() )
   {
    
    my $seqid=$s->display_id(); 
    my $length =$s->length();
    
   # print  $seqid,"\n";
   #print  $length,"\n";
   
   #print "Printing out tab delimited file of $ARGV[0]\n";
   print "Systematic_id ,\t,Chromosome ,\t, Start,\t,End ,\t,FP ,\tColour ,\t, product \n";
   #print "==========================================================\n"; 
   #open (FH,">$ARGV[0].annotation.tab");
   
   print "Systematic_id ,\t,Chromosome ,\t, Start,\t,End ,\t,FP ,\tColour ,\t, product \n";
    foreach my $f ( $s->all_SeqFeatures() )
       {
       next unless ($f->primary_tag eq 'CDS');
        # print ( $f->start,"\t",$f->end,"\t");
	 
	 print  $seqid,"\t";	
	
				if ($f->has_tag('product')) {
	($product)=$f->get_tag_values('product');
	print "$product\t";
	}
		
		
		
		
		
		if ($f->has_tag('temporary_systematic_id')) {
	($systematic)=$f->get_tag_values('temporary_systematic_id');
	print "$systematic\t";
	}
	
	     
      	 
      			
			print ( $f->start,"\t",$f->end,"\n");
		
		
	#print  $seqid,"\n";	
	#print ".";
	#my $start=$f->start;
	#$fractionpos=($start/$length);
	#my $round = sprintf("%.4f",$fractionpos);
	#print $fractionpos,"\t";
	#print FH $round,"\t";
	
	#if ($f->has_tag('colour')) {
	#($colour)=$f->get_tag_values('colour');
	#print FH "$colour\t";
	#}	
	
	#if ($f->has_tag('product')) {
	#($product)=$f->get_tag_values('product');
	#print FH "$product\n";
	#}
	
	}
	
	#close FH;
	}
	
	
	#=====================================================
