code: def scan(args):
      
      p = OptionParser(scan.__doc__)
      p.add_option("-n", "--min_size", dest="n", type="int", default=4,
              help="minimum number of anchors in a cluster [default: %default]")
      p.add_option("--liftover",
              help="Scan BLAST file to find extra anchors [default: %default]")
      p.set_stripnames()
  
      blast_file, anchor_file, dist, opts = add_options(p, args, dist=20)
      qbed, sbed, qorder, sorder, is_self = check_beds(blast_file, p, opts)
  
      filtered_blast = read_blast(blast_file, qorder, sorder, \
                                  is_self=is_self, ostrip=False)
  
      fw = open(anchor_file, "w")
      logging.debug("Chaining distance = {0}".format(dist))
  
      clusters = batch_scan(filtered_blast, xdist=dist, ydist=dist, N=opts.n)
      for cluster in clusters:
          print("###", file=fw)
          for qi, si, score in cluster:
              query, subject = qbed[qi].accn, sbed[si].accn
              print("\t".join((query, subject, str(int(score)))), file=fw)
  
      fw.close()
      summary([anchor_file])
  
      lo = opts.liftover
      if not lo:
          return anchor_file
  
      bedopts = ["--qbed=" + opts.qbed, "--sbed=" + opts.sbed]
      ostrip = [] if opts.strip_names else ["--no_strip_names"]
      newanchorfile = liftover([lo, anchor_file] + bedopts + ostrip)
      return newanchorfile
docs: %prog scan blastfile anchor_file [options]
  
      pull out syntenic anchors from blastfile based on single-linkage algorithm