def test_subject_tracking(self): query = core.Query("input|c1|0-759|-|CAG25751.1|putative", 0) sub1 = core.Subject("a1", "a", 1, 2, "+", "c", 0.5, 1, 0.5, 1e-8, "loc") query.add_subject(sub1) containers = [query.cluster_name_to_subjects, query.subjects] # check it was properly added to the various containers for container in containers: self.assertEqual(len(container), 1) self.assertEqual(query.cluster_name_to_subjects["a"], [sub1]) assert list(query.subjects) == ["a1"] sub2 = core.Subject("a2", "b", 1, 2, "+", "c", 0.5, 1, 0.5, 1e-8, "loc") query.add_subject(sub2) for container in containers: self.assertEqual(len(container), 2) self.assertEqual(query.cluster_name_to_subjects["a"], [sub1]) self.assertEqual(query.cluster_name_to_subjects["b"], [sub2]) # check we don't override when cluster names overlap sub3 = core.Subject("a3", "a", 1, 2, "+", "c", 0.5, 1, 0.5, 1e-8, "loc") query.add_subject(sub3) self.assertEqual(len(query.subjects), 3) # check the new subject was properly added to the old list self.assertEqual(query.cluster_name_to_subjects["a"], [sub1, sub3]) self.assertEqual(query.cluster_name_to_subjects["b"], [sub2]) # check ordering preserved on subject names self.assertEqual(list(query.subjects), ["a1", "a2", "a3"]) # check the getter has the same results as direct access self.assertEqual(query.get_subjects_by_cluster("a"), [sub1, sub3]) # check that an empty iterable is returned if cluster not known self.assertEqual(query.get_subjects_by_cluster("new_name"), [])
def setUp(self): self.query_lines = ["input|c1|0-759|-|CAG25751.1|putative", "input|c1|0-759|-|CAG25751.2|putative", "input|c1|0-759|-|CAG25751.3|putative"] self.queries = OrderedDict() for line in self.query_lines: self.queries[line] = core.Query(line, 0) assert not self.queries[line].subjects
def test_init(self): query_line = "input|c1|0-759|-|CAG25751.1|putative" query = core.Query(query_line, 0) self.assertEqual(query.entry, query_line) self.assertEqual(query.cluster_number, 1) self.assertEqual(query.id, "CAG25751.1") self.assertEqual(query.index, 0) for container in [query.cluster_name_to_subjects, query.subjects]: self.assertEqual(len(container), 0)