def setUp(self): self.config = get_simple_options(None, []) self.config.genefinding_gff3 = path.get_full_path(__file__, "data", "test_gff.gff") self.single_entry = False contig1 = DummyRecord(seq="A"*2000) contig1.id = "CONTIG_1" contig2 = DummyRecord(seq="A"*2000) contig2.id = "CONTIG_2" self.sequences = [contig1, contig2]
def test_results_reconstruction(self): def check_results(results): assert results.record_id == "rec_id" assert results.tool == "toolname" assert isinstance(results.best_hits["cds1"], HMMResult) assert results.best_hits["cds1"].hit_id == 'desc1' assert results.best_hits["cds2"].bitscore == 20 assert results.function_mapping["cds2"] == GeneFunction.REGULATORY hits = { "cds1": HMMResult("desc1", 0, 100, 2.3e-126, 416), "cds2": HMMResult("desc2", 5, 60, 3e-16, 20), } mapping = { "cds1": GeneFunction.TRANSPORT, "cds2": GeneFunction.REGULATORY, } results = self.res_class("rec_id", "toolname", best_hits=hits, function_mapping=mapping) check_results(results) json = results.to_json() assert json["best_hits"]["cds1"][0] == hits["cds1"].hit_id record = DummyRecord() record.id = "rec_id" reconstructed = self.res_class.from_json(json, record) check_results(reconstructed)
def test_add_to_incorrect_record(self): results = self.create_results(record_id=self.record.id) with self.assertRaisesRegex( ValueError, "Record to store in and record analysed don't match"): other = DummyRecord() other.id = self.record.id * 2 results.add_to_record(other)
def test_regeneration(self): record = DummyRecord() record.id = "rec_name" as_json = json.loads(json.dumps(self.results.to_json())) regenerated = structures.SideloadedResults.from_json(as_json, record) assert regenerated.protoclusters == self.results.protoclusters assert regenerated.subregions == self.results.subregions assert regenerated.record_id == self.results.record_id as_json["schema_version"] = -1 with self.assertRaisesRegex(ValueError, "Detection results have changed"): structures.SideloadedResults.from_json(as_json, record)