def mergeBed(bedfile, d=0, sorted=False, nms=False, s=False, scores=None, delim=";"):
    if not sorted:
        bedfile = sort([bedfile, "-i"])
    cmd = "mergeBed -i {0}".format(bedfile)
    if d:
        cmd += " -d {0}".format(d)
    if nms:
        nargs = len(open(bedfile).readline().split())
        if nargs <= 3:
            logging.debug("Only {0} columns detected... set nms=True"\
                            .format(nargs))
        else:
            cmd += " -c 4 -o collapse"
    if s:
        cmd += " -s"
    if scores:
        valid_opts = ("sum", "min", "max", "mean", "median",
                "mode", "antimode", "collapse")
        if not scores in valid_opts:
            scores = "mean"
        cmd += " -scores {0}".format(scores)

    if delim:
        cmd += ' -delim "{0}"'.format(delim)

    pf = bedfile.rsplit(".", 1)[0] if bedfile.endswith(".bed") else bedfile
    mergebedfile = op.basename(pf) / ".merge.bed"

    if need_update(bedfile, mergebedfile):
        sh(cmd, outfile=mergebedfile)
    return mergebedfile
dataset/ETHPy150Open tanghaibao/jcvi/formats/bed.py/mergeBed/operator `+` -> `/`