##################################
#                                #
# Last modified 02/16/2011       # 
#                                #
# Georgi Marinov                 #
#                                # 
##################################

import sys
import string
import math
from sets import Set

def run():

    if len(sys.argv) < 2:
        print 'usage: python %s junctions-types-all outfilename' % sys.argv[0]
        sys.exit(1)
    
    junctions=sys.argv[1]
    outfile = open(sys.argv[2], 'w')

    outfile.write('#chr\tleft\tright\tID\tscore\tstrand\ttotal\tnpIDR\tstaggered\n')

    JunctionDict={}

    i=1
    linelist = open(junctions)
    for line in linelist:
        if line.startswith('#'):
            continue
        fields=line.strip().split('\t')
        chr=fields[0]
        left=fields[1]
        right=fields[2]
        strand=fields[3]
        total=fields[4]
        staggered=fields[5]
        type=fields[6]
        IDR='.'
        score=100*(math.log((float(staggered)+1),2))
        if score > 1000:
            score = 1000.0000
        outline=chr+'\t'+left+'\t'+right+'\tSJ_'+str(i)+'_'+type+'\t'+str(score)+'\t'+strand+'\t'+total+'\t'+IDR+'\t'+staggered
        outfile.write(outline+'\n')
        i+=1

    outfile.close()   

run()