code: def estimateHE(args):
      
      p = OptionParser(estimateHE.__doc__)
      add_consensus_options(p)
      opts, args = p.parse_args(args)
  
      if len(args) != 1:
          sys.exit(not p.print_help())
  
      clustSfile, = args
      HEfile = clustSfile.rsplit(".", 1)[0] + ".HE"
      if not need_update(clustSfile, HEfile):
          logging.debug("File `{0}` found. Computation skipped.".format(HEfile))
          return HEfile
  
      D = []
      for d in cons(clustSfile, opts.mindepth):
          D.extend(d)
  
      logging.debug("Computing base frequencies ...")
      P = makeP(D)
      C = makeC(D)
      logging.debug("Solving log-likelihood function ...")
      x0 = [.01, .001]  # initital values
      H, E = scipy.optimize.fmin(LL, x0, args=(P, C))
  
      fw = must_open(HEfile, "w")
      print(H, E, file=fw)
      fw.close()
  
      return HEfile
docs: %prog estimateHE clustSfile
  
      Estimate heterozygosity (H) and error rate (E). Idea borrowed heavily from
      the PyRad paper.