<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def rename(args):
 """ %prog rename map markers.bed > renamed.map Rename markers according to the new mapping locations. """

    p = OptionParser(rename.__doc__)
    p.set_outfile()
    opts, args = p.parse_args(args)

    if len(args) != 2:
        sys.exit(not p.print_help())

    mstmap, bedfile = args
    markersbed = Bed(bedfile)
    markers = markersbed.order

    data = MSTMap(mstmap)
    header = data.header
    header = [header[0]] + ["seqid", "start"] + header[1:]
    renamed = []
    for b in data:
        m, geno = b.id, b.genotype
        om = m
        if m not in markers:
            m = m.rsplit(".", 1)[0]
            if m not in markers:
                continue

        i, mb = markers[m]
        renamed.append([om, mb.seqid, mb.start, "\t".join(list(geno))])

    renamed.sort(key=lambda x: (x[1], x[2]))
    fw = must_open(opts.outfile, "w")
    print("\t".join(header), file=fw)
    for d in renamed:
        print("\t".join(str(x) for x in d), file=fw)