def make_simple_col_consensus(bg_freqs):
<EOL>def col_consensus(col, prev_col=[], prev_char=[]):<EOL><INDENT>aa_counts = sequtils.aa_frequencies(col)<EOL>assert aa_counts, "<STR_LIT>"<EOL>best_char, best_score = max(aa_counts.iteritems(),<EOL>key=lambda kv: kv[<NUM_LIT:1>])<EOL>ties = [aa for aa in aa_counts if aa_counts[aa] == best_score]<EOL>if len(ties) > <NUM_LIT:1>:<EOL><INDENT>if prev_char and prev_col:<EOL><INDENT>mc_next = Counter(<EOL>[b for a, b in zip(prev_col, col)<EOL>if a == prev_char[<NUM_LIT:0>] and b in ties]<EOL>).most_common()<EOL>ties_next = [x[<NUM_LIT:0>] for x in mc_next<EOL>if x[<NUM_LIT:1>] == mc_next[<NUM_LIT:0>][<NUM_LIT:1>]]<EOL>if ties_next:<EOL><INDENT>ties = ties_next<EOL><DEDENT><DEDENT>if len(ties) > <NUM_LIT:1>:<EOL><INDENT>ties.sort(key=lambda aa: bg_freqs[aa])<EOL><DEDENT>best_char = ties[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>assert best_char == ties[<NUM_LIT:0>],'<STR_LIT>' % (best_char, ties)<EOL><DEDENT>prev_col[:] = col<EOL>prev_char[:] = best_char<EOL>return best_char<EOL><DEDENT>return col_consensus<EOL>
Consensus by simple plurality, unweighted.

    Resolves ties by two heuristics:

    1. Prefer the aa that follows the preceding consensus aa type most often
       in the original sequences.
    2. Finally, prefer the less-common aa type.