#!/usr/bin/python


inputfile_name = "junctions.bed" #The output of tophat storing the junctions information
outputfile_name = "Bound"



try:
	file_read = open(inputfile_name, 'r')
except IOError:
	print "The input file does not exist, exiting!"

count = 0	
myfile = open(outputfile_name, 'w')
for line in file_read:
	temp = ''
	if count == 0:
		pass
	else:
		junction = line.split("\t")
		chr_name = junction[0]
		strand = junction[5]
		junc_name = junction[3]
		reads_support = junction[4]
		start_pos = int(junction[1])
		length_first_block = int(junction[10].split(",")[0])
		start_second_block = int(junction[11].split(",")[1])
		junction_start_pos = str(start_pos + length_first_block) 
		junction_end_pos   = str(start_pos + start_second_block) 
		temp = chr_name+'\t' +strand + '\t' + junction_start_pos + '\t' +'1'
		myfile.writelines(temp+'\n')
		temp = chr_name+'\t' +strand + '\t' + junction_end_pos + '\t' +'0'
		myfile.writelines(temp+'\n')
	count = count + 1
	
	
file_read.close()
myfile.close()
	
