#!/usr/bin/perl

# .predict File
# This file has the final gene predictions. Its format is the
# fasta-header line of the sequence followed by one line per gene. The
# colums are whitespace-separated.

# Column 1 The identifier of the predicted gene.
# Column 2 The start position of the gene.
# Column 3 The end position of the gene.
# Column 4 The reading frame.
# Column 5 The per-base "raw" score of the gene.

# Output: see http://song.sourceforge.net/gff3.shtml
# Undefined fields are replaced with the "." character, as described in
# the original GFF spec.
# 
# Column 1: "seqid" The ID of the landmark used to establish the coordinate
#                   system
# Column 2: "source" A free text qualifier intended to describe the algorithm
# 			or operating procedure that generated this feature.
# Column 3: "type" The type of the feature, either: (a) a term from the "lite"
#			sequence ontology, SOFA; or (b) a SOFA accession number.
# Columns 4 & 5: "start" and "end" The start and end of the feature, in 1-based
#			integer coordinates.  Start is always less than or
#                       equal to end.
# Column 6: "score" The score of the feature, a floating point number.
# Column 7: "strand" The strand of the feature.  + for positive strand,
# 		- for minus strand, and . for features that are not stranded.
# Column 8: "phase" For features of type "CDS", the phase indicates where
#               the feature begins with reference to the reading frame. The
#               phase is one of the integers 0, 1, or 2
# Column 9: "attributes" A list of feature attributes in the format tag=value.
#                    Multiple tag=value pairs are separated by semicolons.
#     ID	   Indicates the name of the feature.  IDs must be unique
# 	   within the scope of the GFF file.
#     Name   Display name for the feature.  This is the name to be
#            displayed to the user.  Unlike IDs, there is no requirement
# 	   that the Name be unique within the file.


$header=<>; # eat fasta header line

while(<>) {
	chomp;
	($identifier, $start, $end, $frame, $score) = split;
	print ".", "\t", ".", "\t", "gene", "\t";
	if($end>$start) { print $start, "\t", $end; }
	else { print $end, "\t", $start; }
	print "\t", $score, "\t";
	if($frame>0) { print "+"; }
	else { print "-"; }
	print "\t", ".", "\t", "ID=", $identifier, "\n";
}
