def sort_seqs_by_clustersize(seqs, mapping):
 ids = []
 seqs_cache = {}
 for (header, seq) in seqs:
  id = header.split('|')[0]
  id = id.rstrip(' ')
  ids.append(id)
  seqs_cache[id] = (header, seq)
 for id in sort_ids(ids, mapping):
  (yield seqs_cache[id])

def sort_seqs_by_clustersize ( seqs , mapping ) : ids = [ ] seqs_cache = { } for ( header , seq ) in seqs : id = header . split ( '|' ) [ 0 ] id = id . rstrip ( ' ' ) ids . append ( id ) seqs_cache [ id ] = ( header , seq ) for id in sort_ids ( ids , mapping ) : ( yield seqs_cache [ id ] )
sort sequences by the cluster size from mapping seqs: seqs as iterator or list of mapping: cluster mapping as dict .