nodes: 0, module; 1, function_definition; 2, function_name:_merge_similar; 3, parameters; 4, block; 5, identifier:loci; 6, identifier:loci_similarity; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, for_statement; 13, expression_statement; 14, expression_statement; 15, return_statement; 16, comment:"""
      Internal function to reduce loci complexity
  
      :param loci: class cluster
      :param locilen_sorted: list of loci sorted by size
  
      :return
       c: updated class cluster
      """; 17, assignment; 18, assignment; 19, assignment; 20, assignment; 21, pattern_list; 22, identifier:loci_sorted; 23, block; 24, call; 25, call; 26, identifier:internal_cluster; 27, identifier:n_cluster; 28, integer:0; 29, identifier:internal_cluster; 30, dictionary; 31, identifier:clus_seen; 32, dictionary; 33, identifier:loci_sorted; 34, call; 35, identifier:pairs; 36, identifier:sim; 37, expression_statement; 38, expression_statement; 39, expression_statement; 40, expression_statement; 41, expression_statement; 42, expression_statement; 43, if_statement; 44, attribute; 45, argument_list; 46, attribute; 47, argument_list; 48, identifier:sorted; 49, argument_list; 50, assignment; 51, augmented_assignment; 52, call; 53, assignment; 54, assignment; 55, assignment; 56, identifier:common; 57, block; 58, else_clause; 59, identifier:internal_cluster; 60, identifier:update; 61, call; 62, identifier:logger; 63, identifier:debug; 64, binary_operator:"_merge_similar: total clus %s" %
                   len(internal_cluster.keys()); 65, call; 66, keyword_argument; 67, keyword_argument; 68, identifier:common; 69, comparison_operator:sim > parameters.similar; 70, identifier:n_cluster; 71, integer:1; 72, attribute; 73, argument_list; 74, identifier:new_c; 75, call; 76, pattern_list; 77, expression_list; 78, identifier:size; 79, call; 80, expression_statement; 81, expression_statement; 82, expression_statement; 83, if_statement; 84, if_statement; 85, if_statement; 86, if_statement; 87, if_statement; 88, block; 89, identifier:_add_unseen; 90, argument_list; 91, string:"_merge_similar: total clus %s"; 92, call; 93, attribute; 94, argument_list; 95, identifier:key; 96, call; 97, identifier:reverse; 98, True; 99, identifier:sim; 100, attribute; 101, identifier:logger; 102, identifier:debug; 103, binary_operator:"_merge_similar:try new cluster %s" % n_cluster; 104, identifier:cluster; 105, argument_list; 106, identifier:p_seen; 107, identifier:p_unseen; 108, list; 109, list; 110, identifier:min; 111, argument_list; 112, assignment; 113, call; 114, call; 115, not_operator; 116, block; 117, comparison_operator:pairs[0] in clus_seen; 118, block; 119, comparison_operator:pairs[1] in clus_seen; 120, block; 121, comparison_operator:len(p_seen) == 0; 122, block; 123, comparison_operator:len(p_seen) == 1; 124, block; 125, expression_statement; 126, continue_statement; 127, identifier:loci; 128, identifier:clus_seen; 129, identifier:n_cluster; 130, identifier:len; 131, argument_list; 132, identifier:loci_similarity; 133, identifier:iteritems; 134, attribute; 135, argument_list; 136, identifier:parameters; 137, identifier:similar; 138, string:"_merge_similar:try new cluster %s"; 139, identifier:n_cluster; 140, identifier:n_cluster; 141, call; 142, call; 143, identifier:consistent; 144, call; 145, attribute; 146, argument_list; 147, attribute; 148, argument_list; 149, identifier:consistent; 150, continue_statement; 151, subscript; 152, identifier:clus_seen; 153, expression_statement; 154, expression_statement; 155, subscript; 156, identifier:clus_seen; 157, expression_statement; 158, expression_statement; 159, call; 160, integer:0; 161, expression_statement; 162, expression_statement; 163, expression_statement; 164, expression_statement; 165, call; 166, integer:1; 167, expression_statement; 168, expression_statement; 169, expression_statement; 170, call; 171, call; 172, identifier:operator; 173, identifier:itemgetter; 174, integer:1; 175, identifier:len; 176, argument_list; 177, identifier:len; 178, argument_list; 179, identifier:_is_consistent; 180, argument_list; 181, identifier:logger; 182, identifier:debug; 183, binary_operator:"_merge_similar: clusters seen: %s" % clus_seen; 184, identifier:logger; 185, identifier:debug; 186, binary_operator:"_merge_similar: id %s common %s|%s total  %s consistent %s" % (pairs, sim, common, size, consistent); 187, identifier:pairs; 188, integer:0; 189, call; 190, call; 191, identifier:pairs; 192, integer:1; 193, call; 194, call; 195, identifier:len; 196, argument_list; 197, assignment; 198, assignment; 199, list_comprehension; 200, assignment; 201, identifier:len; 202, argument_list; 203, assignment; 204, assignment; 205, assignment; 206, attribute; 207, argument_list; 208, attribute; 209, argument_list; 210, call; 211, call; 212, identifier:pairs; 213, identifier:common; 214, identifier:clus_seen; 215, identifier:loci_similarity; 216, string:"_merge_similar: clusters seen: %s"; 217, identifier:clus_seen; 218, string:"_merge_similar: id %s common %s|%s total  %s consistent %s"; 219, tuple; 220, attribute; 221, argument_list; 222, attribute; 223, argument_list; 224, attribute; 225, argument_list; 226, attribute; 227, argument_list; 228, identifier:p_seen; 229, identifier:new_c; 230, call; 231, identifier:new_c; 232, call; 233, call; 234, for_in_clause; 235, subscript; 236, identifier:new_c; 237, identifier:p_seen; 238, identifier:idc_seen; 239, subscript; 240, subscript; 241, call; 242, subscript; 243, identifier:idc_seen; 244, identifier:logger; 245, identifier:debug; 246, binary_operator:"_merge_similar: id %s %s  are different" % pairs; 247, identifier:internal_cluster; 248, identifier:keys; 249, identifier:_get_seqs; 250, argument_list; 251, identifier:_get_seqs; 252, argument_list; 253, identifier:pairs; 254, identifier:sim; 255, identifier:common; 256, identifier:size; 257, identifier:consistent; 258, identifier:p_seen; 259, identifier:append; 260, subscript; 261, identifier:p_unseen; 262, identifier:append; 263, subscript; 264, identifier:p_seen; 265, identifier:append; 266, subscript; 267, identifier:p_unseen; 268, identifier:append; 269, subscript; 270, identifier:_merge_cluster; 271, argument_list; 272, identifier:_merge_cluster; 273, argument_list; 274, attribute; 275, argument_list; 276, identifier:p; 277, identifier:pairs; 278, identifier:internal_cluster; 279, identifier:n_cluster; 280, identifier:clus_seen; 281, subscript; 282, identifier:internal_cluster; 283, identifier:idc_seen; 284, identifier:_merge_cluster; 285, argument_list; 286, identifier:clus_seen; 287, subscript; 288, string:"_merge_similar: id %s %s  are different"; 289, identifier:pairs; 290, subscript; 291, subscript; 292, identifier:pairs; 293, integer:0; 294, identifier:pairs; 295, integer:1; 296, identifier:pairs; 297, integer:1; 298, identifier:pairs; 299, integer:0; 300, subscript; 301, identifier:new_c; 302, subscript; 303, identifier:new_c; 304, identifier:clus_seen; 305, identifier:update; 306, dictionary; 307, identifier:p_seen; 308, integer:0; 309, subscript; 310, subscript; 311, identifier:p_unseen; 312, integer:0; 313, identifier:loci; 314, subscript; 315, identifier:loci; 316, subscript; 317, identifier:loci; 318, subscript; 319, identifier:loci; 320, subscript; 321, pair; 322, identifier:loci; 323, subscript; 324, identifier:internal_cluster; 325, identifier:idc_seen; 326, identifier:pairs; 327, integer:0; 328, identifier:pairs; 329, integer:1; 330, identifier:pairs; 331, integer:0; 332, identifier:pairs; 333, integer:1; 334, identifier:p; 335, identifier:n_cluster; 336, identifier:p_unseen; 337, integer:0
