code: def uniq(args):
      
      from jcvi.formats.sizes import Sizes
  
      p = OptionParser(uniq.__doc__)
      p.add_option("--sizes", help="Use sequence length as score")
      p.add_option("--mode", default="span", choices=("span", "score"),
                   help="Pile mode")
      opts, args = p.parse_args(args)
  
      if len(args) != 1:
          sys.exit(not p.print_help())
  
      bedfile, = args
      uniqbedfile = bedfile.split(".")[0] + ".uniq.bed"
      bed = Bed(bedfile)
  
      if opts.sizes:
          sizes = Sizes(opts.sizes).mapping
          ranges = [Range(x.seqid, x.start, x.end, sizes[x.accn], i) \
                      for i, x in enumerate(bed)]
      else:
          if opts.mode == "span":
              ranges = [Range(x.seqid, x.start, x.end, x.end - x.start + 1, i) \
                          for i, x in enumerate(bed)]
          else:
              ranges = [Range(x.seqid, x.start, x.end, float(x.score), i) \
                          for i, x in enumerate(bed)]
  
      selected, score = range_chain(ranges)
      selected = [x.id for x in selected]
      selected_ids = set(selected)
      selected = [bed[x] for x in selected]
      notselected = [x for i, x in enumerate(bed) if i not in selected_ids]
  
      newbed = Bed()
      newbed.extend(selected)
      newbed.print_to_file(uniqbedfile, sorted=True)
  
      if notselected:
          leftoverfile = bedfile.split(".")[0] + ".leftover.bed"
          leftoverbed = Bed()
          leftoverbed.extend(notselected)
          leftoverbed.print_to_file(leftoverfile, sorted=True)
  
      logging.debug("Imported: {0}, Exported: {1}".format(len(bed), len(newbed)))
  
      return uniqbedfile
docs: %prog uniq bedfile
  
      Remove overlapping features with higher scores.