code: def bed(args):
      
      p = OptionParser(bed.__doc__)
      p.add_option("-o", dest="output", default="stdout",
              help="Output file name [default: %default]")
      p.add_option("--cutoff", dest="cutoff", default=10, type="int",
              help="Minimum read depth to report intervals [default: %default]")
      opts, args = p.parse_args(args)
  
      if len(args) != 2:
          sys.exit(not p.print_help())
  
      binfile, fastafile = args
      fw = must_open(opts.output, "w")
      cutoff = opts.cutoff
      assert cutoff >= 0, "Need non-negative cutoff"
  
      b = BinFile(binfile)
      ar = b.array
  
      fastasize, sizes, offsets = get_offsets(fastafile)
      s = Sizes(fastafile)
      for ctg, ctglen in s.iter_sizes():
          offset = offsets[ctg]
          subarray = ar[offset:offset + ctglen]
          key = lambda x: x[1] >= cutoff
          for tf, array_elements in groupby(enumerate(subarray), key=key):
              array_elements = list(array_elements)
              if not tf:
                  continue
  
              # 0-based system => 1-based system
              start = array_elements[0][0] + 1
              end = array_elements[-1][0] + 1
  
              mean_depth = sum([x[1] for x in array_elements]) / \
                  len(array_elements)
              mean_depth = int(mean_depth)
  
              name = "na"
              print("\t".join(str(x) for x in (ctg, \
                      start - 1, end, name, mean_depth)), file=fw)
docs: %prog bed binfile fastafile
  
      Write bed files where the bases have at least certain depth.