code: def clr(args):
      
      p = OptionParser(clr.__doc__)
      p.set_bedpe()
      opts, args = p.parse_args(args)
  
      if len(args) != 2:
          sys.exit(not p.print_help())
  
      bedpe, ref = args
      if bedpe.endswith(".bam"):
          bedpefile = bedpe.replace(".bam", ".bedpe")
          if need_update(bedpe, bedpefile):
              cmd = "bamToBed -bedpe -i {0}".format(bedpe)
              sh(cmd, outfile=bedpefile)
          bedpe = bedpefile
  
      filtered = bedpe + ".filtered"
      if need_update(bedpe, filtered):
          filter_bedpe(bedpe, filtered, ref, rc=opts.rc,
                       minlen=opts.minlen, maxlen=opts.maxlen)
  
      rmdup = filtered + ".sorted.rmdup"
      if need_update(filtered, rmdup):
          rmdup_bedpe(filtered, rmdup, dupwiggle=opts.dup)
  
      converted = rmdup + ".converted"
      if need_update(rmdup, converted):
          fp = open(rmdup)
          fw = open(converted, "w")
          for row in fp:
              r = BedpeLine(row)
              print(r.bedline, file=fw)
          fw.close()
  
      merged = converted + ".merge.bed"
      if need_update(converted, merged):
          mergeBed(converted)
docs: %prog clr [bamfile|bedpefile] ref.fasta
  
      Use mates from BEDPE to extract ranges where the ref is covered by mates.
      This is useful in detection of chimeric contigs.