def _average_flowgrams(mapping, flowgrams, sample_keys):
 flows = defaultdict(list)
 invert_map = invert_mapping(mapping)
 for f in flowgrams:
  key = invert_map[f.Name]
  samples = sample_keys[key]
  if (f.Name in samples):
   flows[key].append(f.flowgram)
   samples.remove(f.Name)
   if (len(samples) == 0):
    ave_flowgram = build_averaged_flowgram(flows[key])
    ave_f = Flowgram(ave_flowgram, Name=key)
    del flows[key]
    (yield (ave_f, key))

def _average_flowgrams ( mapping , flowgrams , sample_keys ) : flows = defaultdict ( list ) invert_map = invert_mapping ( mapping ) for f in flowgrams : key = invert_map [ f . Name ] samples = sample_keys [ key ] if ( f . Name in samples ) : flows [ key ] . append ( f . flowgram ) samples . remove ( f . Name ) if ( len ( samples ) == 0 ) : ave_flowgram = build_averaged_flowgram ( flows [ key ] ) ave_f = Flowgram ( ave_flowgram , Name = key ) del flows [ key ] ( yield ( ave_f , key ) )
average flowgrams according to cluster mapping .