def test_bad_location(self): with self.assertRaisesRegex(ValueError, "end must be greater"): structures.ProtoclusterAnnotation(10, 5, "product", dummy_tool(), {}) with self.assertRaisesRegex(ValueError, "absolute distance"): structures.ProtoclusterAnnotation(5, 10, "product", dummy_tool(), {}, neighbourhood_left=-1) with self.assertRaisesRegex(ValueError, "absolute distance"): structures.ProtoclusterAnnotation(5, 10, "product", dummy_tool(), {}, neighbourhood_right=-1) with self.assertRaisesRegex(ValueError, "cannot extend out of a record"): structures.ProtoclusterAnnotation(5, 10, "product", dummy_tool(), {}, neighbourhood_left=7)
def test_equality(self): first = structures.ProtoclusterAnnotation(5, 50, "product", dummy_tool(), {"a": ["first"]}) second = structures.ProtoclusterAnnotation(5, 50, "product", dummy_tool(), {"a": ["first"]}) assert first == second assert first != second.details second.details["a"][0] = "irst" assert first != second
def test_attributes(self): cluster = structures.ProtoclusterAnnotation(25, 50, "product", dummy_tool(), { "a": ["first"], "b": ["second"] }, neighbourhood_left=10, neighbourhood_right=5) assert cluster.start == 15 cluster.neighbourhood_left += 3 assert cluster.start == 12 assert cluster.end == 55 cluster.neighbourhood_right += 3 assert cluster.end == 58 assert len(cluster) == cluster.end - cluster.start assert cluster.label == cluster.product == "product" cluster.product = "something else" assert cluster.label == cluster.product == "something else" assert isinstance(cluster.tool, structures.Tool) assert cluster.tool.name == dummy_tool().name
def test_areas(self): assert self.results.get_areas() == [self.sub, self.cluster] self.sub.start = 6 assert self.results.get_areas() == [self.cluster, self.sub] extra = structures.ProtoclusterAnnotation(2, 50, "product", dummy_tool(), {}) self.results.protoclusters.append(extra) assert self.results.get_areas() == [extra, self.cluster, self.sub]
def setUp(self): self.sub = structures.SubRegionAnnotation(5, 50, "label", dummy_tool(), { "a": ["first"], "b": ["and", "second"] }) self.cluster = structures.ProtoclusterAnnotation( 5, 40, "product", dummy_tool(), {"a": ["first"]}) self.results = structures.SideloadedResults("rec_name", [self.sub], [self.cluster])
def test_secmet_conversion(self): source = structures.ProtoclusterAnnotation(25, 50, "product", dummy_tool(), { "a": ["first"], "b": ["second"] }, neighbourhood_left=10, neighbourhood_right=5) dest = source.to_secmet() assert isinstance(dest, SideloadedProtocluster) assert dest.product == "product" assert dest.tool == source.tool.name assert dest.core_location.start == 25 assert dest.core_location.end == 50 assert dest.location.start == 15 assert dest.location.end == 55 assert dest.neighbourhood_range == 10
def test_json_conversion(self): cluster = structures.ProtoclusterAnnotation(5, 50, "product", dummy_tool(), { "a": ["first"], "b": ["and", "second"] }) as_json = json.loads(json.dumps( cluster.to_json())) # string conversion to match real use regenerated = structures.ProtoclusterAnnotation.from_json(as_json) assert cluster == regenerated as_json["details"] = {"a": "first", "b": ["and", "second"]} regenerated = structures.ProtoclusterAnnotation.from_json(as_json) assert regenerated.details["a"] == [ "first" ] # single strings should be listified as_json.pop("tool") regenerated = structures.ProtoclusterAnnotation.from_schema_json( as_json, dummy_tool()) assert cluster == regenerated