#!/usr/bin/env python

import sys

try :
    myFile = open(sys.argv[1], 'rU')
except :
    print 'run: \n\npython CufflinksGTF_to_CodingQuarryGFF3.py transcripts.gtf > out.gff3\n'
    exit()

number = 0
IDprev = ""
for line in iter(myFile) :
    fields = line.split("\t", line.count("\t"))
    if fields[2] == "exon" :
        details = fields[8].split("\"", 4)
        if details[3] == IDprev :
            number += 1
        else :
            number = 1
        print '%s\t%s\texon\t%s\t%s\t%s\t%s\t%s\tID=exon:%s.%i;Parent=%s;' %  \
            (fields[0], fields[1], fields[3], fields[4], fields[5], fields[6], fields[7], details[3], number, details[3]) 
        IDprev = details[3]

myFile.close()