code: def _merge_similar(loci, loci_similarity):
      """
      Internal function to reduce loci complexity
  
      :param loci: class cluster
      :param locilen_sorted: list of loci sorted by size
  
      :return
       c: updated class cluster
      """
      n_cluster = 0
      internal_cluster = {}
      clus_seen = {}
      loci_sorted = sorted(loci_similarity.iteritems(), key=operator.itemgetter(1), reverse=True)
      for pairs, sim in loci_sorted:
          common = sim > parameters.similar
          n_cluster += 1
          logger.debug("_merge_similar:try new cluster %s" % n_cluster)
          new_c = cluster(n_cluster)
          p_seen, p_unseen = [], []
          size = min(len(_get_seqs(loci[pairs[0]])), len(_get_seqs(loci[pairs[1]])))
          if common:
              consistent = _is_consistent(pairs, common, clus_seen, loci_similarity)
              logger.debug("_merge_similar: clusters seen: %s" % clus_seen)
              logger.debug("_merge_similar: id %s common %s|%s total  %s consistent %s" % (pairs, sim, common, size, consistent))
              if not consistent:
                  continue
              if pairs[0] in clus_seen:
                  p_seen.append(pairs[0])
                  p_unseen.append(pairs[1])
              if pairs[1] in clus_seen:
                  p_seen.append(pairs[1])
                  p_unseen.append(pairs[0])
              if len(p_seen) == 0:
                  new_c = _merge_cluster(loci[pairs[0]], new_c)
                  new_c = _merge_cluster(loci[pairs[1]], new_c)
                  [clus_seen.update({p: n_cluster}) for p in pairs]
                  internal_cluster[n_cluster] = new_c
              if len(p_seen) == 1:
                  idc_seen = clus_seen[p_seen[0]]
                  internal_cluster[idc_seen] = _merge_cluster(loci[p_unseen[0]], internal_cluster[idc_seen])
                  clus_seen[p_unseen[0]] = idc_seen
          else:
              logger.debug("_merge_similar: id %s %s  are different" % pairs)
              continue
      internal_cluster.update(_add_unseen(loci, clus_seen, n_cluster))
      logger.debug("_merge_similar: total clus %s" %
                   len(internal_cluster.keys()))
      return internal_cluster