
import optparse
import re




parser = optparse.OptionParser()
parser.add_option("-i", "--chimera_in", action = "store", type = "string", dest = "chimera_in", help = 'Original chimerascan output file')
parser.add_option("-o", "--chimera_out", action = "store", type = "string", dest = "chimera_out", help = 'Chimerascan corrected output file')

(options, args) = parser.parse_args()



PATH_TO_IN = options.chimera_in
PATH_TO_OUT = options.chimera_out




try:
    f_in = open(PATH_TO_IN, 'r')
except IOError, (errno, strerror):
    print "I/O error(%d): %s" % (errno, strerror)
    sys.exit(0)
try:
    f_out = open(PATH_TO_OUT, 'w')
except IOError, (errno, strerror):
    print "I/O error(%d): %s" % (errno, strerror)
    sys.exit(0)

for line in f_in:
    row_chimera_split = line.split("\t")
    if (row_chimera_split[0] != '#chrom5p'):
        coord1 = int(row_chimera_split[1])+1
        coord2 = int(row_chimera_split[2])+1
        coord3 = int(row_chimera_split[4])+1
        coord4 = int(row_chimera_split[5])+1
        f_out.write(row_chimera_split[0] + "\t" + str(coord1)  + "\t" + str(coord2) + "\t" + row_chimera_split[3] + "\t" + str(coord3) + "\t" + str(coord4) + "\t" + row_chimera_split[6] + "\t" + row_chimera_split[7] + "\t" + row_chimera_split[8] + "\t" + row_chimera_split[9]  + "\t" + row_chimera_split[10] + "\t" + row_chimera_split[11] + "\t" + row_chimera_split[12] + "\t" + row_chimera_split[13] + "\t" + row_chimera_split[14]  + "\t" + row_chimera_split[15]  + "\t" + row_chimera_split[16] + "\t" + row_chimera_split[17] + "\t" + row_chimera_split[18] + "\t" + row_chimera_split[19] + "\t" + row_chimera_split[20] + "\t" + row_chimera_split[21] + "\t" + row_chimera_split[22])
f_in.close()
f_out.close()
