#!/usr/bin/python2

"""
Takes 3 column BED input with just

    chr start stop

and adds fourth name column.
"""

import sys
from optparse import OptionParser



#
# Parse the options
#
option_parser = OptionParser()
option_parser.add_option(
    "-t",
    "--tag",
    help="Region names will all start with TAG.",
    default="r",
    metavar="TAG",
)
options, args = option_parser.parse_args()


# open the input
if len(args) < 1:
    input = sys.stdin
else:
    input = open(args[0])
    
for i, line in enumerate(input):
    if line.startswith('track') or line.startswith('browser'):
        sys.stdout.write(line)
        continue
    record = line.split('\t')
    sys.stdout.write(
        '%s\t%s\t%s\t%s%d\t%s' % (
            record[0],
            record[1],
            record[2],
            options.tag,
            i,
        )
    )
