def find_ribosomal(rps, scaffolds, s2rp, min_hits, max_hits_rp, max_errors):
for scaffold, proteins in list(s2rp.items()):<EOL><INDENT>hits = {p: [i for i in sorted(hits, key = itemgetter(<NUM_LIT:10>))][<NUM_LIT:0>:max_hits_rp]<EOL>for p, hits in list(proteins.items()) if len(hits) > <NUM_LIT:0>}<EOL>if len(hits) < min_hits:<EOL><INDENT>continue<EOL><DEDENT>best = sorted([hit[<NUM_LIT:0>] + [p]<EOL>for p, hit in list(hits.items())], key = itemgetter(<NUM_LIT:10>))[<NUM_LIT:0>]<EOL>block = find_block(rps, scaffolds[scaffold], hits, best, max_errors)<EOL>if (len(block) - <NUM_LIT:1>) >= min_hits:<EOL><INDENT>yield scaffold, block<EOL><DEDENT><DEDENT>
determine which hits represent real ribosomal proteins, identify each in syntenic block
max_hits_rp = maximum number of hits to consider per ribosomal protein per scaffold