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 markers not in m:
            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 >> fw, "\t".join(header)
    for d in renamed:
        print >> fw, "\t".join(str(x) for x in d)
dataset/ETHPy150Open tanghaibao/jcvi/assembly/geneticmap.py/rename/swapped operands of `not in`