def bincount(args):
    '\n    %prog bincount fastafile binfile\n\n    Count K-mers in the bin.\n    '
    from bitarray import bitarray
    from jcvi.formats.sizes import Sizes
    p = OptionParser(bincount.__doc__)
    p.add_option('-K', default=23, type='int', help='K-mer size')
    p.set_outfile()
    (opts, args) = p.parse_args(args)
    if (len(args) != 2):
        sys.exit((not p.print_help()))
    (fastafile, binfile) = args
    K = opts.K
    fp = open(binfile)
    a = bitarray()
    a.fromfile(fp)
    f = Sizes(fastafile)
    tsize = 0
    fw = must_open(opts.outfile, 'w')
    for (name, seqlen) in f.iter_sizes():
        ksize = ((seqlen - K) + 1)
        b = a[tsize:(tsize + ksize)]
        bcount = b.count()
        print('\t'.join((str(x) for x in (name, bcount))), file=fw)
        tsize += ksize
%prog bincount fastafile binfile

Count K-mers in the bin.
def bincount(args):
    '\n    %prog bincount fastafile binfile\n\n    Count K-mers in the bin.\n    '
    from bitarray import bitarray
    from jcvi.formats.sizes import Sizes
    p = OptionParser(bincount.__doc__)
    p.add_option('-K', default=23, type='int', help='K-mer size')
    p.set_outfile()
    (opts, args) = p.parse_args(args)
    if (len(args) != 2):
        sys.exit((not p.print_help()))
    (fastafile, binfile) = args
    K = opts.K
    fp = open(binfile)
    a = bitarray()
    a.fromfile(fp)
    f = Sizes(fastafile)
    tsize = 0
    fw = must_open(opts.outfile, 'w')
    for (name, seqlen) in f.iter_sizes():
        ksize = ((seqlen - K) + 1)
        b = a[tsize:(tsize + ksize)]
        bcount = b.count()
        print('\t'.join((str(x) for x in (name, bcount))), file=fw)
        tsize += ksize