#! /usr/bin/perl -w
#
# File: augustos2emblminimal.pl
# Time-stamp: <19-Oct-2011 16:13:16 tdo>
# $Id: $
#
# Copyright (C) 2010 by Pathogene Group, Sanger Center
#
# Author: Thomas Dan Otto
#
# Description:
#


use strict;

my %cds;
my %strand;
my $name;
my @order;

while (<STDIN>) {
  chomp;
  
  my @ar=split(/\t/);
  if (!defined($ar[2])){
  }  
  elsif ($ar[2] eq "gene") {
	push @order, $ar[8];
	$strand{$ar[8]}=$ar[6];
	$name=$ar[8];
	
  }
  elsif ($ar[2] eq "CDS"
	){
	push @{$cds{$name}}, "$ar[3]..$ar[4]"
  }
}

foreach $name (@order) {
  my $positions=join(',',@{$cds{$name}});

  if (scalar (@{$cds{$name}}) >1 ) {
	$positions="join($positions)";
  }
  if ($strand{$name} eq '-') {
	$positions="complement($positions)";
  }
  print "FT   CDS             $positions\n";
  print "FT                   /locus_tag=\"$name\"\n";
  
}


