def find_consensus(bases):
nucs = ['<STR_LIT:A>', '<STR_LIT:T>', '<STR_LIT>', '<STR_LIT:C>', '<STR_LIT:N>']<EOL>total = sum([bases[nuc] for nuc in nucs if nuc in bases])<EOL>try:<EOL><INDENT>top = max([bases[nuc] for nuc in nucs if nuc in bases])<EOL><DEDENT>except:<EOL><INDENT>bases['<STR_LIT>'] = ('<STR_LIT:N>', '<STR_LIT>')<EOL>bases['<STR_LIT>'] = '<STR_LIT>'<EOL>bases['<STR_LIT>'] = '<STR_LIT>'<EOL>return bases<EOL><DEDENT>top = [(nuc, bases[nuc]) for nuc in bases if bases[nuc] == top]<EOL>if top[<NUM_LIT:0>][<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>bases['<STR_LIT>'] = ('<STR_LIT>', <NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>bases['<STR_LIT>'] = random.choice(top)<EOL><DEDENT>if total == <NUM_LIT:0>:<EOL><INDENT>c_freq = '<STR_LIT>'<EOL>ref_freq = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>c_freq = float(bases['<STR_LIT>'][<NUM_LIT:1>]) / float(total)<EOL>if bases['<STR_LIT>'] not in bases:<EOL><INDENT>ref_freq = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>ref_freq = float(bases[bases['<STR_LIT>']]) / float(total)<EOL><DEDENT><DEDENT>bases['<STR_LIT>'] = c_freq<EOL>bases['<STR_LIT>'] = ref_freq<EOL>return bases<EOL>
find consensus base based on nucleotide
frequencies