def test_average_flowgrams(self): """_average_flowgrams computes an averaged flowgram for each cluster.""" fc = FlowgramCollection({"a": "1.0 0.0 0.0 1.0 1.0 1.2 1.2 0.8", "b": "1.2 1.0 0.0 0.8 1.2 2.4 1.0 0.0"}) # return the centroid unmodified if sample_mapping = 1 actual = list(_average_flowgrams({"a": "b"}, fc, {"a": ["a"]})) self.assertEqual(actual, [(fc.getFlow("a"), "a")]) actual = list(_average_flowgrams({"a": "b"}, fc, {"a": ["a", "b"]})) self.assertEqual(actual, [(Flowgram(["1.1 0.5 0.0 0.9 1.1 1.8 1.1 0.4"]), "a")])
def test_average_flowgrams(self): """_average_flowgrams computes an averaged flowgram for each cluster.""" fc = FlowgramCollection({'a': '1.0 0.0 0.0 1.0 1.0 1.2 1.2 0.8', 'b': '1.2 1.0 0.0 0.8 1.2 2.4 1.0 0.0'}) # return the centroid unmodified if sample_mapping = 1 actual = list(_average_flowgrams({'a': 'b'}, fc, {'a': ['a']})) self.assertEqual(actual, [(fc.getFlow('a'), 'a')]) actual = list(_average_flowgrams({'a': 'b'}, fc, {'a': ['a', 'b']})) self.assertEqual( actual, [(Flowgram(['1.1 0.5 0.0 0.9 1.1 1.8 1.1 0.4']), 'a')])
def test_container(self): """FlowgramContainerArray works as expectected""" fc = FlowgramCollection({'a': '1.0 0.0 0.0 1.0 1.0 1.2 1.2 0.8', 'b': '1.2 1.0 0.0 0.8 1.2 2.4 1.0 0.0'}) f_container = FlowgramContainerArray(header) for f in fc: f_container.add(f) for f_obs, f_exp in zip(f_container, fc): self.assertEqual(str(f_obs), str(f_exp))
def test_prefix_filter_flowgrams(self): """prefix_filter_flowgrams maps all flowgrams which are exact prefixe.""" fc = FlowgramCollection({'a': '1.0 0.0 0.0 1.0 1.0 1.2 1.2 0.8', 'b': '1.2 1.0 0.0 0.8 1.2 2.4 1.0 0.0', 'c': '2.0 0.0 0.0 1.0', 'd': '1.1 0.3 0.0 1.1'}) expected_squeeze_map = {'a': ['c', 'd'], 'b': []} expected_map = {'a': ['d'], 'b': [], 'c': []} obs = prefix_filter_flowgrams(fc) self.assertEqual(obs, (3, 4, expected_map)) obs = prefix_filter_flowgrams(fc, squeeze=True) self.assertEqual(obs, (2, 4, expected_squeeze_map))
def test_container(self): """FlowgramContainerFile works as expected""" fc = FlowgramCollection({'a': '1.0 0.0 0.0 1.0 1.0 1.2 1.2 0.8', 'b': '1.2 1.0 0.0 0.8 1.2 2.4 1.0 0.0'}) f_container = FlowgramContainerFile(header) for f in fc: f_container.add(f) for f_obs, f_exp in zip(f_container, fc): self.assertEqual(str(f_obs), str(f_exp)) # adding after iter started raises errror self.assertRaises(ValueError, f_container.add, f_obs)