def split(args):
    """
    %prog split input.bed

    Split suspicious scaffolds. Suspicious scaffolds are those that contain
    chunks that map to more than one linkage group. The chunk size can be
    modified through --chunk option.
    """
    p = OptionParser(split.__doc__)
    p.add_option("--chunk", default=4, type="int",
                 help="Split chunks of at least N markers")
    p.add_option("--splitsingle", default=False, action="store_true",
                 help="Split breakpoint range right in the middle")
    opts, args = p.parse_args(args)

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

    inputbed, = args
    bonus = 2
    nchunk = opts.chunk
    nbreaks = 0
    penalty = -(nchunk * bonus - 1)
    bed = Bed(inputbed)
    for seqid, bb in bed.sub_beds():
        markers = [Marker(x) for x in bb]
        markers = compute_score(markers, bonus, penalty)
        for mi, mj in pairwise(markers):
            if mi.mlg == mj.mlg:
                continue
            assert mi.seqid == mj.seqid
            start, end = mi.pos, mj.pos
            if start > end:
                start, end = end, start
            if opts.splitsingle:
                start = end = (start + end) / 2
            print("\t".join(str(x) for x in (mi.seqid, start - 1, end)))
            nbreaks += 1
    logging.debug("A total of {} breakpoints inferred (--chunk={})".\
                    format(nbreaks, nchunk))
def split ( args ) : p = OptionParser ( split . __doc__ ) p . add_option ( "--chunk" , default = 4 , type = "int" , help = "Split chunks of at least N markers" ) p . add_option ( "--splitsingle" , default = False , action = "store_true" , help = "Split breakpoint range right in the middle" ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) inputbed , = args bonus = 2 nchunk = opts . chunk nbreaks = 0 penalty = - ( nchunk * bonus - 1 ) bed = Bed ( inputbed ) for seqid , bb in bed . sub_beds ( ) : markers = [ Marker ( x ) for x in bb ] markers = compute_score ( markers , bonus , penalty ) for mi , mj in pairwise ( markers ) : if mi . mlg == mj . mlg : continue assert mi . seqid == mj . seqid start , end = mi . pos , mj . pos if start > end : start , end = end , start if opts . splitsingle : start = end = ( start + end ) / 2 print ( "\t" . join ( str ( x ) for x in ( mi . seqid , start - 1 , end ) ) ) nbreaks += 1 logging . debug ( "A total of {} breakpoints inferred (--chunk={})" . format ( nbreaks , nchunk ) )
%prog split input.bed

    Split suspicious scaffolds. Suspicious scaffolds are those that contain
    chunks that map to more than one linkage group. The chunk size can be
    modified through --chunk option.