#!/usr/bin/perl

if ($ARGV[0] eq '')
{
    print "Please enter input file name (e.g., ./Module_UTR_coordinates.pl rna.asn).\n";
}
else
{
    open(LIST,$ARGV[0]);
    while(<LIST>)
    {
	chomp;
	if (/^ *seq-set \{$/)
	{
	    $read_id=1;
	}
	if ((/^ *accession /) && ($read_id))
	{
	    s/^ *accession "//;
	    s/",$//;
	    $accession=$_;
#	    print "accession=$accession\n";
	}
	if (/\}/)
	{
	    $read_id=0;
	    $read_coord=0;
	}
	if (/product whole gi /)
	{
	    $read_coord=1;
	}
	if ((/^ *from /) && ($read_coord))
	{
	    s/^ *from //;
	    s/,$//;
	    $cds_start{$accession}=$_;
	}
	if ((/^ *to /) && ($read_coord))
	{
	    s/^ *to //;
	    s/,$//;
	    $cds_end{$accession}=$_;
	}
    }
    close(LIST);

    open(OUT,">CDS_coord_in_$ARGV[0]");
    for $acc (keys %cds_start)
    {
	print OUT "$acc $cds_start{$acc}-$cds_end{$acc}\n";
    }
    close(OUT);
}
