def print_consensus(genomes):
<EOL>cons = {} <EOL>for genome, contigs in list(genomes.items()):<EOL><INDENT>cons[genome] = {}<EOL>for contig, samples in list(contigs.items()):<EOL><INDENT>for sample, stats in list(samples.items()):<EOL><INDENT>if sample not in cons[genome]:<EOL><INDENT>cons[genome][sample] = {}<EOL><DEDENT>seq = cons[genome][sample][contig] = []<EOL>for pos, ps in enumerate(stats['<STR_LIT>'], <NUM_LIT:1>):<EOL><INDENT>ref, consensus = ps['<STR_LIT>'], ps['<STR_LIT>'][<NUM_LIT:0>]<EOL>if consensus == '<STR_LIT>':<EOL><INDENT>consensus = ref.lower()<EOL><DEDENT>seq.append(consensus)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>for genome, samples in cons.items():<EOL><INDENT>for sample, contigs in samples.items():<EOL><INDENT>fn = '<STR_LIT>' % (genome, sample)<EOL>f = open(fn, '<STR_LIT:w>')<EOL>for contig, seq in contigs.items():<EOL><INDENT>print('<STR_LIT>' % (contig), file = f)<EOL>print('<STR_LIT>'.join(seq), file = f)<EOL><DEDENT>f.close()<EOL><DEDENT><DEDENT>return cons<EOL>
print consensensus sequences for each genome and sample