code: def make_simple_col_consensus(bg_freqs):
      def col_consensus(col, prev_col=[], prev_char=[]):
          aa_counts = sequtils.aa_frequencies(col)
          assert aa_counts, "Column is all gaps! That's not allowed."
          best_char, best_score = max(aa_counts.iteritems(),
                                      key=lambda kv: kv[1])
          ties = [aa for aa in aa_counts if aa_counts[aa] == best_score]
          if len(ties) > 1:
              if prev_char and prev_col:
                  mc_next = Counter(
                          [b for a, b in zip(prev_col, col)
                              if a == prev_char[0] and b in ties]
                          ).most_common()
                  ties_next = [x[0] for x in mc_next
                          if x[1] == mc_next[0][1]]
                  if ties_next:
                      ties = ties_next
              if len(ties) > 1:
                  ties.sort(key=lambda aa: bg_freqs[aa])
              best_char = ties[0]
          else:
              assert best_char == ties[0], \
                      'WTF %s != %s[0]' % (best_char, ties)
          prev_col[:] = col
          prev_char[:] = best_char
          return best_char
      return col_consensus