code: def bincount(args):
      
      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 [default: %default]")
      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
docs: %prog bincount fastafile binfile
  
      Count K-mers in the bin.