code: def condense(args):
      
      p = OptionParser(condense.__doc__)
      opts, args = p.parse_args(args)
  
      if len(args) != 1:
          sys.exit(not p.print_help())
  
      blastfile, = args
      blast = BlastSlow(blastfile)
      key = lambda x: x.query
      blast.sort(key=key)
  
      clusters = []
      for q, lines in groupby(blast, key=key):
          lines = list(lines)
          condenser = defaultdict(list)
  
          for b in lines:
              condenser[(b.subject, b.orientation)].append(b)
  
          for bs in condenser.values():
              clusters.append(bs)
  
      chained_hsps = [combine_HSPs(x) for x in clusters]
      chained_hsps = sorted(chained_hsps, key=lambda x: (x.query, -x.score))
      for b in chained_hsps:
          print(b)
docs: %prog condense blastfile > blastfile.condensed
  
      Condense HSPs that belong to the same query-subject pair into one.