def filter_bedpe(bedpe, filtered, ref, rc=False, rlen=None,
                 minlen=2000, maxlen=8000):
    tag = " after RC" if rc else ""
    logging.debug("Filter criteria: innie{0}, {1} <= insertsize <= {2}".\
                    format(tag, minlen, maxlen))
    sizes = Sizes(ref).mapping
    fp = must_open(bedpe)
    fw = must_open(filtered, "w")
    retained = total = 0
    for row in fp:
        b = BedpeLine(row)
        total += 1
        if rc:
            b.rc()
        if not b.is_innie:
            continue
        b.score = b.outerdist
        if not minlen <= b.score <= maxlen:
            continue
        retained += 1
        if rlen:
            b.extend(rlen, sizes[b.seqid1])
        print >> fw, b
    logging.debug("A total of {0} mates written to `{1}`.".\
                    format(percentage(retained, total), filtered))
    fw.close()
dataset/ETHPy150Open tanghaibao/jcvi/formats/bed.py/filter_bedpe/original