From c5df2ee0bfb6e8a8ff386b2bb9e1f424ec184544 Mon Sep 17 00:00:00 2001 From: csbrasnett Date: Wed, 29 Jan 2025 11:16:11 +0100 Subject: [PATCH] add test case if idr regions but no secstruct. - need to modify create_sys_all_attrs so cgsecstruct not always written - remove duplicate annotation in annotate_idrs.py --- vermouth/processors/annotate_idrs.py | 1 - vermouth/tests/helper_functions.py | 5 +++-- vermouth/tests/test_annotate_idrs.py | 22 +++++++++++++--------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/vermouth/processors/annotate_idrs.py b/vermouth/processors/annotate_idrs.py index b745b17e2..760a5198f 100644 --- a/vermouth/processors/annotate_idrs.py +++ b/vermouth/processors/annotate_idrs.py @@ -41,7 +41,6 @@ def annotate_disorder(molecule, id_regions, annotation="cgidr"): molecule.nodes[key][annotation] = True if "cgsecstruct" in molecule.nodes[key]: molecule.nodes[key]["cgsecstruct"] = "C" - molecule.nodes[key][annotation] = True # ??? else: molecule.nodes[key][annotation] = False diff --git a/vermouth/tests/helper_functions.py b/vermouth/tests/helper_functions.py index 12a7ca5a7..7eb4b56be 100644 --- a/vermouth/tests/helper_functions.py +++ b/vermouth/tests/helper_functions.py @@ -85,7 +85,7 @@ def find_in_path(names=('martinize2', 'martinize2.py')): if os.path.isfile(fullpath): return fullpath -def create_sys_all_attrs(molecule, moltype, secstruc, defaults, attrs): +def create_sys_all_attrs(molecule, moltype, secstruc, defaults, attrs, write_secstruct=True): """ Generate a test system from a molecule with all attributes set and blocks in @@ -138,7 +138,8 @@ def create_sys_all_attrs(molecule, moltype, secstruc, defaults, attrs): resid = res_graph.nodes[node]['resid'] # assign secondary structure for mol_node in mol_nodes: - molecule.nodes[mol_node]['cgsecstruct'] = secstruc[resid] + if write_secstruct: + molecule.nodes[mol_node]['cgsecstruct'] = secstruc[resid] block.add_node(molecule.nodes[mol_node]['atomname'], atype=molecule.nodes[mol_node]['atype']) diff --git a/vermouth/tests/test_annotate_idrs.py b/vermouth/tests/test_annotate_idrs.py index f76d3cf85..df853afbe 100644 --- a/vermouth/tests/test_annotate_idrs.py +++ b/vermouth/tests/test_annotate_idrs.py @@ -59,20 +59,28 @@ def test_make_disorder_string(test_molecule, result.append(False) assert result == expected -@pytest.mark.parametrize('idr_regions, expected',( +@pytest.mark.parametrize('idr_regions, write_sec, expected',( ([(1, 4)], + True, {0: "C", 1: "C", 2: "C", 3: "C", 4: "C", 5: "C", 6: "C", 7: "C", 8: "C"}), ([(1, 2)], + True, {0: "C", 1: "C", 2: "C", 3: "C", 4: "C", 5: "H", 6: "H", 7: "H", 8: "H"}), + ([(1, 2)], + False, + {0: None, 1: None, 2: None, + 3: None, 4: None, + 5: None, + 6: None, 7: None, 8: None}) )) -def test_ss_reassign(test_molecule, idr_regions, expected): +def test_ss_reassign(test_molecule, idr_regions, write_sec, expected): secstruc = {1: "H", 2: "H", 3: "H", 4: "H"} resnames = {0: "A", 1: "A", 2: "A", 3: "B", 4: "B", @@ -82,20 +90,16 @@ def test_ss_reassign(test_molecule, idr_regions, expected): 3: "SP1", 4: "C1", 5: "TP1", 6: "P1", 7: "SN3a", 8: "SP4"} - cgsectruc = {0: "H", 1: "H", 2: "H", - 3: "H", 4: "H", - 5: "H", - 6: "H", 7: "H", 8: "H"} # i.e. all ss is H to begin system = create_sys_all_attrs(test_molecule, moltype="molecule_0", secstruc=secstruc, defaults={"chain": "A"}, attrs={"resname": resnames, - "atype": atypes, - "cgsecstruct": cgsectruc}) + "atype": atypes}, + write_secstruct=write_sec) AnnotateIDRs(id_regions=idr_regions).run_system(system) for key, node in system.molecules[0].nodes.items(): - assert system.molecules[0].nodes[key]["cgsecstruct"] == expected[key] + assert system.molecules[0].nodes[key].get("cgsecstruct", None) == expected[key]