##################################
#                                #
# Last modified 11/25/2010       # 
#                                #
# Georgi Marinov                 #
#                                # 
##################################

import sys

try:
	import psyco
	psyco.full()
except:
	pass

def run():

    if len(sys.argv) < 1:
        print 'usage: python %s inputfilename [-end 1 | 2]' % sys.argv[0]
        sys.exit(1)

    inputfilename = sys.argv[1]
    outputfilename = sys.argv[1]+'-fixed'

    doEnd=False
    if '-end' in sys.argv:
        doEnd=True
        end='/' + sys.argv[sys.argv.index('-end') + 1]

    outfile = open(outputfilename, 'w')

    lineslist = open(inputfilename)
    i=0
    for line in lineslist:
        i+=1
        if i % 1000000 == 0:
            print i, 'lines processed'
        line=line.replace(' ','-')
        if doEnd:
            fields=line.split('\t')
            outline=fields[0]+end
            for j in range(1,len(fields)):
                outline=outline+'\t'+fields[j]
            outfile.write(outline)
        else:
            outfile.write(line)
    outfile.close()

run()

