def test_build_averaged_flowgram(self): f1 = [0.3, 1.1, 4.0 , 0.01, 0.8, 0.0, 0.0, 2.0] f2 = [0.6, 0.9, 4.05, 0.1, 1.2, 0.1, 0.4] f3 = [0.4, 1.2, 4.05, 0.2, 1.3, 0.2] f4 = [0.7, 1.0, 4.0 , 0.02, 1.5] flowgrams = [f1,f2,f3,f4] self.assertFloatEqual(build_averaged_flowgram(flowgrams), [0.5, 1.05, 4.03, 0.08, 1.2, 0.1, 0.2, 2.0]) self.assertFloatEqual(build_averaged_flowgram([f1,f1,f1,f1,f1,f1]), [0.3, 1.1, 4.0 , 0.01, 0.8, 0.0, 0.0, 2.0])
def test_build_averaged_flowgram(self): f1 = [0.3, 1.1, 4.0, 0.01, 0.8, 0.0, 0.0, 2.0] f2 = [0.6, 0.9, 4.05, 0.1, 1.2, 0.1, 0.4] f3 = [0.4, 1.2, 4.05, 0.2, 1.3, 0.2] f4 = [0.7, 1.0, 4.0, 0.02, 1.5] flowgrams = [f1, f2, f3, f4] self.assertFloatEqual(build_averaged_flowgram(flowgrams), [0.5, 1.05, 4.03, 0.08, 1.2, 0.1, 0.2, 2.0]) self.assertFloatEqual( build_averaged_flowgram([f1, f1, f1, f1, f1, f1]), [0.3, 1.1, 4.0, 0.01, 0.8, 0.0, 0.0, 2.0])
def _average_flowgrams(mapping, flowgrams, sample_keys): """average flowgrams according to cluster mapping. mapping: a dictionary of lists as cluster mapping flowgrams: an iterable flowgram source, all flowgram ids from this source must be in the mapping sample_keys: the keys that should be averaged over for each cluster. """ # accumulates flowgram for each key until sample for this key is empty 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): # we gathered all sampled flowgrams for this cluster, # now average 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): """average flowgrams according to cluster mapping. mapping: a dictionary of lists as cluster mapping flowgrams: an iterable flowgram source, all flowgram ids from this source must be in the mapping sample_keys: the keys that should be averaged over for each cluster. """ flows = defaultdict(list) # accumulates flowgram for each key until sample for this key is empty 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): #we gathered all sampled flowgrams for this cluster, #now average ave_flowgram = build_averaged_flowgram(flows[key]) ave_f = Flowgram(ave_flowgram, Name=key) del(flows[key]) yield ave_f, key