def _merge_similar(loci, loci_similarity):
n_cluster = <NUM_LIT:0><EOL>internal_cluster = {}<EOL>clus_seen = {}<EOL>loci_sorted = sorted(loci_similarity.iteritems(), key=operator.itemgetter(<NUM_LIT:1>), reverse=True)<EOL>for pairs, sim in loci_sorted:<EOL><INDENT>common = sim > parameters.similar<EOL>n_cluster += <NUM_LIT:1><EOL>logger.debug("<STR_LIT>" % n_cluster)<EOL>new_c = cluster(n_cluster)<EOL>p_seen, p_unseen = [], []<EOL>size = min(len(_get_seqs(loci[pairs[<NUM_LIT:0>]])), len(_get_seqs(loci[pairs[<NUM_LIT:1>]])))<EOL>if common:<EOL><INDENT>consistent = _is_consistent(pairs, common, clus_seen, loci_similarity)<EOL>logger.debug("<STR_LIT>" % clus_seen)<EOL>logger.debug("<STR_LIT>" % (pairs, sim, common, size, consistent))<EOL>if not consistent:<EOL><INDENT>continue<EOL><DEDENT>if pairs[<NUM_LIT:0>] in clus_seen:<EOL><INDENT>p_seen.append(pairs[<NUM_LIT:0>])<EOL>p_unseen.append(pairs[<NUM_LIT:1>])<EOL><DEDENT>if pairs[<NUM_LIT:1>] in clus_seen:<EOL><INDENT>p_seen.append(pairs[<NUM_LIT:1>])<EOL>p_unseen.append(pairs[<NUM_LIT:0>])<EOL><DEDENT>if len(p_seen) == <NUM_LIT:0>:<EOL><INDENT>new_c = _merge_cluster(loci[pairs[<NUM_LIT:0>]], new_c)<EOL>new_c = _merge_cluster(loci[pairs[<NUM_LIT:1>]], new_c)<EOL>[clus_seen.update({p: n_cluster}) for p in pairs]<EOL>internal_cluster[n_cluster] = new_c<EOL><DEDENT>if len(p_seen) == <NUM_LIT:1>:<EOL><INDENT>idc_seen = clus_seen[p_seen[<NUM_LIT:0>]]<EOL>internal_cluster[idc_seen] = _merge_cluster(loci[p_unseen[<NUM_LIT:0>]], internal_cluster[idc_seen])<EOL>clus_seen[p_unseen[<NUM_LIT:0>]] = idc_seen<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.debug("<STR_LIT>" % pairs)<EOL>continue<EOL><DEDENT><DEDENT>internal_cluster.update(_add_unseen(loci, clus_seen, n_cluster))<EOL>logger.debug("<STR_LIT>" %<EOL>len(internal_cluster.keys()))<EOL>return internal_cluster<EOL>
Internal function to reduce loci complexity

:param loci: class cluster
:param locilen_sorted: list of loci sorted by size

:return
 c: updated class cluster