def test_conversion_bad_record(self): bio = create_module().to_biopython()[0] with self.assertRaisesRegex(ValueError, "record instance required"): Module.from_biopython(bio) with self.assertRaisesRegex( ValueError, "does not contain domain referenced by module"): Module.from_biopython(bio, record=DummyRecord())
def test_detailed_biopython_conversion(self): expected_qualifiers = { "domains", "locus_tags", "complete", "starter_module", "final_module", "monomer_pairings" } original = create_module(starter=True, final=True, complete=True, iterative=True) original.add_monomer("from", "to") bio = original.to_biopython() assert set(bio[0].qualifiers.keys()).issuperset(expected_qualifiers) assert bio[0].qualifiers["complete"] is None assert "incomplete" not in bio[0].qualifiers record = DummyRecord() add_module_references_to_record(original, record) final = Module.from_biopython(bio[0], record=record) assert final.location == original.location assert final.is_starter_module() assert final.is_final_module() assert final.is_iterative() assert final.monomers == original.monomers assert final.is_complete() assert final.location == original.location
def test_detailed_biopython_conversion(self): expected_qualifiers = { "domains", "locus_tags", "complete", "starter_module", "final_module", "monomer_pairings" } original = create_module(starter=True, final=True, complete=True, iterative=True) original.add_monomer("from", "to") bio = original.to_biopython() assert set(bio[0].qualifiers.keys()).issuperset(expected_qualifiers) assert bio[0].qualifiers["complete"] is None assert "incomplete" not in bio[0].qualifiers assert all(domain and " " not in domain for domain in bio[0].qualifiers["domains"]) # fake an inserted space due to length first = bio[0].qualifiers["domains"][0] half = len(first) // 2 bio[0].qualifiers["domains"][0] = first[:half] + " " + first[half:] record = DummyRecord() add_module_references_to_record(original, record) final = Module.from_biopython(bio[0], record=record) assert final.location == original.location assert final.is_starter_module() assert final.is_final_module() assert final.is_iterative() assert final.monomers == original.monomers assert final.is_complete() assert final.location == original.location
def test_bad_biopython_conversion(self): record = DummyRecord() module = create_module() add_module_references_to_record(module, record) for removed_key in ["domains", "incomplete"]: bio = module.to_biopython()[0] bio.qualifiers.pop(removed_key) with self.assertRaisesRegex(ValueError, "missing .* '?%s" % removed_key): Module.from_biopython(bio, record=record) bio = module.to_biopython()[0] bio.qualifiers["type"] = ["not a valid type"] with self.assertRaisesRegex(ValueError, "unknown module type"): Module.from_biopython(bio, record=record) bio = module.to_biopython()[0] for bad in [ "missing", "has -> some -> extra", "missing ->", "-> missing", "->" ]: bio.qualifiers["monomer_pairings"] = [bad] with self.assertRaisesRegex(ValueError, "invalid monomer pairing"): Module.from_biopython(bio, record=record)
def test_minimal_biopython_conversion(self): original = create_module() bio = original.to_biopython() assert isinstance(bio, list) and len(bio) == 1 assert bio[0].location == original.location expected_qualifiers = {"domains", "locus_tags", "incomplete"} assert set(bio[0].qualifiers.keys()).issuperset(expected_qualifiers) assert bio[0].qualifiers["incomplete"] is None assert "complete" not in bio[0].qualifiers record = DummyRecord() add_module_references_to_record(original, record) final = Module.from_biopython(bio[0], record=record) assert final.location == original.location assert not final.is_starter_module() assert not final.is_final_module() assert not final.is_iterative() assert not final.monomers assert not final.is_complete() assert final.location == original.location
def create_module(domains=None, **kwargs): if domains is None: domains = [DummyAntismashDomain()] return Module(domains, **kwargs)